Mercurial > repos > yating-l > jbrowsearchivecreator
comparison apollo/ApolloInstance.py @ 25:31a41ce128cc draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
| author | yating-l |
|---|---|
| date | Fri, 13 Oct 2017 12:44:31 -0400 |
| parents | |
| children | 2191bd0798a9 |
comparison
equal
deleted
inserted
replaced
| 24:bb6fdccef474 | 25:31a41ce128cc |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 import json | |
| 3 import logging | |
| 4 from util import subtools | |
| 5 | |
| 6 class ApolloInstance(object): | |
| 7 def __init__(self, apollo_host): | |
| 8 self.apollo_host = apollo_host | |
| 9 self.logger = logging.getLogger(__name__) | |
| 10 | |
| 11 def getHost(self): | |
| 12 return self.apollo_host | |
| 13 | |
| 14 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) | |
| 16 user_info = json.loads(p) | |
| 17 user_id = user_info.get('userId') | |
| 18 if not user_id: | |
| 19 self.logger.debug("Cannot create new user: %s; The user may already exist", apollo_user.user_email) | |
| 20 user_id = subtools.arrow_get_users(apollo_user.user_email) | |
| 21 self.logger.debug("Got user_id for new or existing user: user_id = %s", str(user_id)) | |
| 22 return user_id | |
| 23 | |
| 24 def grantPermission(self, user_id, organism_id, **user_permissions): | |
| 25 subtools.arrow_update_organism_permissions(user_id, organism_id, **user_permissions) | |
| 26 self.logger.debug("Grant user %s permissions to organism %s, permissions = %s", str(user_id), str(organism_id), ','.join(user_permissions)) | |
| 27 | |
| 28 def addOrganism(self, organism_name, organism_dir): | |
| 29 p = subtools.arrow_add_organism(organism_name, organism_dir) | |
| 30 organism = json.loads(p) | |
| 31 organism_id = organism['id'] | |
| 32 self.logger.debug("Added new organism to Apollo instance, %s", p) | |
| 33 return organism_id | |
| 34 | |
| 35 def loadHubToApollo(self, apollo_user, organism_name, organism_dir, admin_user=False, **user_permissions): | |
| 36 user_id = self.createApolloUser(apollo_user, admin_user) | |
| 37 organism_id = self.addOrganism(organism_name, organism_dir) | |
| 38 self.grantPermission(user_id, organism_id, **user_permissions) | |
| 39 self.logger.debug("Successfully load the hub to Apollo") |
