Mercurial > repos > shellac > guppy_basecaller
diff env/lib/python3.7/site-packages/ephemeris/__init__.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/env/lib/python3.7/site-packages/ephemeris/__init__.py Sat May 02 07:14:21 2020 -0400 @@ -0,0 +1,66 @@ + +# -*- coding: utf-8 -*- + +import yaml +from bioblend import galaxy + +__version__ = '0.10.5' + +PROJECT_NAME = "ephemeris" +PROJECT_OWNER = PROJECT_USERAME = "galaxyproject" +PROJECT_URL = "https://github.com/galaxyproject/ephemeris" +PROJECT_AUTHOR = 'Galaxy Project and Community' +PROJECT_EMAIL = 'jmchilton@gmail.com' +RAW_CONTENT_URL = "https://raw.github.com/%s/%s/master/" % ( + PROJECT_USERAME, PROJECT_NAME +) + + +def check_url(url, log=None): + if not url.startswith('http'): + if log: + log.warning('URL should start with http:// or https://. https:// chosen by default.') + url = 'https://' + url + return url + + +def get_galaxy_connection(args, file=None, log=None, login_required=True): + """ + Return a Galaxy connection, given a user or an API key. + If not given gets the arguments from the file. + If either is missing raise ValueError. + """ + if file: + file_content = load_yaml_file(file) + else: + file_content = dict() + + url = args.galaxy or file_content.get('galaxy_instance') + galaxy_url = check_url(url, log) + api_key = args.api_key or file_content.get('api_key') + + if args.user and args.password: + return galaxy.GalaxyInstance(url=galaxy_url, email=args.user, password=args.password) + elif api_key: + return galaxy.GalaxyInstance(url=galaxy_url, key=api_key) + elif not login_required: + return galaxy.GalaxyInstance(url=galaxy_url) + else: + raise ValueError("Missing api key or user & password combination, in order to make a galaxy connection.") + + +def load_yaml_file(filename): + """ + Load YAML from the `tool_list_file` and return a dict with the content. + """ + with open(filename, 'r') as f: + dictionary = yaml.safe_load(f) + return dictionary + + +def dump_to_yaml_file(content, file_name): + """ + Dump YAML-compatible `content` to `file_name`. + """ + with open(file_name, 'w') as f: + yaml.dump(content, f, default_flow_style=False)