Mercurial > repos > yating-l > jbrowsearchivecreator
comparison apollo/ApolloInstance.py @ 31:127037c49bc8 draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
| author | yating-l |
|---|---|
| date | Mon, 16 Oct 2017 18:03:58 -0400 |
| parents | 2191bd0798a9 |
| children |
comparison
equal
deleted
inserted
replaced
| 30:2191bd0798a9 | 31:127037c49bc8 |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 import os | |
| 2 import json | 3 import json |
| 4 import shutil | |
| 5 import tempfile | |
| 3 import logging | 6 import logging |
| 4 from util import subtools | 7 from util import subtools |
| 8 from mako.lookup import TemplateLookup | |
| 9 | |
| 5 | 10 |
| 6 class ApolloInstance(object): | 11 class ApolloInstance(object): |
| 7 def __init__(self, apollo_host): | 12 def __init__(self, apollo_host, tool_directory, user_email): |
| 8 self.apollo_host = apollo_host | 13 self.apollo_host = apollo_host |
| 14 self.tool_directory = tool_directory | |
| 15 self.default_user = user_email | |
| 9 self.logger = logging.getLogger(__name__) | 16 self.logger = logging.getLogger(__name__) |
| 17 self.apolloTemplate = self._getApolloTemplate() | |
| 18 self._arrow_init() | |
| 19 | |
| 20 def _arrow_init(self): | |
| 21 arrow_config = tempfile.NamedTemporaryFile(bufsize=0) | |
| 22 with open(arrow_config.name, 'w') as conf: | |
| 23 htmlMakoRendered = self.apolloTemplate.render( | |
| 24 apollo_host = self.apollo_host, | |
| 25 admin_user = self.default_user, | |
| 26 admin_pw = '1234' | |
| 27 ) | |
| 28 conf.write(htmlMakoRendered) | |
| 29 | |
| 30 home_dir = os.path.expanduser('~') | |
| 31 arrow_config_dir = os.path.join(home_dir, '.apollo-arrow.yml') | |
| 32 shutil.copyfile(arrow_config.name, arrow_config_dir) | |
| 33 self.logger.debug("Initated arrow: apollo-arrow.yml= %s", arrow_config_dir) | |
| 34 | |
| 35 | |
| 36 def _getApolloTemplate(self): | |
| 37 mylookup = TemplateLookup(directories=[os.path.join(self.tool_directory, 'templates')], | |
| 38 output_encoding='utf-8', encoding_errors='replace') | |
| 39 apolloTemplate = mylookup.get_template("apollo-arrow.yml") | |
| 40 return apolloTemplate | |
| 10 | 41 |
| 11 def getHost(self): | 42 def getHost(self): |
| 12 return self.apollo_host | 43 return self.apollo_host |
| 13 | 44 |
| 14 def createApolloUser(self, apollo_user, admin=None): | 45 def createApolloUser(self, apollo_user, admin=None): |
| 15 p = subtools.arrow_create_user(apollo_user.user_email, apollo_user.firstname, apollo_user.lastname, apollo_user.password, admin) | 46 p = subtools.arrow_create_user(apollo_user.user_email, apollo_user.firstname, apollo_user.lastname, apollo_user.password, admin) |
| 16 print p | 47 user_info = json.loads(p) |
| 17 if p: | 48 user_id = user_info.get('userId') |
| 18 user_info = json.loads(p) | 49 if not user_id: |
| 19 user_id = user_info.get('userId') | |
| 20 if not p or not user_id: | |
| 21 self.logger.debug("Cannot create new user: %s; The user may already exist", apollo_user.user_email) | 50 self.logger.debug("Cannot create new user: %s; The user may already exist", apollo_user.user_email) |
| 22 user_id = subtools.arrow_get_users(apollo_user.user_email) | 51 user_id = subtools.arrow_get_users(apollo_user.user_email) |
| 23 self.logger.debug("Got user_id for new or existing user: user_id = %s", str(user_id)) | 52 self.logger.debug("Got user_id for new or existing user: user_id = %s", str(user_id)) |
| 24 return user_id | 53 return user_id |
| 25 | 54 |
