-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtesInputFiler.py
155 lines (122 loc) · 4.09 KB
/
tesInputFiler.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python3
####################################################################################
#
# Copyright (c) 2018 Thanasis Vergoulis & Konstantinos Zagganas & Loukas Kavouras
# for the Information Management Systems Institute, "Athena" Research Center.
#
# This file is part of SCHeMa.
#
# SCHeMa is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SCHeMa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar. If not, see <https://www.gnu.org/licenses/>.
#
####################################################################################
import subprocess
import os.path
import re
def getInputs(data,folder,config):
allowedTypes=set(['http','ftp'])
mounts=set()
referenceMounts=set()
try:
inputs=data['inputs']
except:
return 1,set(),set()
try:
outputs=data['outputs']
except:
return 2,set(),set()
for inpt in inputs:
try:
url=inpt['url']
except:
return 3,set(),set()
try:
path=inpt['path']
except:
return 4,set(),set()
path=path.split('/')
mpath='/'.join(path[:-1])
folderName=path[-2]
localFilename=path[-1]
localFolder=folder + '/' + folderName
localFilepath=localFolder + '/' + localFilename
if not os.path.exists(localFolder):
subprocess.call(['mkdir','-p',localFolder])
urlTok=url.split(':')
protocol=urlTok[0]
try:
remoteFilename=url.split('/')[-1]
except:
return 9,set(),set()
if protocol not in allowedTypes:
return 5,set(),set()
if protocol=='http':
returnCode=subprocess.call(['wget', '-O', localFilepath, url])
if returnCode!=0:
return 8,set(),set()
elif protocol=='ftp':
patt=re.compile("ftp://([^/ ]+)/.+")
try:
server=patt.match(url).groups()[0]
except:
return 6,set(),set()
try:
creds=config['ftp-creds'][server]
except:
return 7,set(),set()
username=creds['username']
password=creds['password']
commUser='--ftp-user=' + username
commPass="--ftp-password=" + password
returnCode=subprocess.call(['wget', '-O',localFilepath,commUser,commPass,url])
if returnCode!=0:
return 8,set(),set()
mount=(localFolder,mpath)
mounts.add(mount)
subprocess.call(['chmod','777',localFolder,'-R'])
for outpt in outputs:
try:
url=outpt['url']
except:
return 10,set(),set()
try:
path=outpt['path']
except:
return 11,set(),set()
path=path.split('/')
mpath='/'.join(path[:-1])
folderName=path[-2]
localFilename=path[-1]
localFolder=folder + '/' + folderName
localFilepath=localFolder + '/' + localFilename
if not os.path.exists(localFolder):
subprocess.call(['mkdir','-p',localFolder])
mount=(localFolder,mpath)
mounts.add(mount)
subprocess.call(['chmod','777',localFolder,'-R'])
reference=[]
try:
reference=data['reference_data']
except:
pass
for ref in reference:
try:
path=ref['path']
except:
return 12,set(),set()
try:
cpath=ref['container_path']
except:
return 13,set(),set()
referenceMounts.add((path,cpath))
return 0, list(mounts), list(referenceMounts)