Mercurial > repos > geco-team > gmql_download
annotate utilities.py @ 0:35d52820e7c7 draft default tip
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
author | geco-team |
---|---|
date | Tue, 26 Jun 2018 09:01:39 -0400 |
parents | |
children |
rev | line source |
---|---|
0
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
1 # Helper functions to perform REST calls on the GMQL server. |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
2 # ---------------------------------------------------------------------------- |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
3 # Luana Brancato, luana.brancato@mail.polimi.it |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
4 # ---------------------------------------------------------------------------- |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
5 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
6 import sys |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
7 import os |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
8 import yaml |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
9 import requests |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
10 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
11 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
12 def load_parts(module, call) : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
13 """Given the module and the single operation, returns the fragments for the url to call""" |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
14 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
15 y_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),'gmql_rest.yaml') |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
16 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
17 with open(y_path,'r') as yamlf : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
18 cfg = yaml.load(yamlf) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
19 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
20 parts = list () |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
21 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
22 gmql = cfg['GMQL_URL'] |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
23 prefix = cfg[module]['prefix'] |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
24 op = cfg[module]['operations'][call] |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
25 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
26 parts.append(gmql) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
27 if prefix : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
28 parts.append(prefix) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
29 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
30 for p in op : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
31 parts.append(p) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
32 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
33 return parts |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
34 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
35 def compose_url(module, call) : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
36 """Given the fragments of a url, return the composite one""" |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
37 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
38 parts = load_parts(module,call) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
39 url = '/'.join(parts) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
40 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
41 return url |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
42 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
43 def add_url_param(params, module, op, value,) : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
44 """Given the params dict, add a new pair of key:value with the given value and the key set for given module and operation""" |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
45 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
46 y_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'gmql_rest.yaml') |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
47 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
48 with open(y_path, 'r') as yamlf: |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
49 cfg = yaml.load(yamlf) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
50 yamlf.close() |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
51 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
52 key = cfg[module]['params'][op] |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
53 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
54 params.update({key : value}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
55 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
56 return params |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
57 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
58 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
59 def read_token(input): |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
60 """It takes the tabular file with the information over the user |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
61 name authToken valid_flag |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
62 It checks if the user is still valid and extract the authToken for the REST calls""" |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
63 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
64 with open(input,'r') as f_in : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
65 user = f_in.readline().rstrip('\n').split('\t') |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
66 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
67 if user[2] : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
68 token = user[1] |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
69 else : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
70 stop_err("This session is no longer valid") |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
71 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
72 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
73 return token |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
74 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
75 def expire_user(input): |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
76 """Set the validity flag of a user token to false""" |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
77 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
78 with open(input,'r') as f: |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
79 user = f.readline().rstrip('\n').split('\t') |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
80 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
81 user[2] = False |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
82 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
83 with open(input,'w') as f : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
84 f.write('{fullName}\t{token}\t{valid}\n'.format(fullName=user[0], token=user[1], |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
85 valid=user[2])) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
86 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
87 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
88 def get(url, user=None, response_type='json') : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
89 """GET Request |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
90 :param url: url where to fetch the requested resource |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
91 :param user: for authenticated requests; if not provided make an unauthenticated request (es. for login) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
92 :param response_type: type of the fetched response. |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
93 JSON ( Default ) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
94 TEXT |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
95 ZIP |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
96 FILE |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
97 """ |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
98 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
99 #Set request headers |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
100 headers = dict () |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
101 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
102 if user : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
103 headers.update({'X-AUTH-TOKEN' : read_token(user)}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
104 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
105 if response_type == 'text' : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
106 headers.update({'Accept' : 'text/plain'}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
107 elif response_type == 'zip' : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
108 pass |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
109 elif response_type == 'file' : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
110 headers.update({'Accept' : 'file'}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
111 else : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
112 headers.update({'Accept' : 'application/json'}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
113 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
114 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
115 #Make the request |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
116 response = requests.get(url, headers=headers) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
117 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
118 #Check returned server status |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
119 status_code = response.status_code |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
120 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
121 #Read result. If Server OK, read according to response_type. Raise an error otherwise. |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
122 if status_code == requests.codes.ok : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
123 if response_type == 'json' : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
124 return response.json() |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
125 elif response_type == 'text' : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
126 return response.text |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
127 else : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
128 return response |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
129 elif status_code == requests.codes.unauthorized : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
130 expire_user(user) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
131 stop_err("You are not authorized to do this. \nPlease login first.") |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
132 elif status_code == requests.codes.not_found : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
133 stop_err("Resource not found for this user.") |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
134 else : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
135 stop_err("Error {code}: {reason}\n{message}".format(code=status_code, |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
136 reason=response.reason, |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
137 message=response.content)) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
138 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
139 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
140 def post(url, payload, user=None, params=None, content_type='json', response_type='json') : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
141 """ POST Request |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
142 :param url: url where to post data |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
143 :param payload: payload for the post request. Type is specified by content_type. |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
144 :param user: for authenticated requests; if not provided make an unauthenticated request (es. for registration) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
145 :param params: optional query parameters |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
146 :param content_type |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
147 :param response_type: Default is json |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
148 """ |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
149 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
150 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
151 # Set request headers |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
152 headers = dict() |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
153 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
154 if user: |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
155 headers.update({'X-AUTH-TOKEN': read_token(user)}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
156 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
157 headers.update({'Accept': 'application/json'}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
158 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
159 if content_type == 'text' : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
160 headers.update({'Content-Type' : 'text/plain'}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
161 response = requests.post(url, params=params, headers=headers, data=payload) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
162 elif content_type == 'multiform' : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
163 response = requests.post(url, params=params, headers=headers, files=payload) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
164 else : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
165 headers.update({'Content-Type': 'application/json'}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
166 response = requests.post(url, params=params, headers=headers, json=payload) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
167 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
168 # Check returned server status |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
169 status_code = response.status_code |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
170 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
171 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
172 if status_code == requests.codes.ok : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
173 return response.json() |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
174 elif status_code == requests.codes.unauthorized : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
175 content = response.content |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
176 if content.__contains__("The username or password you entered don't match") : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
177 stop_err("The username or password you entered don't match") |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
178 else: |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
179 expire_user(user) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
180 stop_err("You are not authorized to do this. \nPlease login first.") |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
181 else : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
182 stop_err("Error {code}: {reason}\n{message}".format(code=status_code, |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
183 reason=response.reason, |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
184 message=response.content)) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
185 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
186 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
187 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
188 def delete(url, user=None, response_type='json') : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
189 """DELETE request |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
190 :param url: url where to post data |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
191 :param user: for authenticated requests; if not provided make an unauthenticated request (es. for registration) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
192 :param response_type: Default is json |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
193 """ |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
194 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
195 # Set request headers |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
196 headers = dict() |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
197 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
198 if user: |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
199 headers.update({'X-AUTH-TOKEN': read_token(user)}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
200 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
201 headers.update({'Accept': 'application/json'}) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
202 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
203 #Make the request |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
204 response = requests.delete(url, headers=headers) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
205 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
206 #Check returned server status |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
207 status_code = response.status_code |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
208 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
209 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
210 #If Server OK, read result. Raise an error otherwise. |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
211 if status_code == requests.codes.ok : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
212 return response.json() |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
213 elif status_code == requests.codes.unauthorized : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
214 expire_user(user) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
215 stop_err("You are not authorized to do this. \nPlease login first.") |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
216 elif status_code == requests.codes.not_found : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
217 stop_err("Resource not found for this user.") |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
218 else : |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
219 stop_err("Error {code}: {reason}".format(code=status_code, |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
220 reason=response.reason)) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
221 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
222 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
223 |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
224 def stop_err(msg): |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
225 sys.stderr.write("%s\n" % msg) |
35d52820e7c7
planemo upload for repository https://github.com/lu-brn/gmql-galaxy commit 953ee36ceda5814dc9baa03427bc0eb4ee2e93bd-dirty
geco-team
parents:
diff
changeset
|
226 sys.exit() |