diff --git a/src/cal_tools/tools.py b/src/cal_tools/tools.py index cf8443dba5c768ee6975816aa96e86b2680a2561..ae42e894f36f81776bef0b77f813b76f127e2938 100644 --- a/src/cal_tools/tools.py +++ b/src/cal_tools/tools.py @@ -21,11 +21,9 @@ import yaml import zmq from extra_data import H5File, RunDirectory from iCalibrationDB import ConstantMetaData, Versions -from metadata_client.metadata_client import MetadataClient from notebook.notebookapp import list_running_servers from .ana_tools import save_dict_to_hdf5 -from .restful_config import restful_config def parse_runs(runs, return_type=str): @@ -248,53 +246,6 @@ def get_notebook_name(): return environ.get("CAL_NOTEBOOK_NAME", "Unknown Notebook") -def get_run_info(proposal, run): - """Return information about run from the MDC - - :param proposal: proposal number - :param run: run number - :return: dictionary with run information - """ - - mdc_config = restful_config['mdc'] - mdc = MetadataClient( - client_id=mdc_config['user-id'], - client_secret=mdc_config['user-secret'], - user_email=mdc_config['user-email'], - token_url=mdc_config['token-url'], - refresh_url=mdc_config['refresh-url'], - auth_url=mdc_config['auth-url'], - scope=mdc_config['scope'], - base_api_url=mdc_config['base-api-url'], - ) - - mdc_response = mdc.get_proposal_runs( - proposal_number=proposal, run_number=run) - - if mdc_response["success"]: - return mdc_response - else: # empty dictionary for wrong proposal or run. - raise KeyError(mdc_response['app_info']) - - -def creation_date_metadata_client( - proposal: int, run: int -) -> datetime.datetime: - """Get run directory creation date from myMDC using metadata client. - using method `get_proposal_runs`. - - :param proposal: proposal number e.g. 2656 or 900113. - :param run: run number. - :return Optional[datetime.datetime]: Run creation date. - """ - - run_info = get_run_info(proposal, run) - return datetime.datetime.strptime( - run_info['data']['runs'][0]['begin_at'], - "%Y-%m-%dT%H:%M:%S.%f%z", - ).astimezone(datetime.timezone.utc) - - def creation_date_file_metadata( run_folder: Path, ) -> Optional[datetime.datetime]: @@ -357,10 +308,7 @@ def get_dir_creation_date(directory: Union[str, Path], run: int, :return: creation datetime for the directory. """ - directory = Path(directory) - - proposal = int(directory.parent.name[1:]) - directory = directory / 'r{:04d}'.format(run) + directory = Path(directory, f'r{run:04d}') # Validate the availability of the input folder. # And show a clear error message, if it was not found. @@ -371,18 +319,12 @@ def get_dir_creation_date(directory: Union[str, Path], run: int, "- Failed to read creation time, wrong input folder", directory) from e - try: - return creation_date_metadata_client(proposal, run) - except Exception as e: - if verbosity > 0: - print(e) - cdate = creation_date_train_timestamp(dc) if cdate is not None: # Exposing the method used for reading the creation_date. print("Reading creation_date from input files metadata" - " `METADATA/creationDate`") + " `INDEX/timestamp`") else: # It's an older dataset. print("Reading creation_date from last modification data " "for the oldest input file.") diff --git a/tests/test_cal_tools.py b/tests/test_cal_tools.py index e2c494f3ed0bf328517d1dc1a2c06a665e6247c7..ad493e46c1bf1cd15336508c9dbc98f296ae80af 100644 --- a/tests/test_cal_tools.py +++ b/tests/test_cal_tools.py @@ -12,7 +12,6 @@ from cal_tools.agipdlib import AgipdCorrections, CellRange from cal_tools.plotting import show_processed_modules from cal_tools.tools import ( creation_date_file_metadata, - creation_date_metadata_client, creation_date_train_timestamp, get_dir_creation_date, get_from_db, @@ -112,14 +111,6 @@ def test_raise_dir_creation_date(): assert e.value.args[1] == Path(folder) / 'r0004' -@pytest.mark.requires_mdc -def test_creation_date_metadata_client(): - - date = creation_date_metadata_client(PROPOSAL, 9983) - assert isinstance(date, datetime) - assert str(date) == '2020-09-23 13:30:00+00:00' - - @pytest.mark.requires_gpfs def test_creation_date_file_metadata():