-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
43 lines (34 loc) · 1.51 KB
/
utils.py
File metadata and controls
43 lines (34 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import json
import git
import os
import time
class dotdict(dict):
"""dot.notation access to dictionary attributes"""
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delattr__
def filter_dotdict_class_propoperty(dotdict_object, class_blueprint):
varnames = class_blueprint.__init__.__code__.co_varnames
new_dotdict = dotdict({k:v for (k, v) in dotdict_object.items() if k in varnames})
return new_dotdict
def load_parameter_from_json(path):
json_object = json.load(open(path, "r"))
dotdict_object = dotdict(json_object)
if dotdict_object.use_git:
repo = git.Repo(os.getcwd())
headcommit = repo.head.commit
current_branch = repo.active_branch.name
version = current_branch + "_commited_at_" + time.strftime("%a_%d_%b_%Y_%H_%M", time.gmtime(headcommit.committed_date)) + "_run_at_" + str(int(time.time() - headcommit.committed_date))
dotdict_object.result_folder_path = os.path.join(dotdict_object.result_folder_path, version)
return dotdict_object
def load_rest_api_parameter_from_json(path):
json_object = json.load(open(path, "r"))
dotdict_object = dotdict(json_object)
return dotdict_object
class FactoryClass:
def __init__(self, class_contructor, param_dict = {}):
self.class_contructor = class_contructor
self.param_dict = param_dict
def create_class(self, new_param_dict={}):
new_object = self.class_contructor(**self.param_dict, **new_param_dict)
return new_object