Skip to content

Commit d04353d

Browse files
authored
Add provenance cfg to output dir (#713)
* Add provenance cfg to output dir * Add provenance to www too
1 parent cdedf03 commit d04353d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

zppy/__main__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import importlib
44
import io
55
import os
6+
import shutil
7+
from datetime import datetime, timezone
68
from typing import Any, List, Tuple
79

810
from configobj import ConfigObj
@@ -42,18 +44,36 @@ def main():
4244
_validate_config(config)
4345
# Add templateDir to config
4446
config["default"]["templateDir"] = template_dir
47+
# Get timestamp for provenance
48+
# Provenance cfg will be placed in both `output` and `www`
49+
ts_utc = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S_%f")
4550
# Output script directory
4651
output = config["default"]["output"]
4752
username = os.environ.get("USER")
4853
output = output.replace("$USER", username)
4954
script_dir = os.path.join(output, "post/scripts")
5055
job_ids_file = os.path.join(script_dir, "jobids.txt")
56+
provenance = os.path.join(script_dir, f"provenance.{ts_utc}.cfg")
5157
try:
5258
os.makedirs(script_dir)
59+
shutil.copy(args.config, provenance)
5360
except OSError as exc:
5461
if exc.errno != errno.EEXIST:
5562
raise OSError("Cannot create script directory")
5663
pass
64+
# Web output directory
65+
www = config["default"]["www"]
66+
username = os.environ.get("USER")
67+
www = www.replace("$USER", username)
68+
www_case_dir = os.path.join(www, config["default"]["case"])
69+
provenance = os.path.join(www_case_dir, f"provenance.{ts_utc}.cfg")
70+
try:
71+
os.makedirs(www_case_dir)
72+
shutil.copy(args.config, provenance)
73+
except OSError as exc:
74+
if exc.errno != errno.EEXIST:
75+
raise OSError("Cannot create www case directory")
76+
pass
5777
machine_info = _get_machine_info(config)
5878
config = _determine_parameters(machine_info, config)
5979
if args.last_year:

0 commit comments

Comments
 (0)