From cb4fd7f51eb66b1c727ab3556596f42a706bd43e Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Tue, 5 Sep 2023 22:50:30 +0200
Subject: [PATCH] enable renaming all reports folders for all proposals

---
 .../useful_scripts/rename_report_folders.py   | 30 +++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/webservice/useful_scripts/rename_report_folders.py b/webservice/useful_scripts/rename_report_folders.py
index 3f75a74f4..f77b0d78d 100644
--- a/webservice/useful_scripts/rename_report_folders.py
+++ b/webservice/useful_scripts/rename_report_folders.py
@@ -1,38 +1,38 @@
 import argparse
 import os
+from pathlib import Path
 
 # Update runs into 4 digits integers e.g. r2 to r0002.
 
 
-def rename_folders_in_directory(directory_path, really):
-    for folder_name in os.listdir(directory_path):
-        if folder_name.startswith('r') and folder_name[1:].isdigit():
-            new_folder_name = 'r' + folder_name[1:].zfill(4)
-            old_path = os.path.join(directory_path, folder_name)
-            new_path = os.path.join(directory_path, new_folder_name)
+def rename_report_folders_for_instrument(directory_path, really):
+    for folder_name in directory_path.glob("*/*/usr/Reports/*"):
+        if folder_name.name.startswith('r') and folder_name.name[1:].isdigit():
+            new_folder_name = 'r' + folder_name.name[1:].zfill(4)
+            new_path = folder_name.parent.joinpath(new_folder_name)
             if really:
-                os.rename(old_path, new_path)
+                folder_name.rename(new_path)
                 print(f'Renamed {folder_name} to {new_folder_name}')
             else:
                 print(f'Will rename {folder_name} to {new_folder_name}')
 
 
 parser = argparse.ArgumentParser(
-    description='Rename run folders.')
+    description='Instrument to change the report folders for.')
 parser.add_argument(
-    '--runs-directory',
+    '--instrument',
     type=str,
-    help='Directory path to the runs that needs to be renamed',
+    help='instrument name',
     required=True,
 )
 parser.add_argument(
     '--really', action='store_true',
     help="Actually make changes (otherwise dry-run)")
 args = parser.parse_args()
+instrument = args.instrument
 
-if args.runs_directory:
-    runs_directory = args.runs_directory
-else:
-    assert args.runs_directory, "Specify the runs directory"
 
-rename_folders_in_directory(runs_directory, args.really)
+path = "/gpfs/exfel/exp/{instrument}"
+
+rename_report_folders_for_instrument(Path(path.format(instrument=instrument)), args.really)
+
-- 
GitLab