forked from HumanArk/hafarm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PrintRender.py
42 lines (34 loc) · 1.36 KB
/
PrintRender.py
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
import os
import json
import pprint
from time import time
from hafarm import const
from const import ConstantItemJSONEncoder
class PrintParmRender(object):
def __init__(self, hagraphitems_lst, **kwargs):
super(PrintParmRender, self).__init__()
self.hagraphitems_lst = hagraphitems_lst
def render(self):
print
print
for k, n in self.hagraphitems_lst.iteritems():
pprint.pprint(n.parms)
class JsonParmRender(object):
def __init__(self, hagraphitems_lst, **kwargs):
super(JsonParmRender, self).__init__()
self.hagraphitems_lst = hagraphitems_lst
def render(self):
files = {}
for k, item in self.hagraphitems_lst.iteritems():
item.parms['submission_time'] = time()
_db = {}
_db['inputs'] = [ self.hagraphitems_lst[x].parms['job_name'] for x in item.dependencies ]
_db['class_name'] = item.__class__.__name__
_db['backend_name'] = 'JsonParmRender'
_db['parms'] = item.parms
parms_file = os.path.expandvars(item.parms['script_path'])
parms_file = os.path.join(parms_file, item.parms['job_name']) + '.json'
with open(parms_file, 'w') as file:
result = json.dump(_db, file, indent=2, cls=ConstantItemJSONEncoder)
files[k] = parms_file
return files