6
db = psycopg.connect('dbname=terp', serialize=0)
9
def graph_get(cr, graph, wkf_id, nested=True, workitem={}):
10
cr.execute('select * from wkf_activity where wkf_id=%d', (wkf_id,))
11
nodes = cr.dictfetchall()
16
activities[n['id']] = n
17
if n['subflow_id'] and nested:
18
cr.execute('select * from wkf where id=%d', (n['subflow_id'],))
19
wkfinfo = cr.dictfetchone()
20
graph2 = pydot.Cluster('subflow'+str(n['subflow_id']), fontsize=10, label = "Subflow: "+n['name']+'\\nOSV: '+wkfinfo['osv'])
21
(s1,s2) = graph_get(cr, graph2, n['subflow_id'], nested,workitem)
22
graph.add_subgraph(graph2)
27
if n['flow_start'] or n['flow_stop']:
28
args['style']='filled'
29
args['color']='lightgrey'
30
args['label']=n['name']
32
args['label']+='\\n'+n['action']
35
if n['id'] in workitem:
36
args['label']+='\\nx '+str(workitem[n['id']])
38
graph.add_node(pydot.Node(n['id'], **args))
39
actfrom[n['id']] = n['id']
40
actto[n['id']] = n['id']
41
cr.execute('select * from wkf_transition where act_from in ('+','.join(map(lambda x: str(x['id']),nodes))+')')
42
transitions = cr.dictfetchall()
45
args['label'] = str(t['condition'])
47
args['label'] += '\\n'+str(t['signal'])
48
args['style'] = 'bold'
50
if activities[t['act_from']]['split_mode']=='AND':
51
args['arrowtail']='box'
52
elif str(activities[t['act_from']]['split_mode'])=='OR ':
53
args['arrowtail']='inv'
55
if activities[t['act_to']]['join_mode']=='AND':
56
args['arrowhead']='crow'
58
graph.add_edge(pydot.Edge(actfrom[t['act_from']],actto[t['act_to']], fontsize=8, **args))
59
nodes = cr.dictfetchall()
60
cr.execute('select id from wkf_activity where flow_start=True limit 1')
61
start = cr.fetchone()[0]
62
cr.execute('select id from wkf_activity where flow_stop=True limit 1')
63
stop = cr.fetchone()[0]
66
def graph_instance_get(cr, graph, inst_id, nested=False):
68
cr.execute('select * from wkf_instance where id=%d', (inst_id,))
69
inst = cr.dictfetchone()
71
def workitem_get(instance):
72
cr.execute('select act_id,count(*) from wkf_workitem where inst_id=%d group by act_id', (instance,))
73
workitems = dict(cr.fetchall())
75
cr.execute('select subflow_id from wkf_workitem where inst_id=%d', (instance,))
76
for (subflow_id,) in cr.fetchall():
77
workitems.update(workitem_get(subflow_id))
80
graph_get(cr, graph, inst['wkf_id'], nested, workitem_get(inst_id))
83
cr.execute('select * from wkf where id=%d', (wkf_id,))
84
wkfinfo = cr.dictfetchone()
85
graph = pydot.Dot(fontsize = 16, label = "\\n\\nWorkflow: %s\\n OSV: %s"% (wkfinfo['name'],wkfinfo['osv']))
86
graph_instance_get(cr, graph, 1155, True)
87
graph.write_ps('/tmp/a.ps', prog='dot')