comparison alveo_api_key.py @ 14:a38315ecf593 draft

planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
author stevecassidy
date Wed, 01 Nov 2017 01:18:15 -0400
parents 3a9f20428cff
children 5e1b7d922ea3
comparison
equal deleted inserted replaced
13:be3fd14899a1 14:a38315ecf593
1 from __future__ import print_function 1 from __future__ import print_function
2 import argparse 2 import argparse
3 import pyalveo
4 import sys 3 import sys
4 from util import write_key
5 5
6 API_URL = 'https://app.alveo.edu.au'
7 6
8 def parser(): 7 def parser():
9 parser = argparse.ArgumentParser(description="Retrieves Alveo Item Lists") 8 p = argparse.ArgumentParser(description="Retrieves Alveo Item Lists")
10 parser.add_argument('--api_key', required=True, action="store", type=str, help="Alveo API key") 9 p.add_argument('--api_key', required=True, action="store", type=str, help="Alveo API key")
11 parser.add_argument('--output_path', required=True, action="store", type=str, help="File to store the API key in") 10 p.add_argument('--output_path', required=True, action="store", type=str, help="File to store the API key in")
12 return parser.parse_args() 11 return p.parse_args()
13 12
14 def write_key(api_key, output_path, client_module=pyalveo):
15 """Tests whether an API key is valid and writes it to a file.
16
17 :type api_key: String
18 :param api_key: Alveo API key
19
20 :type output_path: String
21 :param output_path: Path to the file to store the API key in
22
23 :type client_module: pyalveo.Client
24 :param client_module: Module providing the client (used for testing purposes),
25 defaults to pyalveo
26
27 :raises: pyalveo.APIError if the API request is not successful
28
29 """
30 client = client_module.Client(api_key, API_URL, use_cache=False)
31 outfile = open(output_path, 'w')
32 outfile.write(api_key)
33 outfile.close()
34 13
35 def main(): 14 def main():
36 args = parser() 15 args = parser()
37 try: 16 try:
38 write_key(args.api_key, args.output_path) 17 write_key(args.api_key, args.output_path)
39 except Exception as e: 18 except Exception as e:
40 print("ERROR: " + str(e), file=sys.stderr) 19 print("ERROR: " + str(e), file=sys.stderr)
41 sys.exit(1) 20 sys.exit(1)
42 21
22
43 if __name__ == '__main__': 23 if __name__ == '__main__':
44 main() 24 main()