Skip to content

Commit 751be27

Browse files
committed
Add option to print extra details about the Versions during deletion
1 parent 3c73db8 commit 751be27

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

Framework/script/RepoCleaner/qcrepocleaner/Ccdb.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313

1414
class ObjectVersion:
1515
'''
16-
A version of an object in the CCDB.
17-
18-
In the CCDB an object can have many versions with different validity intervals.
19-
This class represents a single version.
16+
A version of an object in the CCDB.
17+
18+
In the CCDB an object can have many versions with different validity intervals.
19+
This class represents a single version.
2020
'''
2121

22+
print_details = False
23+
2224
def __init__(self, path: str, validFrom, validTo, createdAt, uuid=None, metadata=None):
2325
'''
2426
Construct an ObjectVersion.
@@ -27,6 +29,8 @@ def __init__(self, path: str, validFrom, validTo, createdAt, uuid=None, metadata
2729
:param validFrom: validity range smaller limit (in ms)
2830
:param validTo: validity range bigger limit (in ms)
2931
:param createdAt: creation timestamp of the object
32+
:param uuid: unique id of the object
33+
:param metadata: metadata of the object
3034
'''
3135
self.path = path
3236
self.uuid = uuid
@@ -42,10 +46,14 @@ def __init__(self, path: str, validFrom, validTo, createdAt, uuid=None, metadata
4246
def __repr__(self):
4347
if "Run" in self.metadata or "RunNumber" in self.metadata:
4448
run_number = self.metadata["Run"] if "Run" in self.metadata else self.metadata["RunNumber"]
45-
return f"Version of object {self.path} created at {self.createdAtDt.strftime('%Y-%m-%d %H:%M:%S')}, valid from {self.validFromAsDt.strftime('%Y-%m-%d %H:%M:%S')}, run {run_number} (uuid {self.uuid})"
4649
else:
47-
return f"Version of object {self.path} created at {self.createdAtDt.strftime('%Y-%m-%d %H:%M:%S')}, valid from {self.validFromAsDt.strftime('%Y-%m-%d %H:%M:%S')} (uuid {self.uuid}, " \
48-
f"ts {self.validFrom})"
50+
run_number = "None"
51+
52+
representation = f"Version of object {self.path} created at {self.createdAtDt.strftime('%Y-%m-%d %H:%M:%S')}, valid from" \
53+
f"{self.validFromAsDt.strftime('%Y-%m-%d %H:%M:%S')}, uuid {self.uuid}, run {run_number}"
54+
if ObjectVersion.print_details:
55+
representation += f", metadata: {self.metadata}"
56+
return representation
4957

5058

5159
class Ccdb:
@@ -58,9 +66,10 @@ class Ccdb:
5866
counter_preserved: int = 0
5967
set_adjustable_eov: bool = False # if True, set the metadata adjustableEOV before change validity
6068

61-
def __init__(self, url):
69+
def __init__(self, url, print_details=False):
6270
logger.info(f"Instantiate CCDB at {url}")
6371
self.url = url
72+
ObjectVersion.print_details = print_details
6473

6574
def getObjectsList(self, added_since: int = 0, path: str = "", no_wildcard: bool = False) -> List[str]:
6675
'''
@@ -150,7 +159,7 @@ def getVersionsList(self, object_path: str, from_ts: str = "", to_ts: str = "",
150159
@dryable.Dryable()
151160
def deleteVersion(self, version: ObjectVersion):
152161
'''
153-
Delete the specified version of an object.
162+
Delete the specified version of an object.
154163
:param version: The version of the object to delete, as an instance of ObjectVersion.
155164
'''
156165
url_delete = self.url + '/' + version.path + '/' + str(version.validFrom) + '/' + version.uuid
@@ -203,7 +212,7 @@ def updateValidity(self, version: ObjectVersion, valid_from: int, valid_to: int,
203212
r = requests.put(full_path, headers=headers)
204213
r.raise_for_status()
205214
self.counter_validity_updated += 1
206-
except requests.exceptions.RequestException as e:
215+
except requests.exceptions.RequestException as e:
207216
logging.error(f"Exception in updateValidity: {traceback.format_exc()}")
208217

209218
@dryable.Dryable()

Framework/script/RepoCleaner/qcrepocleaner/o2-qc-repo-cleaner

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def parseArgs():
103103
'only-path points to an object rather than a folder or if subdirectories must be ignored.')
104104
parser.add_argument('--ignore-last-execution', dest='ignore_last_execution', action='store_true', default=False,
105105
help='Do not check when was the last execution, run from timestamp 0.')
106+
parser.add_argument('--print-versions-details', dest='print_versions_details', action='store_true', default=False,
107+
help='Print extra details about the versions if enabled..')
106108
args = parser.parse_args()
107109
dryable.set(args.dry_run)
108110
logging.info(args)
@@ -373,7 +375,7 @@ def process_object(object_path, rules, ccdb, args):
373375
def run(args, ccdb_url, rules):
374376

375377
# Get list of objects from CCDB
376-
ccdb = Ccdb(ccdb_url)
378+
ccdb = Ccdb(ccdb_url, args.print_versions_details)
377379
ccdb.logger = logging.getLogger
378380
ccdb.set_adjustable_eov = args.set_adjustableEOV
379381
logging.info(f"ccdb.set_adjustable_eov: {ccdb.set_adjustable_eov}")

Framework/script/RepoCleaner/qcrepocleaner/o2-qc-repo-delete-objects-in-runs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ def parseArgs():
3030
parser.add_argument('--yes', action='store_true', help='Answers yes to all. You should really not use that.')
3131
parser.add_argument('--metadata', dest='metadata', action='store', default="",
3232
help='Delete only versions matching these metadata. Format: "[/key=value]*"')
33+
parser.add_argument('--print-versions-details', dest='print_versions_details', action='store_true', default=False,
34+
help='Print extra details about the versions if enabled..')
3335
args = parser.parse_args()
3436
dryable.set(args.dry_run)
3537
logging.info(args)
3638
return args
3739

3840

3941
def run(args):
40-
ccdb = Ccdb(args.url)
42+
ccdb = Ccdb(args.url, args.print_versions_details)
4143

4244
total_deleted = 0
4345
total_planned = 0

0 commit comments

Comments
 (0)