From 294a4e1273ebee62377cc9b6531b4590382705b2 Mon Sep 17 00:00:00 2001 From: Jose Gracia Date: Fri, 17 Nov 2023 16:25:51 +0100 Subject: [PATCH] Add argument parser --- monitoring/db/scripts/get_detailed_power.py | 24 ++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/monitoring/db/scripts/get_detailed_power.py b/monitoring/db/scripts/get_detailed_power.py index 7a19e7f..c7a05be 100644 --- a/monitoring/db/scripts/get_detailed_power.py +++ b/monitoring/db/scripts/get_detailed_power.py @@ -2,6 +2,26 @@ import numpy as np from collections import OrderedDict import os.path + +def parse_arguments(): + parser = argparse.ArgumentParser( + description='Produce detailed power usage data for a list of jobids.') + parser.add_argument('-v', '--verbose', action='store_true', + help='Show database querries, etc.') + parser.add_argument('jobid', type=parse_jobid, + # nargs='+', + help='Job ID such as "2260215" or "226015.hawk-pbs5"') + + return parser.parse_args() + +def parse_jobid(s): + import re + hawkpbs = r'.hawk-pbs5' + jobid = re.sub(hawkpbs, '', s) + if not jobid.isdigit(): + raise argparse.ArgumentTypeError(f'invalid job ID "{s}"') + return jobid + def init_db(): import sqlalchemy as db _verbose = False #True @@ -149,8 +169,10 @@ class Power: if __name__ == "__main__": + args = parse_arguments() + conn = init_db() - jobid = "2260215" + jobid = args.jobid interval = 5 query = init_query(jobid, interval)