Mercurial > repos > yating-l > jbrowsehubtoapollo
annotate util/subtools.py @ 1:2ae1e96a8380 draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
author | yating-l |
---|---|
date | Tue, 24 Oct 2017 18:24:40 -0400 |
parents | bc00f5c4c59e |
children | 8ff4b84d709f |
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. |
1
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
66 #if p.returncode: |
0
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
67 if p.returncode: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
68 if stderr == subprocess.PIPE: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
69 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
|
70 else: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
71 # 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
|
72 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
|
73 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
74 except OSError as e: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
75 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
|
76 cmd, e.strerror) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
77 if e.filename: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
78 message = '\n'.join( |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
79 (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
|
80 logging.error(message) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
81 sys.exit(-1) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
82 except PopenError as p: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
83 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
|
84 p.cmd, p.return_code) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
85 message = '\n'.join( |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
86 (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
|
87 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
88 logging.exception(message) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
89 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
90 sys.exit(p.return_code) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
91 except Exception as e: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
92 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
|
93 cmd, e) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
94 logging.exception(message) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
95 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
96 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
|
97 return output |
0
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
98 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
99 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
|
100 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
|
101 if public: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
102 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
|
103 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
|
104 #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
|
105 return p |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
106 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
107 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
|
108 """ 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
|
109 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
|
110 if admin: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
111 array_call += ['--role', 'admin'] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
112 logging.debug("%s", array_call) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
113 print array_call |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
114 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
|
115 print ("p = %s", p) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
116 return p |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
117 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 if admin: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
125 array_call.append('--administrate') |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
126 if write: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
127 array_call.append('--write') |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
128 if read: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
129 array_call.append('--read') |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
130 if export: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
131 array_call.append('--export') |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
132 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
|
133 return p |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
134 |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
135 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
|
136 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
|
137 logging.debug("%s", array_call) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
138 print array_call |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
139 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
|
140 all_users = json.loads(p) |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
141 for d in all_users: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
142 if d['username'] == user_email: |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
143 return d['userId'] |
bc00f5c4c59e
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff
changeset
|
144 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
|
145 |
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 def verify_user_login(username, 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 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
|
148 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
|
149 '-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
|
150 '-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
|
151 '-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
|
152 '-d', json.dumps(user_info), |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
153 'http://localhost:8080/apollo/Login?operation=login' |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
154 ] |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 |
2ae1e96a8380
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents:
0
diff
changeset
|
161 |