diff --git a/webservice/config/webservice.yaml b/webservice/config/webservice.yaml index 2ed4d41f9871a3f5ec44edce2687c3d1a69eaa03..ce6228b6eb8acafac98cfab1d22ca89b719f8990 100644 --- a/webservice/config/webservice.yaml +++ b/webservice/config/webservice.yaml @@ -50,13 +50,14 @@ correct: --slurm-partition {partition} --request-time {request_time} --slurm-name {action}_{instrument}_{detector}_{cycle}_p{proposal}_{runs} - --report-to /gpfs/exfel/exp/{instrument}/{cycle}/p{proposal}/usr/Reports/{runs}/{det_instance}_{action}_{proposal}_{runs}_{time_stamp} + --report-to {reports_folder}/{det_instance}_{action}_{proposal}_{runs}_{time_stamp} --cal-db-timeout 300000 --cal-db-interface tcp://max-exfl-cal001:8015#8044 dark: in-folder: /gpfs/exfel/exp/{instrument}/{cycle}/p{proposal}/raw out-folder: /gpfs/exfel/u/usr/{instrument}/{cycle}/p{proposal}/dark/runs_{runs} + reports-folder: /gpfs/exfel/d/cal/caldb_store/xfel/reports/{instrument}/{det_instance}/{action} commissioning-penalty: 1250 job-penalty: 2 cmd: >- @@ -66,6 +67,6 @@ dark: --slurm-partition {partition} --request-time {request_time} --slurm-name {action}_{instrument}_{detector}_{cycle}_p{proposal}_{runs} - --report-to /gpfs/exfel/d/cal/caldb_store/xfel/reports/{instrument}/{det_instance}/{action}/{action}_{proposal}_{runs}_{time_stamp} + --report-to {reports_folder}/{action}_{proposal}_{runs}_{time_stamp} --cal-db-interface tcp://max-exfl-cal001:8015#8044 --db-output diff --git a/webservice/useful_scripts/rename_report_folders.py b/webservice/useful_scripts/rename_report_folders.py new file mode 100644 index 0000000000000000000000000000000000000000..ba7240cdf43b1858beb6ffbaaa27573a867bd81e --- /dev/null +++ b/webservice/useful_scripts/rename_report_folders.py @@ -0,0 +1,76 @@ +import argparse +import logging +from pathlib import Path + +# Update runs into 4 digits integers e.g. r2 to r0002. + +# Configure logging +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s - %(levelname)s - %(message)s", + handlers=[ + logging.StreamHandler(), + logging.FileHandler('rename_reports.log')] +) + + +def rename_report_folders_for_instrument(directory_path, cycle_year, really): + logging.info(f"Starting the script for {directory_path} and {cycle_year}.") + for folder_name in directory_path.glob(f"{cycle_year}/**/*/usr/Reports/*"): + if ( + folder_name.name.startswith("r") and + folder_name.name[1:].isdigit() and + len(folder_name.name[1:]) < 4 + ): + new_folder_name = "r" + folder_name.name[1:].zfill(4) + new_path = folder_name.parent.joinpath(new_folder_name) + if really: + folder_name.rename(new_path) + logging.info(f"Renamed {folder_name} to {new_folder_name}") + else: + if new_path.exists(): + # For Testing + logging.warning(f"{new_folder_name} exists!.") + else: + logging.info( + f"Will rename {folder_name} to {new_folder_name}. " + "Use --really to go through with renaming.") + logging.info("Renaming done .") + logging.info(".") + logging.info(".") + logging.info(".") + +def main(): + parser = argparse.ArgumentParser( + description="Instrument to change the report folders for.") + parser.add_argument( + "--path", + type=str, + help="Main path for Instruments", + default="/gpfs/exfel/exp/{instrument}" + ) + parser.add_argument( + "--instrument", + type=str, + help="instrument name", + required=True, + ) + parser.add_argument( + "--cycle-year", + type=str, + help="Cycle year number", + required=True, + ) + parser.add_argument( + "--really", action="store_true", + help="Actually make changes (otherwise dry-run)") + args = parser.parse_args() + path = args.path + instrument = args.instrument + cycle_year = args.cycle_year + + rename_report_folders_for_instrument( + Path(path.format(instrument=instrument)), cycle_year, args.really) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/webservice/webservice.py b/webservice/webservice.py index 0272e3a135d8347502f456b47d98621e421a53c4..3379516d8d151947fb59424cb169bfd49531365d 100644 --- a/webservice/webservice.py +++ b/webservice/webservice.py @@ -1110,7 +1110,10 @@ class ActionsServer: req_id = cur.lastrowid reports_dir = Path(self.config['correct']['reports-folder'].format( - instrument=instrument, cycle=cycle, proposal=proposal, runs=f"r{runnr}" + instrument=instrument, + cycle=cycle, + proposal=proposal, + runs=f"r{runnr:04d}" )) mddirs_by_krb_id = {} @@ -1457,13 +1460,23 @@ class ActionsServer: for karabo_id, dconfig in detectors.items(): detector = dconfig['detector-type'] del dconfig['detector-type'] + runs = "_".join([f"r{int(r):04d}" for r in run_nrs]) + reports_folder = self.config[action]['reports-folder'].format( + action=action, + instrument=instrument, + cycle=cycle, + proposal=proposal, + runs=runs, + det_instance=karabo_id, + ) cmd = self.config[action]['cmd'].format( detector=detector, sched_prio=nice, partition=partition, action=action, instrument=instrument, cycle=cycle, proposal=proposal, - runs="_".join([f"r{r}" for r in run_nrs]), + runs=runs, + reports_folder=reports_folder, time_stamp=request_time.strftime('%y%m%d_%H%M%S_%f'), det_instance=karabo_id, request_time=request_time.isoformat(),