Mercurial > repos > yating-l > jbrowsehubtoapollo
annotate util/subtools.py @ 2:8ff4b84d709f draft
planemo upload for repository https://github.com/Yating-L/jbrowsehub-to-apollo.git commit 324276a31f1d9e410c37d4514ad9432ba6051e35-dirty
author | yating-l |
---|---|
date | Wed, 25 Oct 2017 12:41:34 -0400 |
parents | 2ae1e96a8380 |
children |
rev | line source |
---|---|
0
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
1 #!/usr/bin/env python |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
2 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
3 """ |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
4 This file include common used functions for converting file format to gff3 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
5 """ |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
6 from collections import OrderedDict |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
7 import json |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
8 import subprocess |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
9 import os |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
10 import sys |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
11 import tempfile |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
12 import string |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
13 import logging |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
14 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
15 class PopenError(Exception): |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
16 def __init__(self, cmd, error, return_code): |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
17 self.cmd = cmd |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
18 self.error = error |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
19 self.return_code = return_code |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
20 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
21 def __str__(self): |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
22 message = "The subprocess {0} has returned the error: {1}.".format( |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
23 self.cmd, self.return_code) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
24 message = ','.join( |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
25 (message, "Its error message is: {0}".format(self.error))) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
26 return repr(message) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
27 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
28 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
29 def _handleExceptionAndCheckCall(array_call, **kwargs): |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
30 """ |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
31 This class handle exceptions and call the tool. |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
32 It maps the signature of subprocess.check_call: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
33 See https://docs.python.org/2/library/subprocess.html#subprocess.check_call |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
34 """ |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
35 stdout = kwargs.get('stdout', subprocess.PIPE) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
36 stderr = kwargs.get('stderr', subprocess.PIPE) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
37 shell = kwargs.get('shell', False) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
38 stdin = kwargs.get('stdin', None) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
39 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
40 cmd = array_call[0] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
41 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
42 output = None |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
43 error = None |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
44 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
45 # TODO: Check the value of array_call and <=[0] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
46 logging.debug("Calling {0}:".format(cmd)) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
47 logging.debug("%s", array_call) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
48 logging.debug("---------") |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
49 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
50 # TODO: Use universal_newlines option from Popen? |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
51 try: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
52 p = subprocess.Popen(array_call, stdout=stdout, |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
53 stderr=stderr, shell=shell, stdin=stdin) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
54 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
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 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
56 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
57 output, error = p.communicate() |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
58 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
59 if stdout == subprocess.PIPE: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
60 logging.debug("\t{0}".format(output)) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
61 else: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
62 logging.debug("\tOutput in file {0}".format(stdout.name)) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
63 # If we detect an error from the subprocess, then we raise an exception |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
64 # TODO: Manage if we raise an exception for everything, or use CRITICAL etc... but not stop process |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
65 # TODO: The responsability of returning a sys.exit() should not be there, but up in the app. |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
66 if p.returncode: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
67 if stderr == subprocess.PIPE: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
68 raise PopenError(cmd, error, p.returncode) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
69 else: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
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 |
1
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
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)) |
0
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
72 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
73 except OSError as e: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
74 message = "The subprocess {0} has encountered an OSError: {1}".format( |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
75 cmd, e.strerror) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
76 if e.filename: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
77 message = '\n'.join( |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
78 (message, ", against this file: {0}".format(e.filename))) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
79 logging.error(message) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
80 sys.exit(-1) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
81 except PopenError as p: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
82 message = "The subprocess {0} has returned the error: {1}.".format( |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
83 p.cmd, p.return_code) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
84 message = '\n'.join( |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
85 (message, "Its error message is: {0}".format(p.error))) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
86 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
87 logging.exception(message) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
88 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
89 sys.exit(p.return_code) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
90 except Exception as e: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
91 message = "The subprocess {0} has encountered an unknown error: {1}".format( |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
92 cmd, e) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
93 logging.exception(message) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
94 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
95 sys.exit(-1) |
1
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
96 return output |
0
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
97 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
98 def arrow_add_organism(organism_name, organism_dir, public=False): |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
99 array_call = ['arrow', 'organisms', 'add_organism', organism_name, organism_dir] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
100 if public: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
101 array_call.append('--public') |
1
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
102 p = _handleExceptionAndCheckCall(array_call) |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
103 #p = subprocess.check_output(array_call) |
0
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
104 return p |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
105 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
106 def arrow_create_user(user_email, firstname, lastname, password, admin=False): |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
107 """ Create a new user of Apollo, the default user_role is "user" """ |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
108 array_call = ['arrow', 'users', 'create_user', user_email, firstname, lastname, password] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
109 if admin: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
110 array_call += ['--role', 'admin'] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
111 logging.debug("%s", array_call) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
112 print array_call |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
113 p = subprocess.check_output(array_call) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
114 print ("p = %s", p) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
115 return p |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
116 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
117 def arrow_update_organism_permissions(user_id, organism, **user_permissions): |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
118 array_call = ['arrow', 'users', 'update_organism_permissions', str(user_id), str(organism)] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
119 admin = user_permissions.get("admin", False) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
120 write = user_permissions.get("write", False) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
121 read = user_permissions.get("read", False) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
122 export = user_permissions.get("export", False) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
123 if admin: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
124 array_call.append('--administrate') |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
125 if write: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
126 array_call.append('--write') |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
127 if read: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
128 array_call.append('--read') |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
129 if export: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
130 array_call.append('--export') |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
131 p = subprocess.check_output(array_call) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
132 return p |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
133 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
134 def arrow_get_users(user_email): |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
135 array_call = ['arrow', 'users', 'get_users'] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
136 logging.debug("%s", array_call) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
137 print array_call |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
138 p = subprocess.check_output(array_call) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
139 all_users = json.loads(p) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
140 for d in all_users: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
141 if d['username'] == user_email: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
142 return d['userId'] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
143 logging.error("Cannot find user %s", user_email) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
144 |
2
8ff4b84d709f
planemo upload for repository https://github.com/Yating-L/jbrowsehub-to-apollo.git commit 324276a31f1d9e410c37d4514ad9432ba6051e35-dirty
yating-l
parents:
1
diff
changeset
|
145 def verify_user_login(username, password, apollo_host): |
1
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
146 user_info = {'username': username, 'password': password} |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
147 array_call = ['curl', |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
148 '-b', 'cookies.txt', |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
149 '-c', 'cookies.txt', |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
150 '-H', 'Content-Type:application/json', |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
151 '-d', json.dumps(user_info), |
2
8ff4b84d709f
planemo upload for repository https://github.com/Yating-L/jbrowsehub-to-apollo.git commit 324276a31f1d9e410c37d4514ad9432ba6051e35-dirty
yating-l
parents:
1
diff
changeset
|
152 apollo_host + '/Login?operation=login' |
1
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
153 ] |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
154 p = _handleExceptionAndCheckCall(array_call) |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
155 msg = json.loads(p) |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
156 if 'error' in msg: |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
157 logging.error("The Authentication for user %s failed. Get error message %s", username, msg['error']) |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
158 exit(-1) |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
159 |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
160 |