Skip to content
Snippets Groups Projects
Commit 95545c36 authored by Albert Feghaly's avatar Albert Feghaly
Browse files

Merge remote-tracking branch 'origin/master' into 15-allow-to-keep-file-content-in-memory

Conflicts:
	pyiricdata/Client.py
parents d3bccf3e d1724061
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,8 @@ from bs4 import BeautifulSoup ...@@ -10,7 +10,8 @@ from bs4 import BeautifulSoup
import sys import sys
from collections import namedtuple from collections import namedtuple
from .tools import is_json from pyiricdata.tools import is_json
from pyiricdata.exceptions import IricDataConnectionError
IDF = namedtuple('IricDataFile', ['metadata', 'data', 'annotations']) IDF = namedtuple('IricDataFile', ['metadata', 'data', 'annotations'])
...@@ -41,13 +42,11 @@ class Client: ...@@ -41,13 +42,11 @@ class Client:
if login.status_code == 200: if login.status_code == 200:
if any(x in login.text for x in ['Erreur', 'Error']): if any(x in login.text for x in ['Erreur', 'Error']):
sys.stderr.write('ERROR: Connexion failed -- verify your username and password\n') raise IricDataConnectionError('Connexion failed -- verify your username and password')
sys.exit(1)
else: else:
sys.stdout.write('Your connexion to IRIC-Data has been established [user=%s]\n' % self.user) sys.stdout.write('Your connexion to IRIC-Data has been established [user=%s]\n' % self.user)
else: else:
sys.stderr.write('ERROR: Could not initiate connexion with IRIC-Data\n') raise IricDataConnectionError('Could not initiate connexion with IRIC-Data')
sys.exit(1)
self.session = session self.session = session
...@@ -144,9 +143,11 @@ class Client: ...@@ -144,9 +143,11 @@ class Client:
) )
).json() ).json()
df = pd.DataFrame(r['data']) df = pd.DataFrame(r['data']).rename({'id': 'numerical_id'}, axis=1) # id is internal to iric-data
df.index = df.iric_data_id df.index = df.iric_data_id
df.index.name = 'ID' df.index.name = 'ID'
ordering = ['filename', 'numerical_id', 'hash']
df = df[ordering + [x for x in df.columns if x not in ordering]]
return(df) return(df)
...@@ -186,13 +187,20 @@ class Client: ...@@ -186,13 +187,20 @@ class Client:
"get_datafiles_list(dataset_id=dataset_id)\n") "get_datafiles_list(dataset_id=dataset_id)\n")
return(self.get_datafiles_list(dataset_id=dataset_id)) return(self.get_datafiles_list(dataset_id=dataset_id))
""" Get DatasetId by name""" """ Get a subset of the available datasets for which there is a match """
def get_dataset_id_by_name(self, name): def filter_datasets(self, term, exact_match=False):
return self.datasets.loc[self.datasets.dataset_name==name,'dataset_slug'][0] if exact_match:
return self.datasets[self.datasets.dataset_name.str.fullmatch(term)]
else:
return self.datasets[self.datasets.dataset_name.str.contains(term)]
""" Get a subset of the available datasets for which name match a given term """ """ Get a subset of the available datafiles for which there is a match """
def search_dataset_names(self, term): def filter_datafiles(self, term, exact_match=False, **kwargs): # kwargs refer to get_datafiles_list arguments
return self.datasets.loc[self.datasets.dataset_name.str.contains(term),:] df = self.get_datafiles_list(**kwargs)
if exact_match:
return df[df.filename.str.fullmatch(term)]
else:
return df[df.filename.str.contains(term)]
""" Get file content according to file_id """ """ Get file content according to file_id """
def get_file(self, file_id): def get_file(self, file_id):
...@@ -434,8 +442,6 @@ class Client: ...@@ -434,8 +442,6 @@ class Client:
if resp.status_code == 200: if resp.status_code == 200:
print('File update succesful on {}'.format(file_id)) print('File update succesful on {}'.format(file_id))
else: else:
sys.stderr.write('ERROR: something went wrong during datafiles update\n') raise IricDataConnectionError('Something went wrong during datafile update')
sys.exit(2)
else: else:
sys.stderr.write('FAILED: At least one error has occured, please fix them and try again.\n') raise IricDataConnectionError('At least one error has occured, please investigate and try again.')
sys.exit(1)
#!/usr/bin/env python3
class IricDataConnectionError(Exception):
def __init__(self, message):
super().__init__(message)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment