17
17
'''
18
18
from idlelib .debugobj_r import remote_object_tree_item
19
19
20
- import ns_def , ns_egt_maker , ns_ddx_figure
20
+ import ns_def , ns_egt_maker , ns_ddx_figure , network_sketcher_cli
21
21
from collections import Counter
22
22
import tkinter as tk ,tkinter .ttk , openpyxl
23
23
import ipaddress , sys , os , re , shutil
24
24
import numpy as np
25
+ import networkx as nx
25
26
26
27
class flow ():
28
+ def add_routing_path_to_flow (self ,full_filepath_master ,flow_list_array ):
29
+ print ('--- Routing path calculation ---' )
30
+ argv_array = ['show' , 'l3_broadcast_domain' ]
31
+ l3_broadcast_array = network_sketcher_cli .ns_cli_run .cli_show (self , full_filepath_master , argv_array )
32
+ #print(l3_broadcast_array)
33
+
34
+ G = nx .Graph ()
35
+ # Add nodes and edges to the graph
36
+ for domain_info in l3_broadcast_array :
37
+ broadcast_domain , device_interfaces = domain_info
38
+ devices = [dev [0 ] for dev in device_interfaces ]
39
+
40
+ # Connect all devices in the broadcast domain (full graph)
41
+ for i in range (len (devices )):
42
+ for j in range (i + 1 , len (devices )):
43
+ G .add_edge (devices [i ], devices [j ])
44
+
45
+ for row in flow_list_array [2 :]:
46
+ data = row [1 ]
47
+ source = data [1 ]
48
+ target = data [2 ]
49
+
50
+ path = flow .get_shortest_path (G , source , target )
51
+ #print(path)
52
+ if 'is not in G' in path :
53
+ continue
54
+
55
+ if len (path ) >= 2 :
56
+ path = path [1 :- 1 ]
57
+ path2 = ', ' .join ([f"'{ p } '" for p in path ])
58
+ if path2 == '' :
59
+ path2 = ' '
60
+
61
+ data [7 ] = path2
62
+
63
+ #print(flow_list_array)
64
+ return (flow_list_array )
65
+
66
+ def get_shortest_path (G ,source , target ):
67
+ try :
68
+ path = nx .shortest_path (G , source = source , target = target )
69
+ #print(source,target,path, G)
70
+ return path
71
+ except nx .NetworkXNoPath :
72
+ return f"The Path from { source } to { target } could not be found."
73
+ except nx .NodeNotFound as e :
74
+ return str (e )
75
+
27
76
def append_flows_to_diagram (self ,variable3_7_y_1 ,variable3_7_y_2 ,variable3_7_y_3 ): #add at ver 2.4.3
28
77
print ('--- append_flows_to_diagram ---' )
29
- print (variable3_7_y_1 .get (), variable3_7_y_2 .get (), variable3_7_y_3 .get ())
30
- print (self .pptx_full_filepath )
31
- print (self .full_filepath )
78
+ # print(variable3_7_y_1.get(), variable3_7_y_2.get(), variable3_7_y_3.get())
79
+ # print(self.pptx_full_filepath)
80
+ # print(self.full_filepath)
32
81
33
82
ws_flow_name = 'Flow_Data'
34
83
excel_maseter_file = self .full_filepath
@@ -56,7 +105,7 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
56
105
(element [4 ] == variable3_7_y_3 .get () or variable3_7_y_3 .get () == 'Any' ):
57
106
filtered_target_flow .append (element )
58
107
59
- print (filtered_target_flow )
108
+ # print(filtered_target_flow)
60
109
61
110
'''read the pptx file and shapes data'''
62
111
self .shape_name_grid_array = []
@@ -75,7 +124,7 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
75
124
except IndexError :
76
125
pass
77
126
78
- print (self .shape_name_grid_array )
127
+ # print(self.shape_name_grid_array)
79
128
80
129
''' deside routes and write flows '''
81
130
if os .path .isfile (self .pptx_full_filepath ) == True :
@@ -117,7 +166,7 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
117
166
if source_grid == None or destination_grid == None :
118
167
continue
119
168
120
- print (source_grid , destination_grid )
169
+ # print(source_grid, destination_grid)
121
170
122
171
line_type = 'FLOW0'
123
172
inche_from_connect_x = (source_grid [1 ] + source_grid [3 ] * 0.25 ) / 914400
@@ -127,10 +176,10 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
127
176
ns_ddx_figure .extended .add_line (self ,line_type ,inche_from_connect_x ,inche_from_connect_y ,inche_to_connect_x ,inche_to_connect_y )
128
177
129
178
elif len (selected_route_path ) >= 3 :
130
- print (selected_route_path )
179
+ # print(selected_route_path)
131
180
for i in range (len (selected_route_path ) - 1 ):
132
181
pair = [selected_route_path [i ], selected_route_path [i + 1 ]]
133
- print (pair ,i ,len (selected_route_path ) - 2 )
182
+ # print(pair,i,len(selected_route_path) - 2 )
134
183
135
184
# get source grid value
136
185
source_grid = next (
@@ -173,6 +222,9 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
173
222
modified_filepath = os .path .join (folder , f"Added_flows_{ filename } " )
174
223
self .active_ppt .save (modified_filepath )
175
224
225
+ #file open
226
+ ns_def .messagebox_file_open (modified_filepath )
227
+
176
228
def get_flow_item_list (self ): # add at ver 2.4.3
177
229
#print('--- get_flow_item_list ---')
178
230
excel_maseter_file = self .inFileTxt_L2_3_1 .get ()
@@ -260,8 +312,9 @@ def export_flow_file(self,dummy):
260
312
for i in range (1 , 8 ):
261
313
if tmp_master_flow_array [1 ][i ] == '' :
262
314
tmp_master_flow_array [1 ][i ] = '<EMPTY>'
315
+ print (tmp_master_flow_array [1 ][7 ])
263
316
264
- flow_list_array .append ([current_row_num , ['' ,str (current_row_num - 2 ), '>>' + str (tmp_master_flow_array [1 ][1 ]), '>>' + str (tmp_master_flow_array [1 ][2 ]), '>>' + str (tmp_master_flow_array [1 ][3 ]), '>>' + str (tmp_master_flow_array [1 ][4 ]), '>>' + str (tmp_master_flow_array [1 ][5 ]), '>>' + str (tmp_master_flow_array [1 ][6 ]),' ' , '<END>' ]])
317
+ flow_list_array .append ([current_row_num , ['' ,str (current_row_num - 2 ), '>>' + str (tmp_master_flow_array [1 ][1 ]), '>>' + str (tmp_master_flow_array [1 ][2 ]), '>>' + str (tmp_master_flow_array [1 ][3 ]), '>>' + str (tmp_master_flow_array [1 ][4 ]), '>>' + str (tmp_master_flow_array [1 ][5 ]), '>>' + str (tmp_master_flow_array [1 ][6 ]),str ( tmp_master_flow_array [ 1 ][ 7 ]) , '<END>' ]])
265
318
current_row_num += 1
266
319
267
320
if flag_master_has_flow_sheet == True and all_empty == True :
0 commit comments