Skip to content
Snippets Groups Projects

Sanitize cal_tools.tools.get_creation_date

Merged Cyril Danilevski requested to merge clean/get_dir_creation_date into master
1 unresolved thread
Files
2
@@ -233,15 +233,16 @@ def get_run_info(proposal, run):
@@ -233,15 +233,16 @@ def get_run_info(proposal, run):
def get_dir_creation_date(directory: str, run: int,
def get_dir_creation_date(directory: str, run: int,
verbosity: Optional[int] = 0) -> datetime.datetime:
verbosity: Optional[int] = 0) -> datetime.datetime:
"""
"""
Return run starting time from the MDC.
Return run start time from MyDC.
If not succeeded, return modification time of oldest file.h5
If not available from MyMDC, retrieve the data from the dataset's metadata
in [directory]/[run]04.
in [directory]/[run] or, if the dataset is older than 2020, from the
 
directory's creation time.
If the files are not available, this function will raise a ValueError.
If the data is not available from either source, this function will raise a
 
ValueError.
:param directory: path to directory which contains runs
:param directory: path to directory which contains runs
:param run: run number
:param run: run number
:param tsdir: to get modification time of [directory]/[run]04.
:param verbosity: Level of verbosity (0 - silent)
:param verbosity: Level of verbosity (0 - silent)
:return: (datetime) modification time
:return: (datetime) modification time
"""
"""
directory = Path(directory)
directory = Path(directory)
proposal = int(directory.parent.name[1:])
proposal = int(directory.parent.name[1:])
try:
try:
@@ -272,5+273,5 @@
@@ -272,5+273,5 @@
return min(dates)
return min(dates)
except (IOError, ValueError):
except (IOError, ValueError):
ntries -= 1
ntries -= 1
 
except KeyError: # The files are here, but it's an older dataset
 
return datetime.datetime.fromtimestamp(directory.stat().st_ctime)
msg = 'Could not get the creation time from the directory'
msg = 'Could not get the creation time from the directory'
raise ValueError(msg, directory)
raise ValueError(msg, directory)
Loading