Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def download_xnat_file(self, src, dst):
"""Download XNAT specific file."""
results = None
with XnatUtils.get_interface(host=self.host, user=self.user,
pwd=self.pwd) as xnat:
try:
_res, _file = src.split('/files/')
res = xnat.select(_res)
if not res.exists():
msg = 'resources specified by %s not found on XNAT.'
raise AutoSpiderError(msg % src)
except Exception:
msg = 'resources can not be checked because the path given is \
wrong for XNAT. Please check https://wiki.xnat.org/display/XNAT16/\
XNAT+REST+API+Directory for the path.'
raise AutoSpiderError(msg % src)
try:
results = res.file(_file).get(dst)
except Exception:
raise AutoSpiderError('downloading files from XNAT failed.')
return results
pwd=self.pwd) as xnat:
try:
_res, _file = src.split('/files/')
res = xnat.select(_res)
if not res.exists():
msg = 'resources specified by %s not found on XNAT.'
raise AutoSpiderError(msg % src)
except Exception:
msg = 'resources can not be checked because the path given is \
wrong for XNAT. Please check https://wiki.xnat.org/display/XNAT16/\
XNAT+REST+API+Directory for the path.'
raise AutoSpiderError(msg % src)
try:
results = res.file(_file).get(dst)
except Exception:
raise AutoSpiderError('downloading files from XNAT failed.')
return results
except Exception:
msg = 'resources can not be checked because the path given is \
wrong for XNAT: %s. Please check https://wiki.xnat.org/display/XNAT16/\
XNAT+REST+API+Directory for the path.'
raise AutoSpiderError(msg % src)
try:
# res.get(dst, extract=True)
results = XnatUtils.download_files_from_obj(dst, res)
if len(results) == 1:
return results[0]
else:
return results
except Exception as err:
print(err)
raise AutoSpiderError('downloading resource from XNAT failed.')
return results
def download_xnat_resource(self, src, dst):
"""Download XNAT complete resource."""
results = None
with XnatUtils.get_interface(host=self.host, user=self.user,
pwd=self.pwd) as xnat:
try:
res = xnat.select(src)
if not res.exists():
msg = 'resources specified by %s not found on XNAT.'
raise AutoSpiderError(msg % src)
except Exception:
msg = 'resources can not be checked because the path given is \
wrong for XNAT: %s. Please check https://wiki.xnat.org/display/XNAT16/\
XNAT+REST+API+Directory for the path.'
raise AutoSpiderError(msg % src)
try:
# res.get(dst, extract=True)
results = XnatUtils.download_files_from_obj(dst, res)
if len(results) == 1:
return results[0]
else:
return results
except Exception as err:
print(err)
raise AutoSpiderError('downloading resource from XNAT failed.')
return results
# Write the script
with open(filepath, 'w') as f:
f.write(template.substitute(self.run_inputs))
if not self.exe_lang:
if self.template.startswith('#PYTHON'):
self.exe_lang = 'python'
elif self.template.startswith('%MATLAB'):
self.exe_lang = 'matlab'
elif self.template.startswith('#RUBY'):
self.exe_lang = 'ruby'
elif self.template.startswith('#BASH'):
self.exe_lang = 'bash'
else:
raise AutoSpiderError('Template Unknown. Please add #BASH/\
#PYTHON/#RUBY/#MATLAB at the beginning of the call file and rerun \
GeneratorAutoSpider.')
self.succeeded = run_cmd(self.exe_lang, filepath,
time_writer=self.time_writer,
matlab_bin=self.matlab_bin)