Skip to content
Snippets Groups Projects

Resolve "Lacking sanity checks to iricdata connection"

Merged Albert Feghaly requested to merge 21-lacking-sanity-checks-to-iricdata-connection into master
All threads resolved!
+ 23
5
@@ -269,6 +269,18 @@ class Client:
annotation = annotation.json()
return annotation
def get_file_content(self, file_id):
"""Returns datafile content for a given file_id"""
conn = self.get_file_data_conn(file_id)
if conn is not None:
return conn.content
else:
return None
""" Return a connector of the contents of a file for a given file_id """
def get_file_data_conn(self, file_id):
dwnl_url = os.path.join(self.url,
@@ -297,17 +309,22 @@ class Client:
"""
def filter_datafiles(self, term, field='filename', exact_match=False, **kwargs):
df = self.get_datafiles_list(**kwargs)
if exact_match:
return df[df[field].str.fullmatch(term)]
if df is None:
sys.stderr.write("Please try again with more arguments, for more details please see function get_datafiles_list()")
return None
elif df.empty:
return None
else:
return df[df[field].str.contains(term)]
if exact_match:
return df[df[field].str.fullmatch(term)]
else:
return df[df[field].str.contains(term)]
""" Get file content according to file_id """
def get_file(self, file_id):
try:
file_metadata = self.get_file_metadata(file_id)
file_content = self.get_file_data_conn(file_id).content
file_content = self.get_file_content(file_id)
file_annotation = self.get_file_annotation(file_id)
return IDF(file_metadata, file_content, file_annotation)
except TypeError:
@@ -326,6 +343,7 @@ class Client:
filename = file_meta['filename'] if filename is None else filename
out_file_path = os.path.join(folder_out, filename)
file_conn = self.get_file_data_conn(file_id)
assert file_conn is not None # should never be None here
if os.path.exists(out_file_path):
sys.stderr.write('Warning: File already exists at ' +
'location %s, skipping.\n' % out_file_path)
Loading