Skip to content
Snippets Groups Projects
Commit 7ce86099 authored by ferrari's avatar ferrari
Browse files

initial commit

parent fae7fd75
No related branches found
No related tags found
No related merge requests found
...@@ -2,21 +2,33 @@ import git ...@@ -2,21 +2,33 @@ import git
import json import json
import os import os
import datetime import datetime
import argparse
import warnings
import __main__ import __main__
def log_info(args, path=None): def log_info(args, path=None):
time = datetime.time() time = datetime.datetime.now().isoformat()
if isinstance(args, argparse.Namespace):
args = args.__dict__
elif isinstance(args, argparse.ArgumentParser):
args = args.parse_args().__dict__
if path: if path:
if '/' in path: if '/' in path:
os.makedirs(path.rsplit('/', 1)[0], exist_ok=True) os.makedirs(path.rsplit('/', 1)[0], exist_ok=True)
else: else:
if not os.path.isdir('run_log'): if not os.path.isdir('run_log'):
os.makedirs('run_log') os.makedirs('run_log')
path = 'run_log/' + time.isoformat() + '.json' path = 'run_log/' + time + '.json'
with open(path, 'w') as logfile: with open(path, 'w') as logfile:
repo = git.Repo(os.path.dirname(os.path.abspath(__main__.__file__)), search_parent_directories=True) repo = git.Repo(os.path.dirname(os.path.abspath(__main__.__file__)), search_parent_directories=True)
sha = repo.head.object.hexsha sha = repo.head.object.hexsha
changes = repo.index.diff(None)
if len(changes):
warnings.simplefilter('always', DeprecationWarning)
warnings.warn(f'{[c.a_path for c in changes]} have differences with current commit',
DeprecationWarning, stacklevel=2)
warnings.simplefilter('default', DeprecationWarning)
json.dump({'script': __main__.__file__, json.dump({'script': __main__.__file__,
'commit': sha, 'commit': sha,
'parameters': args, 'parameters': args,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment