diff --git a/scripts/cleanRuns.py b/scripts/cleanRuns.py
index bf138d4..4cc9479 100755
--- a/scripts/cleanRuns.py
+++ b/scripts/cleanRuns.py
@@ -1,159 +1,164 @@
#!/usr/bin/env python3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import BlackDynamite as BD
import os
import sys
import socket
import re
import shutil
import yaml
import tqdm
################################################################
def validate(question):
if params["truerun"] is True:
validated = BD.bdparser.validate_question(question, params)
else:
print("{0}? Forced N".format(question))
validated = False
return validated
parser = BD.BDParser()
parser.register_params(
"clearRun",
params={
- "runid": int,
+ "run_id": int,
"clean_orphans": str,
"machine_name": str,
"constraints": [str],
"delete": bool
},
defaults={
"machine_name": socket.gethostname(),
"delete": False,
},
help={
"machine_name": "Machine name for desired runs",
"delete": "Entirely remove runs from database",
- "runid": "ID of a specific run"
+ "run_id": "ID of a specific run"
}
)
params = parser.parseBDParameters()
fname = 'bd.yaml'
with open(fname) as f:
config = yaml.load(f, Loader=yaml.SafeLoader)
if 'study' in config:
params['study'] = config['study']
+if "run_id" in params:
+ if "constraints" not in params:
+ params["constraints"] = []
+ params["constraints"].append("runs.id = " + str(params["run_id"]))
+
if "machine_name" in params:
if "constraints" in params:
params["constraints"].append(
"machine_name = " + params["machine_name"])
else:
params["constraints"] = ["machine_name = " + params["machine_name"]]
base = BD.Base(**params)
runSelector = BD.RunSelector(base)
if "clean_orphans" in params:
run_list = runSelector.selectRuns([])
run_ids = [r.id for r, j in run_list]
resdir = params["clean_orphans"] + "/BD-" + params["study"] + "-runs"
print("clean orphans from " + resdir)
if not os.path.exists(resdir):
print("Directory '" + resdir + "' do not exists")
sys.exit(-1)
to_delete = {}
for filename in os.listdir(resdir):
fullname = os.path.join(resdir, filename)
# print(fullname)
if (os.path.isdir(fullname)):
match = re.match("run-([0-9]+)", filename)
if (match):
# print(filename)
id = int(match.group(1))
if (id not in run_ids):
to_delete[id] = fullname
if (len(to_delete.keys()) == 0):
print("No orphans found")
sys.exit(0)
validated = validate("Delete output from runs " + str(to_delete.keys()))
if (validated):
for id, fullname in to_delete.items():
print("Delete output from run " + str(id))
shutil.rmtree(fullname)
sys.exit(0)
runSelector = BD.RunSelector(base)
run_list = runSelector.selectRuns(params, quiet=True)
if (len(run_list) == 0):
print("No runs selected")
sys.exit()
delete_flag = params["delete"]
if delete_flag:
validated = validate(f"Delete {len(run_list)} runs")
else:
validated = validate(f"Reset {len(run_list)} runs")
for i, (r, j) in enumerate(tqdm.tqdm(run_list)):
if "run_path" in r:
run_path = r["run_path"]
else:
run_path = None
if run_path:
if os.path.exists(run_path):
if (validated):
print("Deleting directory: " + run_path)
shutil.rmtree(run_path)
else:
print("Simulate deletion of directory: " + run_path)
else:
print("output directory: '" + run_path +
"' not found: are we on the right machine ?")
if delete_flag:
if validated:
# print("Deleting run " + str(r.id) + " from base")
r.delete()
else:
print("Simulate deletion of run " + str(r.id) + " from base")
else:
if validated:
# print("Deleting data associated with run " + str(r.id))
r.deleteData()
r["STATE"] = "CREATED"
r["start_time"] = None
r.update()
else:
print("Simulate deletion of data associated with run " + str(r.id))
if i % 1000 == 0:
# if truerun, commit the changes to the base
if params["truerun"] is True:
base.commit()
if validated:
base.pack()
diff --git a/scripts/pushQuantity.py b/scripts/pushQuantity.py
index 969e3b2..fa9b3db 100755
--- a/scripts/pushQuantity.py
+++ b/scripts/pushQuantity.py
@@ -1,82 +1,82 @@
#!/usr/bin/env python3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import BlackDynamite as BD
def main(argv=None):
parser = BD.BDParser()
parser.register_params(
group="pushQuantity",
- params={"runid": int,
+ params={"run_id": int,
"quantity_id": str,
"value": str,
"values": [str],
"step": int,
"is_float": bool},
defaults={"step": 0},
- help={"runid": "The id of the run to update",
+ help={"run_id": "The id of the run to update",
"quantity_id": "ID of the Quantity to push",
"value": "Value tu push for the quantity",
"values": "Vectorial value tu push for the quantity",
"step": "Step at which the data is generated",
"is_float": "0 if the quantity is a float 1 other why"}
)
params = parser.parseBDParameters()
- if("runid" not in params):
+ if("run_id" not in params):
myrun, myjob = BD.getRunFromScript()
- params['runid'] = myrun.id
+ params['run_id'] = myrun.id
if("quantity_id" not in params):
raise Exception("The quantity id should be set")
if("value" not in params and "values" not in params):
raise Exception("The value should be set")
is_vector = False
if("values" in params):
is_vector = True
if("value" in params):
raise Exception(
"You cannot define values and value at the same time")
base = BD.Base(**params)
- if ("runid" in params):
- if "run_constraints" not in params:
- params["run_constraints"] = []
- params["run_constraints"].append("id = " + str(params["runid"]))
+ if ("run_id" in params):
+ if "constraints" not in params:
+ params["constraints"] = []
+ params["constraints"].append("runs.id = " + str(params["run_id"]))
runSelector = BD.RunSelector(base)
run_list = runSelector.selectRuns(params)
if (not len(run_list) == 1):
raise Exception("No or too many runs selected")
r, j = run_list[0]
if params["truerun"] is True:
if is_vector is False:
r.pushScalarQuantity(
params["value"], params["step"], params["quantity_id"],
params["is_float"] is False)
else:
r.pushVectorQuantity(
params["values"], params["step"], params["quantity_id"],
params["is_float"] is False)
base.commit()
if __name__ == '__main__':
main()