-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
96 lines (76 loc) · 2.35 KB
/
main.py
File metadata and controls
96 lines (76 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import fts
import gfal2
import json
import os
import urlparse
import web
from common import isValidStorageURL
urls = (
'/', 'index',
'/up', 'upload',
'/upload/(.*)', 'uploadStore',
'/transfer', 'transfer',
'/fts', 'ftsConnect',
'/storage', 'storageHandler',
)
voms_db = {}
transfer_db = {}
jobid_db = {}
ftsconnect_db = {}
render = web.template.render('templates/')
gfal = gfal2.creat_context()
class index:
def GET(self):
return render.index()
class upload:
def GET(self):
return render.upload()
class storageHandler:
def GET(self):
query_dict = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))
storageLocation = query_dict.get('location', '')
if not isValidStorageURL(storageLocation.encode('ascii', 'ignore')):
raise web.seeother('/')
os.environ['X509_USER_PROXY'] = '/tmp/x509up_u8365'
print 'storageLocation', storageLocation
locationContents = gfal.listdir(storageLocation)
web.header('Content-Type', 'application/json')
jsonLocContents = json.dumps(map(lambda s: {'name':s}, locationContents))
return jsonLocContents
class uploadStore:
def GET(self, filename):
pass
def POST(self, filename):
data = web.data()
voms_db[filename] = data
print 'size of db entry =', len(voms_db[filename])
# with open('data/'+filename, 'wb') as outfile:
# outfile.write(data)
return 'Successful upload'
class ftsConnect:
def GET(self, filename):
# write the proxy cert to a file
certfilepath = '/tmp/'+filename
with open(certfilepath, 'wb') as certfile:
certfile.write(voms_db[filename])
# point the env var X509_USER_PROXY to its place (i.e. /tmp/x509up_u<uid>)
os.environ['X509_USER_PROXY'] = certfilepath
fts = fts.libftspython.Fts("https://itgt-fts-01.cern.ch:8443")
ftsconnect_db['connection'] = fts
class transfer:
def GET(self):
query_dict = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))
if ('source' and 'dest') in query_dict:
fts = ftsconnect_db['connection']
src = query_dict['source']
dst = query_dict['dest']
file_pair = (src, dst)
job1 = libftspython.Job(file)
id1 = fts.submit(job1)
jobid_db[id1] = job1
else:
print 'The parameters are not present:', query_dict
raise web.seeother('/')
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()