-
Notifications
You must be signed in to change notification settings - Fork 2
/
graph2porisprocess.py
927 lines (748 loc) · 31.9 KB
/
graph2porisprocess.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
import csv, os, re
from bs4 import BeautifulSoup
from pyexcel_ods import save_data
from collections import OrderedDict
from pathlib import Path
from config_csys import *
# Importing test configuration file
import config
from graph2porislib import *
file_data = ['','']
localcsids = {}
inverse_localcsids = {}
def get_project_ancestors(thisproject,rootproject,projects):
if (thisproject.id != rootproject.id):
parentproj = None
if hasattr(thisproject,'parent'):
print("The parent id to find for",thisproject.identifier,"is",thisproject.parent.id)
for p in projects:
if p.id == thisproject.parent.id:
parentproj = p
break
else:
print("The project",thisproject.identifier,"has no parent",dict(thisproject))
if parentproj is not None:
result = get_project_ancestors(parentproj,rootproject,projects)
result += [thisproject]
else:
print("Error, we could not find the parent of ",thisproject.identifier)
#result = [thisproject]
assert(False)
else:
# If thisproject is the root project, we have finished
result = [thisproject]
return result
def get_project_successors(thisproject,projects):
result = []
for p in projects:
if hasattr(p,'parent'):
if p.parent.id == thisproject.id:
result += [p] + get_project_successors(p,projects)
return result
def get_project_tree(thisproject,rootproject,projects):
# First we will add the ancestors
result = get_project_ancestors(thisproject,rootproject,projects)
# Then we will add the successors
result += get_project_successors(thisproject,projects)
return result
def create_ods_file_from_graphml_file(filename, deviceName):
global file_data
global localcsids
global inverse_localcsids
with open(filename) as file:
soup = BeautifulSoup(file, 'lxml-xml')
graph = soup.find("graph",{"id":"G"})
nodes = soup.findAll("node", {"yfiles.foldertype":""})
groups = soup.find_all("node", {"yfiles.foldertype":"group"})
edges = soup.findAll("edge")
urlkey = soup.find("key",{"attr.name":"url"})['id']
csidkey = soup.find("key",{"attr.name":"csID"})['id']
cscodekey = soup.find("key",{"attr.name":"csCode"})['id']
csprjident = soup.find("key",{"attr.name":"identifier"})['id']
csrootprjident = soup.find("key",{"attr.name":"rootid"})['id']
csparentCSIDident = soup.find("key",{"attr.name":"parentCSID"})['id']
csrmid = soup.find("key",{"attr.name":"rmID"})['id']
print("url key",urlkey)
print("csid key",csidkey)
print("parentCSID key",csparentCSIDident)
# Retrieving file_data
file_data = graph.find_all('data')
file_cscode = ""
file_identifier = ""
file_root_identifier = ""
parent_csys_identifier = ""
for n in file_data:
print(n['key'])
if n['key'] == cscodekey:
if len(n.contents) >= 1:
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
file_cscode = thiscontent
else:
file_cscode = 'INS'
if n['key'] == csprjident:
if len(n.contents) >= 1:
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
file_identifier = thiscontent
else:
file_identifier = 'instrument'
if n['key'] == csrootprjident:
if len(n.contents) >= 1:
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
file_root_identifier = thiscontent
else:
file_root_identifier = 'instrument'
if n['key'] == csparentCSIDident:
if len(n.contents) >= 1:
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
parent_csys_identifier = thiscontent
else:
parent_csys_identifier = ''
print("csCode:",file_cscode)
print("identifier:",file_identifier)
print("root_identifier:",file_root_identifier)
print("parent_csys_identifier:",parent_csys_identifier)
continueProcess = False
if not csys_use:
continueProcess = True
else:
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()
print("Proyectos:")
for p in projects:
print(" ",p.identifier," | ",p.name)
if p.identifier == file_identifier:
continueProcess = True
if continueProcess:
continueProcess = False
my_project = redmine.project.get(file_identifier)
if my_project is None:
print("No podemos obtener el proyecto")
else:
print ("Obtenemos proyecto: ",my_project.identifier," | ",my_project.name)
my_root_project = redmine.project.get(file_root_identifier)
if my_root_project is None:
print("No podemos obtener el proyecto raíz")
else:
print ("Obtenemos proyecto raíz: ",my_root_project.identifier," | ",my_root_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:
print(cf)
cfdict[cf.name] = cf
project_tree = get_project_tree(my_project,my_root_project,projects)
for p in project_tree:
print(p.identifier)
rm_issues_dict = {}
for p in project_tree:
for i in p.issues:
i_ident = i.custom_fields.get(cfdict['csID'].id).value
rm_issues_dict[i_ident] = i
print(i_ident,i.subject)
continueProcess = True
if continueProcess:
# First we must find the roots
roots = []
groups_dict = {}
global_dict = {}
csv_dict_data = []
error_list = []
nodes_graphml_d6 = {}
nodes_graphml_url = {}
nodes_graphml_rmid = {}
nodes_graphml = {}
rm_issues_created = {}
for group in groups:
group_dict = {}
group_dict['min'] = None
group_dict['default'] = None
group_dict['max'] = None
group_dict['group_id'] = group['id']
group_dict['csID'] = group['id']
group_name = group.find('y:NodeLabel').text.strip()
group_dict['url'] = ""
group_dict['rmid'] = ""
group_data = group.findChildren('data',recursive=False)
#print("+++",group_name)
nodes_graphml[group['id']] = group
# Prevent having rmide and not having csid (error in removing csID an not removing rmid)
thisrmid = None
thisrmidcontent = None
hascsid = False
hasrmid = False
for n in group_data:
if n['key']==csidkey:
nodes_graphml_d6[group['id']] = n
if len(n.contents) >= 1:
hascsid = True
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
group_dict['csID'] = thiscontent
localcsids[group_dict['group_id']] = group_dict['csID']
if group_dict['csID'] not in inverse_localcsids.keys():
inverse_localcsids[group_dict['csID']] = group_dict['group_id']
else:
error_list += [group_dict['csID'] +" identifier is not unique, check "+ group_name + " and " + global_dict[inverse_localcsids[group_dict['csID']]]['group_name'] ]
print(error_list)
if n['key']==urlkey:
#print("***",group_name,n.contents)
nodes_graphml_url[group['id']] = n
if len(n.contents) >= 1:
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
group_dict['url'] = thiscontent
#group_dict['rmid'] = n.contents[0].split('/')[-1]
if n['key']==csrmid:
#print("***",group_name,n.contents)
if len(n.contents) >= 1:
thisrmid = n
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
thisrmidcontent = thiscontent
hasrmid = True
# Prevent having rmide and not having csid (error in removing csID an not removing rmid)
if hascsid and hasrmid:
nodes_graphml_rmid[group['id']] = thisrmid
group_dict['rmid'] = thisrmidcontent
group_dict['group_name'] = group_name
# The group can be a prSys, or a prParam, or a prValueFloat
group_shape = group.find('y:Shape')['type'].strip()
group_dict['shape'] = group_shape
if group_shape == "parallelogram":
group_dict['node_type'] = "prValFloat"
else:
if group_shape == "roundrectangle":
# We must know if it is a prSys or a prParam
# prParam: <y:Fill color="#CAECFF84" transparent="false"/>
group_color_attribute = group.find('y:Fill')
if group_color_attribute is not None:
if group_color_attribute.get('color') is not None:
group_color = group_color_attribute['color'].strip()
if group_color == "#CAECFF84":
group_dict['node_type'] = "prParam"
else:
group_dict['node_type'] = "prSys"
else:
group_dict['node_type'] = "prSys"
group_id_parts = re.findall(r'n\d{1,}', group_dict['group_id'])
if(len(group_id_parts) > 1):
group_dict['parent_group_id'] = convert_list_to_string(group_id_parts[:-1], '::')
#print("parent_group",group_dict['parent_group_id'],groups_dict[group_dict['parent_group_id']]['group_name'])
group_dict['parent_group_name'] = groups_dict[group_dict['parent_group_id']]['group_name']
else:
roots += [group_dict]
group_dict['parent_group_id'] = None
group_dict['parent_group_name'] = ""
groups_dict[group_dict['group_id']] = group_dict
global_dict[group_dict['group_id']] = group_dict
nodes_dict = {}
# Prevent having rmide and not having csid (error in removing csID an not removing rmid)
thisrmid = None
thisrmidcontent = None
hascsid = False
hasrmid = False
for node in nodes:
ischild = False
isMax = False
isMin = False
isDefault = False
node_dict = {}
node_dict['node_type'] = "unknown"
node_dict['node_id'] = node['id']
node_id_parts = re.findall(r'n\d{1,}', node_dict['node_id'])
node_dict['node_group_id'] = convert_list_to_string(node_id_parts[:-1], '::')
node_dict['node_name'] = node.find('y:NodeLabel').text.strip()
node_data = node.findChildren('data',recursive=False)
node_dict['min'] = None
node_dict['default'] = None
node_dict['max'] = None
node_dict['defaulttext'] = None
node_dict['rmid'] = ""
node_dict['url'] = ""
node_dict['relations'] = []
node_dict['next'] = []
node_dict['csID'] = node['id']
node_shape = node.find('y:Shape')['type'].strip()
#print(node_dict['node_name'],node_shape)
nodes_graphml[node['id']] = node
for n in node_data:
if n['key']==csidkey:
nodes_graphml_d6[node['id']] = n
if len(n.contents) >= 1:
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
node_dict['csID'] = thiscontent
localcsids[node_dict['node_id'] ] = node_dict['csID']
if node_dict['csID'] not in inverse_localcsids.keys():
inverse_localcsids[node_dict['csID']] = node_dict['node_id']
else:
error_list += [node_dict['csID'] +" identifier is not unique, check "+ node_dict['node_name'] + " and " + global_dict[inverse_localcsids[node_dict['csID']]]['node_name'] ]
if n['key']==urlkey:
nodes_graphml_url[node['id']] = n
if len(n.contents) >= 1:
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
node_dict['url'] = thiscontent
if n['key']==csrmid:
#print("***",group_name,n.contents)
thisrmid = n
if len(n.contents) >= 1:
thiscontent = n.contents[0].strip()
if len(thiscontent) > 0:
thisrmidcontent = thiscontent
hasrmid = True
# Prevent having rmide and not having csid (error in removing csID an not removing rmid)
if hascsid and hasrmid:
nodes_graphml_rmid[node['id']] = thisrmid
node_dict['rmid'] = thisrmidcontent
color_attribute = node.find('y:Fill')
node_color = None
if color_attribute is not None:
if color_attribute.get('color') is not None:
node_color = color_attribute['color'].strip()
if node_shape == "parallelogram":
if node_color is not None:
if node_color == "#99CCFF":
node_dict['node_type'] = "prValue"
else:
if node_color == "#CCCCFF":
node_dict['node_type'] = "prValFloat"
second_label = node.find('y:NodeLabel',{"textColor":"#0000FF"}).text.strip()
valueslist = second_label.split('≤')
if len(valueslist) == 1:
valueslist = second_label.split('<')
#print(">>>>>>",valueslist)
node_dict['min'] = float(valueslist[0].strip())
node_dict['default'] = float(valueslist[1].strip())
node_dict['max'] = float(valueslist[2].strip())
else:
if node_color == "#CCFFCC":
# This is prValueText
node_dict['node_type'] = "prValText"
second_label = node.find('y:NodeLabel',{"textColor":"#FF0000"}).text.strip()
node_dict['defaulttext'] = second_label
else:
print("Not recognized, TODO.")
else:
if node_shape == "roundrectangle":
node_dict['node_type'] = "prMode"
else:
if node_shape == "ellipse":
node_dict['node_type'] = "prCmd"
node_tree = []
if('parent_group_name' in groups_dict[node_dict['node_group_id']]):
node_tree.append(groups_dict[node_dict['node_group_id']]['parent_group_name'])
node_dict['node_group_name'] = groups_dict[node_dict['node_group_id']]['parent_group_name']
#node_dict['node_type'] = groups_dict[node_dict['node_group_id']]['node_type']
#node_dict['node_group_sort_order'] = groups_dict[node_dict['node_group_id']]['parent_group_sort_order']
else:
node_dict['node_group_name'] = groups_dict[node_dict['node_group_id']]['group_name']
#node_dict['node_group_sort_order'] = groups_dict[node_dict['node_group_id']]['group_sort_order']
node_tree.append(groups_dict[node_dict['node_group_id']]['group_name'])
node_tree.append(node_dict['node_name'])
node_tree_text = convert_list_to_string(node_tree, ' > ')
#node_tree_text = node_tree_text + ' (' + str(groups_dict[node_dict['node_group_id']]['group_sort_order']) + ')'
nodes_dict[node_dict['node_id']] = node_dict
global_dict[node_dict['node_id']] = node_dict
csv_dict_data.append(node_dict)
if len(error_list) <= 0:
for key in groups_dict:
group_dict = groups_dict[key]
node_dict = {}
node_dict['node_id'] = group_dict['group_id']
node_dict['node_name'] = group_dict['group_name']
node_dict['node_group_id'] = group_dict['parent_group_id']
node_dict['node_group_name'] = group_dict['parent_group_name']
node_dict['node_type'] = group_dict['node_type']
node_dict['min'] = group_dict['min']
node_dict['default'] = group_dict['default']
node_dict['max'] = group_dict['max']
node_dict['defaulttext'] = group_dict['default']
node_dict['url'] = group_dict['url']
node_dict['rmid'] = group_dict['rmid']
node_dict['relations'] = []
node_dict['next'] = []
node_dict['csID'] = group_dict['csID']
nodes_dict[node_dict['node_id']] = node_dict
csv_dict_data.append(node_dict)
for e in edges:
for d in e.find_all('data'):
#print("-->",d)
polyline = d.find('y:PolyLineEdge')
#print("polyline",polyline)
if polyline is not None:
linestile = polyline.find('y:LineStyle')#['type']
if linestile is not None:
if linestile['color'] == "#FF9900":
nodes_dict[e['source']]['relations'] += [e['target']]
else:
nodes_dict[e['source']]['next'] += [e['target']]
data = OrderedDict() # from collections import OrderedDict
print(localcsids)
if csys_use:
trackerdict = {}
trackers = redmine.tracker.all()
for tr in trackers:
trackerdict[tr.name] = tr
rows = [['RM#','url','RMID','ID','row#','subject','','tracker','Rlv?','status','parent',
'blocking_items','precedent_items','prMin','prDefault','prMax','prDefaultText','version','priority']]
rmtranslator = {}
for n in csv_dict_data:
rmissueneeded = False
if csys_use:
# See if the id exists in redmine
if n['csID'] not in rm_issues_dict.keys():
print("NO",n['csID'],rm_issues_dict.keys())
rmissueneeded = True
else:
rmtranslator[n['node_id']] = n['csID']
if rmissueneeded:
print("New rmissue for ", n['node_id'])
thistrackerid = trackerdict[n['node_type']].id
thisRmTsk = redmine.issue.create(project_id = my_project.id,
tracker_id = thistrackerid,
subject = n['node_name'],
)
url = csys_server_url+'/issues/'+str(thisRmTsk.id)
urlwithkey= url +'?key='+csys_key_txt
resp = req.get(urlwithkey)
thisRmTsk = redmine.issue.get(thisRmTsk.id)
thisCsId = thisRmTsk.custom_fields.get(cfdict['csID'].id).value
rm_issues_dict[thisCsId] = thisRmTsk
rmtranslator[n['node_id']] = thisCsId
print("------------------------->",n['node_id'],thisCsId)
n['rmid'] = thisRmTsk.id
n['url'] = url
rm_issues_created[n['node_id']] = thisCsId
print("******************************************************************")
print(rmtranslator)
for n in csv_dict_data:
row = []
thisgroup = n['node_group_id']
if thisgroup is not None:
print("orig",thisgroup)
if csys_use:
if thisgroup in rmtranslator.keys():
thisgroup = rmtranslator[thisgroup]
else:
if thisgroup in localcsids.keys():
thisgroup= localcsids[thisgroup]
relstr = ""
first = True
for c in n['relations']:
if not first:
relstr += ", "
else:
first = False
relid = c
if csys_use:
if relid in rmtranslator.keys():
relid = rmtranslator[relid]
else:
if relid in localcsids.keys():
relid = localcsids[relid]
relstr += relid
n['relations'] = relstr
relstr = ""
first = True
for c in n['next']:
if not first:
relstr += ", "
else:
first = False
relid = c
if csys_use:
if relid in rmtranslator.keys():
relid = rmtranslator[relid]
else:
if relid in localcsids.keys():
relid = localcsids[relid]
relstr += relid
n['next'] = relstr
strparent = ''
if thisgroup is not None:
strparent = thisgroup
else:
# If the item has no parent, then its parent if shall be
# the parentCSID of the project, because a partial diagram must always
# belong to a parent system
strparent = parent_csys_identifier
strrel = ''
if n['relations'] is not None:
strrel = n['relations']
strnext = ''
if n['next'] is not None:
strnext = n['next']
strmin = ''
if n['min'] is not None:
strmin = n['min']
strdefault = ''
if n['default'] is not None:
strdefault = n['default']
strmax = ''
if n['max'] is not None:
strmax = n['max']
strdefaulttext = ''
if n['defaulttext'] is not None:
strdefaulttext = n['defaulttext']
thisid = n['node_id']
if csys_use:
if thisid in rmtranslator.keys():
thisid = rmtranslator[thisid]
else:
if thisid in localcsids.keys():
thisid = localcsids[thisid]
row += [[n['rmid'],n['url'],n['rmid'],thisid,'',n['node_name'],'',n['node_type'],'','',
strparent,strrel,strnext,strmin,strdefault,strmax,strdefaulttext,'','Normal']]
'''
row += [[n['relations'],n['next'],n['default'],n['max']]]
'''
rows += row
data.update({"Dict": [['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',5,'',len(csv_dict_data)+1]
, ['',''], ['',''], ['',file_identifier], ['',file_cscode]]})
data.update({"Items": rows})
data.update({"ExtraFields":[[]]})
dirname = os.path.dirname(filename)
basenamelist = os.path.splitext(os.path.basename(filename))
onlyname = basenamelist[0]
extension = basenamelist[1]
odsextension = ".ods"
save_data(os.path.join(dirname,onlyname+odsextension), data)
print(">>>>",nodes_graphml_d6)
if csys_use:
print(global_dict.keys())
print(rm_issues_created.keys())
# We shall add the csID keys
for k in rm_issues_created.keys():
print(global_dict[k])
# First we update the csId field
global_dict[k]['csID'] = rm_issues_created[k]
# ONGOING PROCESS
if True:
for k in global_dict.keys():
item = global_dict[k]
ident = item['csID']
print("ident is ",ident)
rm = rm_issues_dict[ident]
thisparentid = None
if 'parent_group_id' in item.keys():
thisparentid = item['parent_group_id']
else:
if 'node_group_id' in item.keys():
thisparentid = item['node_group_id']
if thisparentid is not None:
print('parent id is ',thisparentid)
if thisparentid is not None:
thisparentgroup = global_dict[thisparentid]
print("thisparentgroup is ", dict(thisparentgroup))
thisparentcsID = thisparentgroup['csID']
print("thisparentcsID is ", thisparentcsID)
rmparent = rm_issues_dict[thisparentcsID]
print("parent is ", rmparent.subject)
print(dict(rm))
if hasattr(rm,'parent'):
prevparentid = rm.parent.id
else:
prevparentid = None
if prevparentid != rmparent.id:
print("The parent is not the same")
if prevparentid is None:
print("Parent was none")
else:
print("Parent was", str(prevparentid))
rm.parent_issue = rmparent
result = redmine.issue.update(
rm.id,
parent_issue_id = rmparent.id
)
# print("Fixing it!",str(result))
# rm.save
thismin = None
if 'min' in item.keys():
thismin = item['min']
if thismin is not None:
print("thismin is ",thismin)
thismax = None
if 'max' in item.keys():
thismax = item['max']
if thismax is not None:
print("thismax is ",thismax)
thisdefault = None
if 'default' in item.keys():
thisdefault = item['default']
if thisdefault is not None:
print("thisdefault is ",thisdefault)
thisdefaulttext = None
if 'defaulttext' in item.keys():
thisdefaulttext = item['defaulttext']
if thisdefaulttext is not None:
print("thisdefaulttext is ",thisdefaulttext)
shall_update_default = False
shall_update_min = False
shall_update_max = False
shall_update_defaulttext = False
if thismin is not None:
# This is a prValueFloat or similar
print("*** Check min value")
rm_min = None
rm_min_cf = rm.custom_fields.get(cfdict['prMin'].id)
if rm_min_cf is not None:
print("*** preexisting is not none",dict(rm_min_cf))
rm_min = rm_min_cf.value
if rm_min != str(thismin):
print("Fixing min data")
rm_min_cf.value = thismin
print("*** Fixed cf is",dict(rm_min_cf))
shall_update_min = True
if thismax is not None:
# This is a prValueFloat or similar
print("*** Check max value")
rm_max = None
rm_max_cf = rm.custom_fields.get(cfdict['prMax'].id)
if rm_max_cf is not None:
print("*** preexisting is not none",dict(rm_max_cf))
rm_max = rm_max_cf.value
if rm_max != str(thismax):
print("Fixing max data")
rm_max_cf.value = thismax
print("*** Fixed cf is",dict(rm_max_cf))
shall_update_max = True
if thisdefault is not None:
# This is a prValueFloat or similar
print("*** Check default value")
rm_default = None
rm_default_cf = rm.custom_fields.get(cfdict['prDefault'].id)
if rm_default_cf is not None:
print("*** preexisting is not none",dict(rm_default_cf))
rm_default = rm_default_cf.value
if rm_default != str(thisdefault):
print("Fixing default data")
rm_default_cf.value = thisdefault
print("*** Fixed cf is",dict(rm_default_cf))
shall_update_default = True
if thisdefaulttext is not None:
# This is a prValueText or similar
print("*** Check defaulttext value")
rm_defaulttext = None
rm_defaulttext_cf = rm.custom_fields.get(cfdict['prDefaultText'].id)
if rm_defaulttext_cf is not None:
print("*** preexisting is not none",dict(rm_defaulttext_cf))
rm_defaulttext = rm_defaulttext_cf.value
if rm_defaulttext != thisdefaulttext:
print("Fixing defaulttext data")
rm_defaulttext_cf.value = thisdefaulttext
print("*** Fixed cf is",dict(rm_defaulttext_cf))
shall_update_defaulttext = True
if shall_update_default or shall_update_min or shall_update_max or shall_update_defaulttext:
cfs = rm.custom_fields
new_cfs = []
for c in cfs:
thiscv = {}
thiscv['id'] = c['id']
thiscv['value'] = c['value']
if c['id'] == cfdict['prMin'].id and shall_update_min:
thiscv['value'] = thismin
if c['id'] == cfdict['prMax'].id and shall_update_max:
thiscv['value'] = thismax
if c['id'] == cfdict['prDefault'].id and shall_update_default:
thiscv['value'] = thisdefault
if c['id'] == cfdict['prDefaultText'].id and shall_update_defaulttext:
thiscv['value'] = thisdefaulttext
new_cfs.append(thiscv)
print(new_cfs)
result = redmine.issue.update(
rm.id,
custom_fields = new_cfs
)
print("result is", result)
if 'relations' in item.keys():
relations = item['relations']
print("found relations ",relations)
else:
relations = ""
print("not found relations")
print(str(item.keys()))
print(ident, rm.subject,rm.tracker.name, "[", relations, "]")
rels = relations.split(',')
print(rels)
rel_existentes = {}
for ir in rm.relations:
print("ir es ", dict(ir))
if ir.relation_type == 'blocks':
if (rm.id == ir.issue_to_id):
rel_existentes[str(ir.issue_id)] = ir
print("rel_existentes para ", str(rm.id)," es ",str(rel_existentes.keys()))
print("rels es ",rels)
for r in rels:
r = r.strip()
if len(r) > 1:
print("r es ", r)
other_rm = rm_issues_dict[r]
if str(other_rm.id) in rel_existentes.keys():
print("Ya existe la relación " + str(other_rm.id) + ", la quit ode la lista de relaciones existentes")
rel_existentes.pop(str(other_rm.id))
else:
print("Hemos de crear la relación de bloqueo entre la issue ", rm.id," y la issue ", other_rm.id)
relat = redmine.issue_relation.create(
issue_id=other_rm.id,
issue_to_id=rm.id,
relation_type='blocks')
for k in rel_existentes.keys():
print("Debería borrar la relación "+ k + "?" )
# redmine.issue_relation.delete(ir.id)
print("\nItero por las creadas",rm_issues_created)
print("\nd6",nodes_graphml_d6.keys())
print("\npadres",nodes_graphml.keys())
for k in rm_issues_created.keys():
if k in nodes_graphml_d6.keys():
nodes_graphml_d6[k].contents[0].replace_with(rmtranslator[k])
else:
new_tag = soup.new_tag('data',key=csidkey)
new_tag.string = rmtranslator[k]
nodes_graphml[k].append(new_tag)
for k in nodes_dict.keys():
thisurl = nodes_dict[k]['url']
if thisurl=="":
thisurl = csys_server_url+'/issues/'+str(rm_issues_dict[rmtranslator[k]].id)
if k in nodes_graphml_url.keys():
nodes_graphml_url[k].string = thisurl
else:
new_tag = soup.new_tag('data',key=urlkey)
new_tag.string = thisurl
nodes_graphml[k].append(new_tag)
thisrmid = nodes_dict[k]['rmid']
if thisrmid=="":
thisrmid = str(rm_issues_dict[rmtranslator[k]].id)
if k in nodes_graphml_rmid.keys():
nodes_graphml_rmid[k].string = str(thisrmid)
else:
new_tag = soup.new_tag('data',key=csrmid)
new_tag.string = str(thisrmid)
nodes_graphml[k].append(new_tag)
with open(os.path.join(dirname,onlyname+extension+'.out'), "w", encoding='utf-8') as file:
file.write(str(soup))
else:
print("ERROR!\nERROR!\nERROR!\nERROR!")
print("Identifiers inconsistency errors: ")
for e in error_list:
print(e)
print("\n\nPROCESS CANCELLED (identifiers)\n\n\n")
else:
print("\n\nPROCESS CANCELLED\n\n\n")