Mercurial > repos > yating-l > jbrowsehubtoapollo
changeset 3:6f262a92e8dc draft default tip
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 91b46f7c891c2466bc5b6a063411cdae75964515-dirty
author | yating-l |
---|---|
date | Mon, 27 Nov 2017 12:06:18 -0500 |
parents | 8ff4b84d709f |
children | |
files | apollo/ApolloInstance.py apollo/ApolloInstance.pyc apollo/ApolloUser.py apollo/ApolloUser.pyc apollo/__init__.py apollo/__init__.pyc jbrowsehubToApollo.py jbrowsehubToApollo.xml logging.json templates/__init__.py templates/apollo-arrow.yml todo.md tool_dependencies.xml util/Logger.py util/Reader.py util/Reader.pyc util/__init__.py util/__init__.pyc util/santitizer.py util/santitizer.pyc util/subtools.py util/subtools.pyc |
diffstat | 19 files changed, 0 insertions(+), 718 deletions(-) [+] |
line wrap: on
line diff
--- a/apollo/ApolloInstance.py Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -#!/usr/bin/env python -import os -import json -import shutil -import tempfile -import logging -import random -import string -from util import subtools -from mako.lookup import TemplateLookup - - -class ApolloInstance(object): - def __init__(self, apollo_host, apollo_admin, tool_directory): - self.apollo_host = apollo_host - self.tool_directory = tool_directory - self.logger = logging.getLogger(__name__) - self.apollo_admin = apollo_admin - self.apolloTemplate = self._getApolloTemplate() - self._arrow_init() - - - def _arrow_init(self): - subtools.verify_user_login(self.apollo_admin.user_email, self.apollo_admin.password, self.apollo_host) - arrow_config = tempfile.NamedTemporaryFile(bufsize=0) - with open(arrow_config.name, 'w') as conf: - htmlMakoRendered = self.apolloTemplate.render( - apollo_host = self.apollo_host, - admin_user = self.apollo_admin.user_email, - admin_pw = self.apollo_admin.password - ) - conf.write(htmlMakoRendered) - - home_dir = os.path.expanduser('~') - arrow_config_dir = os.path.join(home_dir, '.apollo-arrow.yml') - shutil.copyfile(arrow_config.name, arrow_config_dir) - self.logger.debug("Initated arrow: apollo-arrow.yml= %s", arrow_config_dir) - - #TODO: Encode admin password - ''' - def _generatePassword(self, length=8): - chars = string.digits + string.letters - pw = ''.join([random.choice(chars) for _ in range(length)]) - return pw - ''' - - def _getApolloTemplate(self): - mylookup = TemplateLookup(directories=[os.path.join(self.tool_directory, 'templates')], - output_encoding='utf-8', encoding_errors='replace') - apolloTemplate = mylookup.get_template("apollo-arrow.yml") - return apolloTemplate - - def createApolloUser(self, apollo_user, admin=None): - p = subtools.arrow_create_user(apollo_user.user_email, apollo_user.firstname, apollo_user.lastname, apollo_user.password, admin) - user_info = json.loads(p) - user_id = user_info.get('userId') - if not user_id: - self.logger.debug("Cannot create new user: %s; The user may already exist", apollo_user.user_email) - subtools.verify_user_login(apollo_user.user_email, apollo_user.password, self.apollo_host) - user_id = subtools.arrow_get_users(apollo_user.user_email) - self.logger.debug("Got user_id for new or existing user: user_id = %s", str(user_id)) - return user_id - - def grantPermission(self, user_id, organism_id, **user_permissions): - subtools.arrow_update_organism_permissions(user_id, organism_id, **user_permissions) - self.logger.debug("Grant user %s permissions to organism %s, permissions = %s", str(user_id), str(organism_id), ','.join(user_permissions)) - - def addOrganism(self, organism_name, organism_dir): - p = subtools.arrow_add_organism(organism_name, organism_dir) - if not p: - self.logger.error("The user is not authorized to add organism") - exit(-1) - organism = json.loads(p) - organism_id = organism['id'] - self.logger.debug("Added new organism to Apollo instance, %s", p) - return organism_id - - def loadHubToApollo(self, apollo_user, organism_name, organism_dir, admin_user=False, **user_permissions): - #user_id = self.createApolloUser(apollo_user, admin_user) - organism_id = self.addOrganism(organism_name, organism_dir) - #self.grantPermission(user_id, organism_id, **user_permissions) - self.logger.debug("Successfully load the hub to Apollo") \ No newline at end of file
--- a/apollo/ApolloUser.py Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -#!/usr/bin/python - -import os - -class ApolloUser(object): - def __init__(self, user_email, password, firstname=None, lastname=None): - self.user_email = user_email - self.firstname = firstname - self.lastname = lastname - self.password = password
--- a/jbrowsehubToApollo.py Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -#!/usr/bin/env python -import os -import sys -import argparse -import json -import logging -import socket -from apollo.ApolloInstance import ApolloInstance -from util.Reader import Reader -from util.Logger import Logger - - -def main(argv): - parser = argparse.ArgumentParser(description='Upload a hub to display on Apollo.') - parser.add_argument('-j', '--data_json', help='JSON file containing the metadata of the inputs') - parser.add_argument('-o', '--output', help='HTML output') - - #parser.add_argument('-e', '--extra_file_path', help='Extra file path for generated jbrowse hub') - #parser.add_argument('-d', '--jbrowsehub', help='Name of the HTML summarizing the content of the JBrowse Hub Archive') - - # Get the args passed in parameter - args = parser.parse_args() - json_inputs_data = args.data_json - outputFile = args.output - #outputFile = args.jbrowsehub - - - ##Parse JSON file with Reader - reader = Reader(json_inputs_data) - - # Begin init variables - extra_files_path = reader.getExtFilesPath() - #user_email = reader.getUserEmail() - species_name = reader.getSpeciesName() - #apollo_host = reader.getApolloHost() - apollo_port = reader.getPortNum() - apollo_host = "http://localhost:"+ apollo_port + "/apollo" - #apollo_host = "http://localhost:8080/apollo" - #apollo_user = reader.getApolloUser() - apollo_admin_user = reader.getAdminUser() - toolDirectory = reader.getToolDir() - #jbrowse_hub = reader.getJBrowseHubDir() - debug_mode = reader.getDebugMode() - - #### Logging management #### - # If we are in Debug mode, also print in stdout the debug dump - log = Logger(tool_directory=toolDirectory, debug=debug_mode, extra_files_path=extra_files_path) - log.setup_logging() - - logging.info("#### JBrowseArchiveCreator: Start to upload JBrowse Hub to Apollo instance: %s #### ", apollo_host) - logging.debug('JSON parameters: %s\n\n', json.dumps(reader.args)) - - # Set up apollo - apollo = ApolloInstance(apollo_host, apollo_admin_user, toolDirectory) - jbrowse_hub_dir = _getHubDir(extra_files_path) - apollo.loadHubToApollo(apollo_admin_user, species_name, jbrowse_hub_dir, admin=True) - outHtml(outputFile, apollo_host, species_name) - - logging.info('#### JBrowseArchiveCreator: Congratulation! JBrowse Hub is uploaded! ####\n') - -def _getHubDir(extra_files_path): - for root, dirs, files in os.walk(extra_files_path): - for name in files: - if name == "trackList.json": - logging.debug("JBrowse hub directory: %s", root) - return root - logging.error("Cannot find jbrowsehub") - exit(-1) - -def outHtml(outputFile, host_name, species_name): - with open(outputFile, 'w') as htmlfile: - htmlstr = 'The new Organism "%s" is created on Apollo: <br>' % species_name - jbrowse_hub = '<li><a href = "%s" target="_blank">View JBrowse Hub on Apollo</a></li>' % host_name - htmlstr += jbrowse_hub - htmlfile.write(htmlstr) - -if __name__ == "__main__": - main(sys.argv) \ No newline at end of file
--- a/jbrowsehubToApollo.xml Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -<tool id="jbrowsehubtoapollo" name="JBrowseHub To Apollo" version="1.0.0"> - <description> - This Galaxy tool is used to prepare your files to be ready for displaying on JBrowse with Apollo plugin - </description> - - <requirements> - <requirement type="package" version="3.0.3">apollo_api</requirement> - </requirements> - - <stdio> - </stdio> - - <command detect_errors="exit_code"><![CDATA[ - - ## Dump the tool parameters into a JSON file - python $json_file parameters.json; - python $__tool_directory__/jbrowsehubToApollo.py --data_json parameters.json -o $output - ]]></command> - <configfiles> - <configfile name="json_file"> -import json -import sys - -file_path = sys.argv[1] -#set global data_parameter_dict = {} -#silent $data_parameter_dict.update({"species_name": str($species_name)}) -#set apollo_admin = {"user_email": str($admin_username), "password": str($admin_password)} -#silent $data_parameter_dict.update({"apollo_admin": $apollo_admin}) -##silent $data_parameter_dict.update({"user_email": str($__user_email__)}) -#silent $data_parameter_dict.update({"tool_directory": str($__tool_directory__)}) -#silent $data_parameter_dict.update({"extra_files_path": str($jbrowse_hub.extra_files_path)}) -#silent $data_parameter_dict.update({"port": str($advanced_options.port)}) -#silent $data_parameter_dict.update({"debug_mode": str($advanced_options.debug_mode)}) -with open(file_path, 'w') as f: - json.dump($data_parameter_dict, f) - </configfile> - </configfiles> - - - <inputs> - <param - format="jbrowsehub" - type="data" - name="jbrowse_hub" - label="JBrowse Hub created by JBrowse Archive Creator" - /> - <param - name="species_name" - type="text" - size="30" - value="unknown" - label="Species name" - /> - <param name="admin_username" type="text" label="Admin username" help="Login in with Apollo admin account"> - <sanitizer> - <valid initial="string.letters,string.digits"> - <add value="@-=_.()/+*^,:?!"/> - </valid> - </sanitizer> - </param> - <param - name="admin_password" - type="text" - label="Admin password" - /> - <conditional name="advanced_options"> - <param name="advanced_options_selector" type="select" label="Advanced options"> - <option value="off" selected="true">Hide advanced options</option> - <option value="on">Display advanced options</option> - </param> - <!-- TODO: Avoid redundancy here --> - <when value="on"> - <param name="port" type="integer" min="8000" max="8888" value="8080" label="Port number of Apollo" /> - <param name="debug_mode" type="select" label="Activate debug mode"> - <option value="false" selected="true">No</option> - <option value="true">Yes</option> - <help> - Use this option if you are a G-OnRamp developer - </help> - </param> - </when> - <when value="off"> - <param name="port" type="hidden" value="8080" /> - <param name="debug_mode" type="hidden" - value="false"> - </param> - </when> - </conditional> - </inputs> - <outputs> - <data format="html" name="output" label="${tool.name}" /> - </outputs> - - <help> - This Galaxy tool will load a jbrowse hub to Apollo instance for visualization and interactive annotation. - </help> - <citations> - </citations> -</tool> \ No newline at end of file
--- a/logging.json Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -{ - "version": 1, - "disable_existing_loggers": false, - "formatters": { - "simple": { - "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s" - } - }, - - "handlers": { - "console": { - "class": "logging.StreamHandler", - "level": "INFO", - "formatter": "simple", - "stream": "ext://sys.stdout" - }, - - "console_stderr": { - "class": "logging.StreamHandler", - "level": "ERROR", - "formatter": "simple", - "stream": "ext://sys.stderr" - } - }, - - "loggers": { - "Reader": { - "level": "INFO", - "handlers": ["console"], - "propagate": "yes" - } - }, - - "root": { - "level": "DEBUG", - "handlers": ["console", "console_stderr"] - } -} \ No newline at end of file
--- a/templates/apollo-arrow.yml Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -## Apollo's Arrow: Global Configuration File. -# Each stanza should contian a single galaxy server to control. -# -# You can set the key __default to the name of a default instance -__default: local - -local: - url: ${apollo_host} - username: ${admin_user} - password: ${admin_pw}
--- a/todo.md Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -# JBrowseHubToApollo's TODO - -- [ ] Correct new Apollo user's email address. Galaxy santitizes '@' to '__at__' -- [ ] Check password for admin login - -### DONE - - -- [x] upload jbrowsehub to Apollo instance
--- a/tool_dependencies.xml Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -<?xml version="1.0"?> -<tool_dependency> - - <package name="apollo_api" version="3.0.3"> - <install version="1.0"> - <actions> - <action type="download_by_url">https://github.com/galaxy-genome-annotation/python-apollo/archive/3.0.3.tar.gz</action> - <action type="make_directory">$INSTALL_DIR/apollo</action> - <action type="shell_command"> - export PYTHONPATH=$PYTHONPATH:$INSTALL_DIR/apollo && - python setup.py install --install-lib $INSTALL_DIR/apollo - </action> - <action type="set_environment"> - <environment_variable action="append_to" name="PYTHONPATH">$INSTALL_DIR/apollo</environment_variable> - <environment_variable action="append_to" name="PATH">$INSTALL_DIR/apollo</environment_variable> - </action> - </actions> - </install> - </package> - - - -</tool_dependency>
--- a/util/Logger.py Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -import os -import sys -import json -import logging -import logging.config - -#from util.Filters import TraceBackFormatter - -class Logger(object): - def __init__(self, tool_directory, debug="False", extra_files_path=None): - self.tool_directory = tool_directory - self.default_level = logging.INFO - self.debug = debug - self.extra_files_path = extra_files_path - - def setup_logging(self): - """Setup logging configuration - reference: https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/ - """ - config_path = os.path.join(self.tool_directory, 'logging.json') - default_level=logging.INFO - if self.debug.lower() == "true": - default_level=logging.DEBUG - if os.path.exists(config_path): - with open(config_path, 'rt') as f: - config = json.load(f) - config["handlers"]["console"]["level"] = default_level - if self.extra_files_path: - for i in config["handlers"]: - if "filename" in config["handlers"][i]: - config["handlers"][i]["filename"] = os.path.join(self.extra_files_path, config["handlers"][i]["filename"]) - logging.config.dictConfig(config) - else: - logging.warn("Extra files path is not set. The log files will exist at current working directory instead of final output folder") - else: - logging.basicConfig(level=default_level) - logging.warn("Cannot find logging configuration file!\n") -
--- a/util/Reader.py Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -import json -import re -import logging -import codecs -import socket -from apollo.ApolloUser import ApolloUser -from util import santitizer - -class Reader(object): - - def __init__(self, input_json_file): - self.inputFile = input_json_file - self.args = self.loadJson() - - - def loadJson(self): - try: - data_file = codecs.open(self.inputFile, 'r', 'utf-8') - return json.load(data_file) - except IOError: - print "Cannot find JSON file\n" - exit(1) - - def getJBrowseHubDir(self): - try: - return self.args["jbrowse_hub"] - except KeyError: - print ("jbrowse_hub is not defined in the input file!") - exit(1) - - def getToolDir(self): - try: - return self.args["tool_directory"] - except KeyError: - print ("tool_directory is not defined in the input file!") - exit(1) - - def getExtFilesPath(self): - try: - return self.args["extra_files_path"] - except KeyError: - print ("extra_files_path is not defined in the input file!") - exit(1) - - def getUserEmail(self): - try: - return self.args["user_email"] - except KeyError: - print ("user_email is not defined in the input file!") - exit(1) - - def getDebugMode(self): - try: - return self.args["debug_mode"] - except KeyError: - print ("debug_mode is not defined in the input file!") - exit(1) - - def getPortNum(self): - try: - return self.args["port"] - except KeyError: - print ("port is not defined in the input file!") - exit(1) - - def getApolloHost(self): - #apollo_host = self.args.get("apollo_host") - hostname = socket.gethostname() - ip = socket.gethostbyname(hostname) - protocol = socket.getprotobyname(hostname) - apollo_host = str(protocol) + str(ip) - return apollo_host - - - def getSpeciesName(self): - species_name = santitizer.sanitize_name_input(self.args["species_name"]) - return species_name - - def getAdminUser(self): - admin_info = self.args.get("apollo_admin") - user_email = admin_info['user_email'] - password = admin_info['password'] - apollo_admin = ApolloUser(user_email, password) - return apollo_admin - - def getApolloUser(self): - user_info = self.args.get("apollo_user") - if not user_info: - firstname = "demo" - lastname = "user" - password = "gonramp" - user_email = self.getUserEmail() - else: - firstname = user_info['firstname'] - lastname = user_info['lastname'] - user_email = user_info['user_email'] - password = user_info['password'] - apollo_user = ApolloUser(user_email, firstname, lastname, password) - return apollo_user - - \ No newline at end of file
--- a/util/santitizer.py Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf8 -*- - -""" -This class handles the subprocess calls of the different tools used -in HubArchiveCreator -""" - -import logging -import os -import subprocess -import sys -import string -import tempfile - - -def prefixTrackName(filename): - """ - santitize trackName. Because track name must begin with a letter and - contain only the following chars: [a-zA-Z0-9_]. - See the "track" Common settings at: - https://genome.ucsc.edu/goldenpath/help/trackDb/trackDbHub.html#bigPsl_-_Pairwise_Alignments - skip the santitization for cytoBandIdeo track - """ - if filename == 'cytoBandIdeo': - return filename - valid_chars = "_%s%s" % (string.ascii_letters, string.digits) - sanitize_name = ''.join([c if c in valid_chars else '_' for c in filename]) - sanitize_name = "gonramp_" + sanitize_name - return sanitize_name - -def sanitize_name_input(string_to_sanitize): - """ - Sanitize the string passed in parameter by replacing '/' and ' ' by '_' - - :param string_to_sanitize: - :return : - - :Example: - - >>> sanitize_name_input('this/is an//example') - this_is_an__example - """ - return string_to_sanitize \ - .replace("/", "_") \ - .replace(" ", "_") - -def sanitize_name_inputs(inputs_data): - """ - Sanitize value of the keys "name" of the dictionary passed in parameter. - - Because sometimes output from Galaxy, or even just file name, from user inputs, have spaces. - Also, it can contain '/' character and could break the use of os.path function. - - :param inputs_data: dict[string, dict[string, string]] - """ - for key in inputs_data: - inputs_data[key]["name"] = sanitize_name_input(inputs_data[key]["name"]) - -def sanitize_group_name(group_name): - return group_name.lower().replace(' ', '_') - -def sanitize_name(input_name): - """ - Galaxy will name all the files and dirs as *.dat, - the function can replace '.' to '_' for the dirs - """ - validChars = "_-%s%s" % (string.ascii_letters, string.digits) - sanitized_name = ''.join([c if c in validChars else '_' for c in input_name]) - return "gonramp_" + sanitized_name
--- a/util/subtools.py Wed Oct 25 12:41:34 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +0,0 @@ -#!/usr/bin/env python - -""" -This file include common used functions for converting file format to gff3 -""" -from collections import OrderedDict -import json -import subprocess -import os -import sys -import tempfile -import string -import logging - -class PopenError(Exception): - def __init__(self, cmd, error, return_code): - self.cmd = cmd - self.error = error - self.return_code = return_code - - def __str__(self): - message = "The subprocess {0} has returned the error: {1}.".format( - self.cmd, self.return_code) - message = ','.join( - (message, "Its error message is: {0}".format(self.error))) - return repr(message) - - -def _handleExceptionAndCheckCall(array_call, **kwargs): - """ - This class handle exceptions and call the tool. - It maps the signature of subprocess.check_call: - See https://docs.python.org/2/library/subprocess.html#subprocess.check_call - """ - stdout = kwargs.get('stdout', subprocess.PIPE) - stderr = kwargs.get('stderr', subprocess.PIPE) - shell = kwargs.get('shell', False) - stdin = kwargs.get('stdin', None) - - cmd = array_call[0] - - output = None - error = None - - # TODO: Check the value of array_call and <=[0] - logging.debug("Calling {0}:".format(cmd)) - logging.debug("%s", array_call) - logging.debug("---------") - - # TODO: Use universal_newlines option from Popen? - try: - p = subprocess.Popen(array_call, stdout=stdout, - stderr=stderr, shell=shell, stdin=stdin) - - # TODO: Change this because of possible memory issues => https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate - - output, error = p.communicate() - - if stdout == subprocess.PIPE: - logging.debug("\t{0}".format(output)) - else: - logging.debug("\tOutput in file {0}".format(stdout.name)) - # If we detect an error from the subprocess, then we raise an exception - # TODO: Manage if we raise an exception for everything, or use CRITICAL etc... but not stop process - # TODO: The responsability of returning a sys.exit() should not be there, but up in the app. - if p.returncode: - if stderr == subprocess.PIPE: - raise PopenError(cmd, error, p.returncode) - else: - # TODO: To Handle properly with a design behind, if we received a option as a file for the error - raise Exception("Error when calling {0}. Error as been logged in your file {1}. Error code: {2}".format(cmd, stderr.name, p.returncode)) - - except OSError as e: - message = "The subprocess {0} has encountered an OSError: {1}".format( - cmd, e.strerror) - if e.filename: - message = '\n'.join( - (message, ", against this file: {0}".format(e.filename))) - logging.error(message) - sys.exit(-1) - except PopenError as p: - message = "The subprocess {0} has returned the error: {1}.".format( - p.cmd, p.return_code) - message = '\n'.join( - (message, "Its error message is: {0}".format(p.error))) - - logging.exception(message) - - sys.exit(p.return_code) - except Exception as e: - message = "The subprocess {0} has encountered an unknown error: {1}".format( - cmd, e) - logging.exception(message) - - sys.exit(-1) - return output - -def arrow_add_organism(organism_name, organism_dir, public=False): - array_call = ['arrow', 'organisms', 'add_organism', organism_name, organism_dir] - if public: - array_call.append('--public') - p = _handleExceptionAndCheckCall(array_call) - #p = subprocess.check_output(array_call) - return p - -def arrow_create_user(user_email, firstname, lastname, password, admin=False): - """ Create a new user of Apollo, the default user_role is "user" """ - array_call = ['arrow', 'users', 'create_user', user_email, firstname, lastname, password] - if admin: - array_call += ['--role', 'admin'] - logging.debug("%s", array_call) - print array_call - p = subprocess.check_output(array_call) - print ("p = %s", p) - return p - -def arrow_update_organism_permissions(user_id, organism, **user_permissions): - array_call = ['arrow', 'users', 'update_organism_permissions', str(user_id), str(organism)] - admin = user_permissions.get("admin", False) - write = user_permissions.get("write", False) - read = user_permissions.get("read", False) - export = user_permissions.get("export", False) - if admin: - array_call.append('--administrate') - if write: - array_call.append('--write') - if read: - array_call.append('--read') - if export: - array_call.append('--export') - p = subprocess.check_output(array_call) - return p - -def arrow_get_users(user_email): - array_call = ['arrow', 'users', 'get_users'] - logging.debug("%s", array_call) - print array_call - p = subprocess.check_output(array_call) - all_users = json.loads(p) - for d in all_users: - if d['username'] == user_email: - return d['userId'] - logging.error("Cannot find user %s", user_email) - -def verify_user_login(username, password, apollo_host): - user_info = {'username': username, 'password': password} - array_call = ['curl', - '-b', 'cookies.txt', - '-c', 'cookies.txt', - '-H', 'Content-Type:application/json', - '-d', json.dumps(user_info), - apollo_host + '/Login?operation=login' - ] - p = _handleExceptionAndCheckCall(array_call) - msg = json.loads(p) - if 'error' in msg: - logging.error("The Authentication for user %s failed. Get error message %s", username, msg['error']) - exit(-1) - -