annotate apollo/ApolloInstance.py @ 0:9945eba268e6 draft default tip

planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
author yating-l
date Mon, 27 Nov 2017 12:49:27 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9945eba268e6 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
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
2 import os
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
3 import json
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
4 import shutil
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
5 import tempfile
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
6 import logging
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
7 import random
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
8 import string
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
9 from util import subtools
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
10 from mako.lookup import TemplateLookup
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
11
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
12 from ApolloOrganism import ApolloOrganism
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
13 from ApolloUser import ApolloUser
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
14
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
15 class ApolloInstance(object):
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
16 def __init__(self, apollo_host, apollo_admin, tool_directory):
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
17 self.apollo_host = apollo_host
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
18 self.tool_directory = tool_directory
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
19 self.logger = logging.getLogger(__name__)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
20 self.apollo_admin = apollo_admin
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
21 self.apolloTemplate = self._getApolloTemplate()
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
22 self._arrow_init()
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
23
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
24
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
25 def _arrow_init(self):
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
26 subtools.verify_user_login(self.apollo_admin['user_email'], self.apollo_admin['password'], self.apollo_host)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
27 arrow_config = tempfile.NamedTemporaryFile(bufsize=0)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
28 with open(arrow_config.name, 'w') as conf:
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
29 htmlMakoRendered = self.apolloTemplate.render(
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
30 apollo_host = self.apollo_host,
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
31 admin_user = self.apollo_admin['user_email'],
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
32 admin_pw = self.apollo_admin['password']
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
33 )
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
34 conf.write(htmlMakoRendered)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
35
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
36 home_dir = os.path.expanduser('~')
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
37 arrow_config_dir = os.path.join(home_dir, '.apollo-arrow.yml')
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
38 shutil.copyfile(arrow_config.name, arrow_config_dir)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
39 self.logger.debug("Initated arrow: apollo-arrow.yml= %s", arrow_config_dir)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
40
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
41 #TODO: Encode admin password
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
42 '''
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
43 def _generatePassword(self, length=8):
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
44 chars = string.digits + string.letters
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
45 pw = ''.join([random.choice(chars) for _ in range(length)])
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
46 return pw
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
47 '''
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
48
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
49 def _getApolloTemplate(self):
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
50 mylookup = TemplateLookup(directories=[os.path.join(self.tool_directory, 'templates')],
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
51 output_encoding='utf-8', encoding_errors='replace')
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
52 apolloTemplate = mylookup.get_template("apollo-arrow.yml")
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
53 return apolloTemplate
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
54
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
55
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
56 def manageApolloOrganism(self, organism_name, organism_dir, action):
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
57 organism = ApolloOrganism(organism_name, organism_dir)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
58 if action == "add":
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
59 organism.addOrganism()
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
60 self.logger.info("Successfully add a new organism (%s) to Apollo", organism_name)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
61 elif action == "overwrite":
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
62 organism.overwriteOrganism()
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
63 self.logger.info("Successfully overwrite the organism %s", organism_name)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
64 else:
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
65 self.logger.error("Invalid operation %s", action)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
66 exit(-1)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
67
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
68 def manageApolloUser(self, operations_dictionary = dict()):
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
69 for operation, users_list in operations_dictionary.items():
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
70 apollo_user = ApolloUser(users_list)
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
71 if operation == "create":
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
72 apollo_user.createApolloUser()
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
73 elif operation == "delete":
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
74 apollo_user.deleteApolloUser()
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
75 elif operation == "add":
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
76 apollo_user.addApolloUserToGroup()
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
77 elif operation == "delete":
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
78 apollo_user.removeApolloUserFromeGroup()
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
79
9945eba268e6 planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff changeset
80