Mercurial > repos > yating-l > gonramp_apollo_tools
annotate util/subtools.py @ 0:ce4f91831680 draft default tip
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
author | yating-l |
---|---|
date | Fri, 16 Feb 2018 10:57:13 -0500 |
parents | |
children |
rev | line source |
---|---|
0
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
1 #!/usr/bin/env python |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
2 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
3 """ |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
4 This file include common used functions for converting file format to gff3 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
5 """ |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
6 from collections import OrderedDict |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
7 import json |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
8 import subprocess |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
9 import os |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
10 import sys |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
11 import tempfile |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
12 import string |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
13 import logging |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
14 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
15 class PopenError(Exception): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
16 def __init__(self, cmd, error, return_code): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
17 self.cmd = cmd |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
18 self.error = error |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
19 self.return_code = return_code |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
20 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
21 def __str__(self): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
22 message = "The subprocess {0} has returned the error: {1}.".format( |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
23 self.cmd, self.return_code) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
24 message = ','.join( |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
25 (message, "Its error message is: {0}".format(self.error))) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
26 return repr(message) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
27 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
28 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
29 def _handleExceptionAndCheckCall(array_call, **kwargs): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
30 """ |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
31 This class handle exceptions and call the tool. |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
32 It maps the signature of subprocess.check_call: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
33 See https://docs.python.org/2/library/subprocess.html#subprocess.check_call |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
34 """ |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
35 stdout = kwargs.get('stdout', subprocess.PIPE) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
36 stderr = kwargs.get('stderr', subprocess.PIPE) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
37 shell = kwargs.get('shell', False) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
38 stdin = kwargs.get('stdin', None) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
39 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
40 cmd = array_call[0] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
41 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
42 output = None |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
43 error = None |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
44 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
45 # TODO: Check the value of array_call and <=[0] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
46 logging.debug("Calling {0}:".format(cmd)) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
47 logging.debug("%s", array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
48 logging.debug("---------") |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
49 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
50 # TODO: Use universal_newlines option from Popen? |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
51 try: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
52 p = subprocess.Popen(array_call, stdout=stdout, |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
53 stderr=stderr, shell=shell, stdin=stdin) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
54 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
55 # TODO: Change this because of possible memory issues => https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
56 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
57 output, error = p.communicate() |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
58 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
59 if stdout == subprocess.PIPE: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
60 logging.debug("\t{0}".format(output)) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
61 else: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
62 logging.debug("\tOutput in file {0}".format(stdout.name)) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
63 # If we detect an error from the subprocess, then we raise an exception |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
64 # TODO: Manage if we raise an exception for everything, or use CRITICAL etc... but not stop process |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
65 # TODO: The responsability of returning a sys.exit() should not be there, but up in the app. |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
66 if p.returncode: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
67 if stderr == subprocess.PIPE: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
68 raise PopenError(cmd, error, p.returncode) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
69 else: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
70 # TODO: To Handle properly with a design behind, if we received a option as a file for the error |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
71 raise Exception("Error when calling {0}. Error as been logged in your file {1}. Error code: {2}".format(cmd, stderr.name, p.returncode)) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
72 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
73 except OSError as e: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
74 message = "The subprocess {0} has encountered an OSError: {1}".format( |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
75 cmd, e.strerror) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
76 if e.filename: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
77 message = '\n'.join( |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
78 (message, ", against this file: {0}".format(e.filename))) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
79 logging.error(message) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
80 sys.exit(-1) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
81 except PopenError as p: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
82 message = "The subprocess {0} has returned the error: {1}.".format( |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
83 p.cmd, p.return_code) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
84 message = '\n'.join( |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
85 (message, "Its error message is: {0}".format(p.error))) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
86 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
87 logging.exception(message) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
88 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
89 sys.exit(p.return_code) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
90 except Exception as e: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
91 message = "The subprocess {0} has encountered an unknown error: {1}".format( |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
92 cmd, e) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
93 logging.exception(message) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
94 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
95 sys.exit(-1) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
96 return output |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
97 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
98 def arrow_add_organism(organism_name, organism_dir, public=False): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
99 array_call = ['arrow', 'organisms', 'add_organism', organism_name, organism_dir] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
100 if public: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
101 array_call.append('--public') |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
102 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
103 #p = subprocess.check_output(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
104 return p |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
105 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
106 def arrow_create_user(user_email, firstname, lastname, password, admin=False): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
107 """ |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
108 Create a new user of Apollo, the default user_role is "user" |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
109 """ |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
110 array_call = ['arrow', 'users', 'create_user', user_email, firstname, lastname, password] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
111 if admin: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
112 array_call += ['--role', 'admin'] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
113 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
114 j = json.loads(p) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
115 if "userId" in j: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
116 return j['userId'] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
117 elif "error" in j: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
118 logging.error("Got error message: %s", j['error']) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
119 exit(-1) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
120 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
121 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
122 def arrow_delete_user(user_email): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
123 array_call = ['arrow', 'users', 'delete_user', user_email] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
124 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
125 j = json.loads(p) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
126 if "error" in j: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
127 logging.error("Got error message: %s", j['error']) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
128 exit(-1) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
129 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
130 def arrow_add_to_group(groupname, user_email): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
131 if not arrow_get_groups(groupname): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
132 arrow_create_group(groupname) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
133 array_call = ['arrow', 'users', 'add_to_group', groupname, user_email] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
134 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
135 j = json.loads(p) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
136 if j != dict(): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
137 logging.error("Error add user %s to group %s. The user doesn't exist", user_email, groupname) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
138 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
139 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
140 def arrow_remove_from_group(groupname, user_email): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
141 if arrow_get_groups(groupname): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
142 array_call = ['arrow', 'users', 'remove_from_group', groupname, user_email] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
143 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
144 j = json.loads(p) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
145 if j != dict(): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
146 logging.error("Error remove user %s to group %s. The user doesn't exist", user_email, groupname) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
147 else: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
148 logging.error("Group %s doesn't exist. Check if you spell the name correctly", groupname) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
149 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
150 def arrow_create_group(groupname): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
151 if arrow_get_groups(groupname): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
152 logging.error("Group %s already exist. Create a group with another name.", groupname) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
153 array_call = ['arrow', 'groups', 'create_group', groupname] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
154 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
155 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
156 def arrow_get_groups(groupname): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
157 array_call = ['arrow', 'groups', 'get_groups'] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
158 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
159 all_groups = json.loads(p) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
160 for g in all_groups: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
161 if g['name'] == groupname: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
162 return True |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
163 return False |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
164 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
165 def arrow_update_organism_permissions(user_id, organism, **user_permissions): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
166 array_call = ['arrow', 'users', 'update_organism_permissions', str(user_id), str(organism)] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
167 admin = user_permissions.get("admin", False) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
168 write = user_permissions.get("write", False) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
169 read = user_permissions.get("read", False) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
170 export = user_permissions.get("export", False) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
171 if admin: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
172 array_call.append('--administrate') |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
173 if write: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
174 array_call.append('--write') |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
175 if read: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
176 array_call.append('--read') |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
177 if export: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
178 array_call.append('--export') |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
179 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
180 return p |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
181 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
182 def arrow_get_users(user_email): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
183 array_call = ['arrow', 'users', 'get_users'] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
184 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
185 all_users = json.loads(p) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
186 for d in all_users: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
187 if d['username'] == user_email: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
188 return d['userId'] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
189 logging.error("Cannot find user %s", user_email) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
190 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
191 def arrow_get_organism(organism_name): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
192 array_call= ['arrow', 'organisms', 'get_organisms', '--common_name', organism_name] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
193 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
194 org = json.loads(p) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
195 if 'error' not in org: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
196 return org[0]['id'] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
197 else: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
198 logging.debug("Got error msg %s when look for organism %s.", org['error'], organism_name) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
199 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
200 def arrow_delete_organism(organism_id): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
201 array_call = ['arrow', 'organisms', 'delete_organism', str(organism_id)] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
202 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
203 return p |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
204 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
205 def verify_user_login(username, password, apollo_host): |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
206 user_info = {'username': username, 'password': password} |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
207 array_call = ['curl', |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
208 '-b', 'cookies.txt', |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
209 '-c', 'cookies.txt', |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
210 '-H', 'Content-Type:application/json', |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
211 '-d', json.dumps(user_info), |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
212 apollo_host + '/Login?operation=login' |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
213 ] |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
214 p = _handleExceptionAndCheckCall(array_call) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
215 msg = json.loads(p) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
216 if 'error' in msg: |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
217 logging.error("The Authentication for user %s failed. Get error message %s", username, msg['error']) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
218 exit(-1) |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
219 |
ce4f91831680
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
yating-l
parents:
diff
changeset
|
220 |