Skip to content

Commit aecb017

Browse files
committed
getCCDBTimeMachineTimestamp.py: fix printouts
1 parent 6e1170e commit aecb017

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

‎GRID/utils/getCCDBTimeMachineTimestamp.py‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,15 @@ def ccdb_cross_check(run, path, not_after, timeout=15):
116116
same validity window. Never raises; returns None on any failure."""
117117
timestamp = get_run_start_tf(run)
118118
url = f"{CCDB_HOST}/browse/{path}/{timestamp}"
119+
result = {"timestamp": timestamp}
120+
119121
objects = get_ccdb_objects(url)
120122
if not objects:
121-
return {"error": "no CCDB object covers this instant"}
123+
return {**result, "error": "no CCDB object covers this instant"}
122124

123125
as_of = [o for o in objects if o.get("Created", 0) <= not_after]
124126
newest = max(objects, key=lambda o: o.get("Created", 0))
125-
result = {"timestamp": timestamp, "newest": newest, "as_of": None, "outdated": False}
127+
result.update({"newest": newest, "as_of": None, "outdated": False})
126128
if as_of:
127129
result["as_of"] = max(as_of, key=lambda o: o.get("Created", 0))
128130
result["outdated"] = newest["Created"] > result["as_of"]["Created"]
@@ -184,16 +186,17 @@ def get_NotAfter(year, period, run, passname, samples=9, ccdb_check_path="TPC/Ca
184186

185187
if ccdb_check:
186188
check = ccdb_cross_check(run, ccdb_check_path, not_after)
189+
check_timestamp = f"/{check['timestamp']}" if check else ""
187190
if check is None or "error" in check:
188191
reason = check["error"] if check else "unknown error"
189-
print(f"[getCCDBTimeMachineTimestamp] CCDB cross-check on {ccdb_check_path}/{check["timestamp"]} skipped: {reason}",
192+
print(f"[getCCDBTimeMachineTimestamp] CCDB cross-check on {ccdb_check_path}{check_timestamp} skipped: {reason}",
190193
file=sys.stderr)
191194
elif check["as_of"] is None:
192-
print(f"[getCCDBTimeMachineTimestamp] CCDB cross-check on {ccdb_check_path}/{check["timestamp"]}: no object "
195+
print(f"[getCCDBTimeMachineTimestamp] CCDB cross-check on {ccdb_check_path}{check_timestamp}: no object "
193196
f"existed yet at the recommended timestamp (earliest is {describe_object(check['newest'])})",
194197
file=sys.stderr)
195198
else:
196-
print(f"[getCCDBTimeMachineTimestamp] CCDB cross-check on {ccdb_check_path}/{check["timestamp"]}: as-of object is "
199+
print(f"[getCCDBTimeMachineTimestamp] CCDB cross-check on {ccdb_check_path}{check_timestamp}: as-of object is "
197200
f"{describe_object(check['as_of'])}", file=sys.stderr)
198201
if check["outdated"]:
199202
print(f"[getCCDBTimeMachineTimestamp] note: CCDB's current object for this window is newer "
@@ -218,7 +221,7 @@ def query_CCDBTimeMachineTS(base_url, user, period, passname):
218221
user_path = 'Users/' + user[0] + '/' + user
219222
url = f"{base_url}/browse/{user_path}/CCDBTimeMachineTS/{query}"
220223

221-
print(f"[getCCDBTimeMachineTimestamp] Checking if CCDBTimeMachineTS already exists: {url}")
224+
print(f"[getCCDBTimeMachineTimestamp] Checking if CCDBTimeMachineTS already exists: {url}", file=sys.stderr)
222225

223226
response = requests.get(url, cert=(cert_path, key_path), verify=False)
224227
if response.status_code != 404:
@@ -230,7 +233,8 @@ def filter_known_fields(cls, data: dict) -> dict:
230233

231234
clean_meta = filter_known_fields(CCDBTimeMachineTS, meta[0])
232235
print(f"[getCCDBTimeMachineTimestamp] Found object for {clean_meta['Period']}, Pass: {clean_meta['Pass']}, "
233-
f"NotAfter: {clean_meta['NotAfter']} ({human(clean_meta['NotAfter'])}), uploaded by LPMProductionTag {clean_meta['LPMProductionTag']}")
236+
f"NotAfter: {clean_meta['NotAfter']} ({human(clean_meta['NotAfter'])}), uploaded by LPMProductionTag {clean_meta['LPMProductionTag']}",
237+
file=sys.stderr)
234238
return clean_meta['NotAfter']
235239

236240
return None
@@ -258,7 +262,7 @@ def upload_CCDBTimeMachineTS(base_url, user, keys):
258262
stop = start + 1
259263
url = f"{base_url}/{user_path}/CCDBTimeMachineTS/{start}/{stop}/{query}"
260264

261-
print(f"[getCCDBTimeMachineTimestamp] Uploading CCDBTimeMachineTS: {url}")
265+
print(f"[getCCDBTimeMachineTimestamp] Uploading CCDBTimeMachineTS: {url}", file=sys.stderr)
262266

263267
# Prepare request
264268
with open(empty_file, 'rb') as f:
@@ -289,11 +293,11 @@ def get_CCDBTimeMachineTS(production_tag, year, period, run, passname,
289293
not_after = None
290294

291295
if not_after is not None and force_overwrite == True:
292-
print("[getCCDBTimeMachineTimestamp] Existing object will be overwritten")
296+
print("[getCCDBTimeMachineTimestamp] Existing object will be overwritten", file=sys.stderr)
293297

294298
if not_after == None or force_overwrite == True:
295299
print("[getCCDBTimeMachineTimestamp] Estimating CCDBTimeMachineTS for "
296-
f"LPMProductionTag: {production_tag}, Period: {period}, Pass: {passname}")
300+
f"LPMProductionTag: {production_tag}, Period: {period}, Pass: {passname}", file=sys.stderr)
297301
not_after = get_NotAfter(year, period, run, passname, samples, ccdb_check_path, ccdb_check)
298302
time_machine_ts = CCDBTimeMachineTS(production_tag, period, passname, not_after)
299303
if publish_to_ccdb:
@@ -338,9 +342,10 @@ def main():
338342
if missing:
339343
parser.error("missing required value(s): " + ", ".join(missing))
340344

341-
get_CCDBTimeMachineTS(args.production_tag, args.year, args.period, args.run, args.passname,
345+
not_after = get_CCDBTimeMachineTS(args.production_tag, args.year, args.period, args.run, args.passname,
342346
args.samples, args.ccdb_check_path, not args.no_ccdb_check, args.ccdb_url, args.username,
343347
args.force_overwrite, args.publish_to_ccdb, args.skip_ccdb_query)
348+
print(not_after)
344349

345350

346351
if __name__ == "__main__":

0 commit comments

Comments
 (0)