comparison env/lib/python3.9/site-packages/ephemeris/__init__.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1
2 # -*- coding: utf-8 -*-
3
4 import yaml
5 from bioblend import galaxy
6
7 __version__ = '0.10.6'
8
9 PROJECT_NAME = "ephemeris"
10 PROJECT_OWNER = PROJECT_USERAME = "galaxyproject"
11 PROJECT_URL = "https://github.com/galaxyproject/ephemeris"
12 PROJECT_AUTHOR = 'Galaxy Project and Community'
13 PROJECT_EMAIL = 'jmchilton@gmail.com'
14 RAW_CONTENT_URL = "https://raw.github.com/%s/%s/master/" % (
15 PROJECT_USERAME, PROJECT_NAME
16 )
17
18
19 def check_url(url, log=None):
20 if not url.startswith('http'):
21 if log:
22 log.warning('URL should start with http:// or https://. https:// chosen by default.')
23 url = 'https://' + url
24 return url
25
26
27 def get_galaxy_connection(args, file=None, log=None, login_required=True):
28 """
29 Return a Galaxy connection, given a user or an API key.
30 If not given gets the arguments from the file.
31 If either is missing raise ValueError.
32 """
33 if file:
34 file_content = load_yaml_file(file)
35 else:
36 file_content = dict()
37
38 url = args.galaxy or file_content.get('galaxy_instance')
39 galaxy_url = check_url(url, log)
40 api_key = args.api_key or file_content.get('api_key')
41
42 if args.user and args.password:
43 return galaxy.GalaxyInstance(url=galaxy_url, email=args.user, password=args.password)
44 elif api_key:
45 return galaxy.GalaxyInstance(url=galaxy_url, key=api_key)
46 elif not login_required:
47 return galaxy.GalaxyInstance(url=galaxy_url)
48 else:
49 raise ValueError("Missing api key or user & password combination, in order to make a galaxy connection.")
50
51
52 def load_yaml_file(filename):
53 """
54 Load YAML from the `tool_list_file` and return a dict with the content.
55 """
56 with open(filename, 'r') as f:
57 dictionary = yaml.safe_load(f)
58 return dictionary
59
60
61 def dump_to_yaml_file(content, file_name):
62 """
63 Dump YAML-compatible `content` to `file_name`.
64 """
65 with open(file_name, 'w') as f:
66 yaml.dump(content, f, default_flow_style=False)