Mercurial > repos > yating-l > gonramp_apollo_tools
annotate apolloUserManager.py @ 2:4be6fcac4bf2 draft default tip
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
author | yating-l |
---|---|
date | Wed, 29 Nov 2017 15:39:32 -0500 |
parents | 78af01d73add |
children |
rev | line source |
---|---|
0
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
1 #!/usr/bin/env python |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
2 import os |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
3 import sys |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
4 import argparse |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
5 import json |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
6 import logging |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
7 import socket |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
8 from apollo.ApolloInstance import ApolloInstance |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
9 from apollo.ApolloUser import ApolloUser |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
10 from util.Reader import Reader |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
11 from util.Logger import Logger |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
12 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
13 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
14 def main(argv): |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
15 parser = argparse.ArgumentParser(description='Upload a hub to display on Apollo.') |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
16 parser.add_argument('-j', '--data_json', help='JSON file containing the metadata of the inputs') |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
17 parser.add_argument('-o', '--output', help='HTML output') |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
18 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
19 # Get the args passed in parameter |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
20 args = parser.parse_args() |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
21 json_inputs_data = args.data_json |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
22 outputFile = args.output |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
23 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
24 ##Parse JSON file with Reader |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
25 reader = Reader(json_inputs_data) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
26 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
27 # Begin init variables |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
28 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
29 apollo_port = reader.getPortNum() |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
30 apollo_host = "http://localhost:"+ apollo_port + "/apollo" |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
31 apollo_admin_user = reader.getAdminUser() |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
32 toolDirectory = reader.getToolDir() |
1
78af01d73add
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
0
diff
changeset
|
33 extra_files_path = reader.getExtFilesPath() |
0
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
34 debug_mode = reader.getDebugMode() |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
35 operations_dictionary = reader.getOperationList() |
1
78af01d73add
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
0
diff
changeset
|
36 |
0
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
37 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
38 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
39 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
40 #### Logging management #### |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
41 # If we are in Debug mode, also print in stdout the debug dump |
1
78af01d73add
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
0
diff
changeset
|
42 log = Logger(tool_directory=toolDirectory, debug=debug_mode, extra_files_path=extra_files_path) |
0
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
43 log.setup_logging() |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
44 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
45 logging.info("#### Apollo User Manager: Start on Apollo instance: %s #### ", apollo_host) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
46 logging.debug('JSON parameters: %s\n\n', json.dumps(reader.args)) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
47 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
48 # Set up apollo |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
49 apollo = ApolloInstance(apollo_host, apollo_admin_user, toolDirectory) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
50 apollo.manageApolloUser(operations_dictionary) |
2
4be6fcac4bf2
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
1
diff
changeset
|
51 outHtml(outputFile, apollo_host) |
0
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
52 logging.info('#### Apollo User Manager: Congratulation! ####\n') |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
53 |
2
4be6fcac4bf2
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
1
diff
changeset
|
54 def outHtml(outputFile, host_name): |
4be6fcac4bf2
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
1
diff
changeset
|
55 with open(outputFile, 'w') as htmlfile: |
4be6fcac4bf2
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
1
diff
changeset
|
56 htmlstr = 'The Apollo User Manager has done with operations on Apollo: <br>' |
4be6fcac4bf2
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
1
diff
changeset
|
57 jbrowse_hub = '<li><a href = "%s" target="_blank">View JBrowse Hub on Apollo</a></li>' % host_name |
4be6fcac4bf2
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
1
diff
changeset
|
58 htmlstr += jbrowse_hub |
4be6fcac4bf2
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
1
diff
changeset
|
59 htmlfile.write(htmlstr) |
1
78af01d73add
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
0
diff
changeset
|
60 |
0
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
61 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
62 if __name__ == "__main__": |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
63 main(sys.argv) |