global RUN_ID
// Open the database
db = open_or_create_db()
// Create the unique ID for this run
guid = str(uuid.uuid4())
// Get general metadata, environment info, etc
run = {"unique_id": guid,
"author": getpass.getuser(),
"description": "",
"inputs": [],
"outputs": [],
"script": scriptpath,
"command": sys.executable,
"environment": [platform.platform(), "python " + sys.version.split("\n")[0]],
"date": datetime.datetime.utcnow(),
"command_args": " ".join(cmd_args)}
if not option_set("ignored metadata", "git"):
try:
repo = Repo(scriptpath, search_parent_directories=True)
run["gitrepo"] = repo.working_dir
run["gitcommit"] = repo.head.commit.hexsha
run["gitorigin"] = get_origin(repo)
if not option_set("ignored metadata", "diff"):
whole_diff = ""
diffs = repo.index.diff(None, create_patch=True)
for diff in diffs:
whole_diff += "\n\n\n" + diff.diff.decode("utf-8")
run["diff"] = whole_diff
except (InvalidGitRepositoryError, ValueError):
// We can"t store git info for some reason, so just skip it
pass
// Put basics into DB
RUN_ID = db.insert(run)
// Print message
if not option_set("general", "quiet"):
print("recipy run inserted, with ID %s" % (guid))
db.close()
// Register exception hook so exceptions can be logged
sys.excepthook = log_exception