-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcsys2graphxlsx.py
More file actions
166 lines (125 loc) · 4.96 KB
/
csys2graphxlsx.py
File metadata and controls
166 lines (125 loc) · 4.96 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from config_csys import *
from redminelib import Redmine
import argparse # This library allows us to easily parse the command line arguments
# Importing test configuration file
import config
import os
from pyexcel_xlsx import save_data
from collections import OrderedDict
from pathlib import Path
######### WE WILL PARSE THE COMMAND LINE ARGUMENTS FOR THE WRAPPER GEN #############
parser = argparse.ArgumentParser(description='Launches a cosmoSys graph generation XLSX from an cosmosys project so it can be imported to yEd to create a graph')
## The second argument is the api ODS file
parser.add_argument('prj_ident', help="the identifier of the cosmoSys project")
# Obtaining the arguments from the command line
args=parser.parse_args()
# Printing the obtained arguments:
print("/* The cosmoSys project identifier is:",args.prj_ident+" */")
prjName = args.prj_ident
print("Project name:",prjName)
import requests as req
prcfdict = {}
cfdict = {}
rmissues = {}
from redminelib import Redmine
if csys_ignorecert:
redmine = Redmine(csys_server_url,key=csys_key_txt, requests={'verify': False})
else:
redmine = Redmine(csys_server_url,key=csys_key_txt)
projects = redmine.project.all()
nodestable = []
edgestable = []
rm_issues_dict = {}
chapters_list = []
#################### PARAMETERS TO TUNE ############################
include_chapters = True
onlyblocks = True
def print_subprojects(p):
global projects
for cp in projects:
if hasattr(cp,'parent'):
if cp.parent.id == p.id:
print(cp.name,"->",p.name)
print_subprojects(cp)
def scan_project(p):
global nodestable, edgestable, rm_issues_dict,projects,include_chapters,chapters_list
for i in p.issues:
i_ident = i.custom_fields.get(cfdict['csID'].id).value
if hasattr(i,'parent') and (i.parent is not None):
parent = redmine.issue.get(i.parent.id)
parent_ident = parent.custom_fields.get(cfdict['csID'].id).value
chapters_list += parent_ident
else:
parent_ident = ""
rm_issues_dict[i_ident] = i
if hasattr(i,'description'):
idescription = i.description
else:
idescription = ""
nodestable += [[i_ident,i.subject,parent_ident,str(i.id),csys_server_url+'/issues/'+str(i.id),i.tracker.name,idescription,i.status.name]]
for r in i.relations:
if (not onlyblocks) or (r.relation_type == "blocks"):
if r.issue_id == i.id:
dst = redmine.issue.get(r.issue_to_id)
dst_ident = dst.custom_fields.get(cfdict['csID'].id).value
if (not onlyblocks) and (hasattr(r,'delay')):
rdelay = str(r.delay)
else:
rdelay = ""
edgestable += [[i_ident,dst_ident,r.relation_type,rdelay]]
for cp in projects:
if hasattr(cp,'parent'):
if cp.parent.id == p.id:
print(cp.name,"->",p.name)
scan_project(cp)
print("Proyectos:",len(projects))
continueProcess = False
for p in projects:
print(" ",p.identifier," | ",p.name)
if p.identifier == prjName:
continueProcess = True
if continueProcess:
continueProcess = False
my_project = redmine.project.get(prjName)
if my_project is None:
print("No podemos obtener el proyecto")
else:
print ("Obtenemos proyecto: ",my_project.identifier," | ",my_project.name)
# Now we obtain the csCode
for cf in my_project.custom_fields:
print(cf)
prcfdict[cf.name] = cf
if cf.name == "csCode":
file_cscode = cf.value
print("csCode:",file_cscode)
cfields = redmine.custom_field.all()
for cf in cfields:
cfdict[cf.name] = cf
print(cf.name)
print_subprojects(my_project)
scan_project(my_project)
data = OrderedDict() # from collections import OrderedDict
print(nodestable)
print("**************************")
if include_chapters:
finalnodestable = nodestable
finaledgestable = edgestable
else:
finalnodestable = []
finaledgestable = []
for n in nodestable:
n[2] = ""
if n[0] not in chapters_list:
finalnodestable += [n]
for e in edgestable:
if e[0] not in chapters_list and e[1] not in chapters_list:
if e[0] in rm_issues_dict.keys() and e[1] in rm_issues_dict.keys():
finaledgestable += [e]
data.update({"Nodes": [['csID','subject','parentID','rmid','URL','tracker','description','status']]+finalnodestable})
data.update({"Edges": [['src','dst','type','delay']]+finaledgestable})
print(data)
# Saving the information into the ODS file
onlyname = prjName
dirname = os.path.dirname('.')
odsextension = ".xlsx"
save_data(os.path.join(dirname,onlyname+odsextension), data)