@@ -44,72 +44,83 @@ def update_handler(self):
4444
4545 # if n == 0:
4646 print ("update handler started.." )
47- if self .start_update_handler == True :
47+ # if self.start_update_handler == True:
4848
49- while True :
50- if len (self .processing ) == 0 :
51- self .start_update_handler = False
52- break
49+ while True :
50+ if len (self .processing ) == 0 :
51+ self .start_update_handler = False
52+ return
5353
54- msg = {"type" :"WRITE_QUERY" , "username" :self .username , "processing" :self .processing }
54+ msg = {"type" :"WRITE_QUERY" , "username" :self .username , "processing" :self .processing }
5555
56- s = socket .socket ()
56+ s = socket .socket ()
57+
58+ ip = MDS_IPs ["primary" ]["ip" ]
59+ port = MDS_IPs ["primary" ]["port" ]
60+ # print(s.gethostname())
61+ s .bind (('' , 9090 ))
62+
63+ try :
64+ s .connect ((ip , port ))
65+
66+ _send_msg (s , msg )
5767
58- ip = MDS_IPs ["primary" ]["ip" ]
59- port = MDS_IPs ["primary" ]["port" ]
60- # print(s.gethostname())
61- s .bind (('' , 9090 ))
62-
63- try :
64- s .connect ((ip , port ))
65-
66- _send_msg (s , msg )
68+ response = _wait_recv_msg (s , MSG_SIZE )
69+
70+ s .close ()
71+ if response ["status" ] == "SUCCESS" : # here check response from mds
72+ print (response ["msg" ])
73+ file_written = response ["file_written" ]
6774
68- response = _wait_recv_msg (s , MSG_SIZE )
69-
70- s .close ()
71- if response ["status" ] == "SUCCESS" : # here check response from mds
72- print (response ["msg" ])
73- file_written = response ["file_written" ]
74-
75- for filename in file_written : #populate listbox again
76- self .listbox .insert (END , filename )
77- # listbox.insert(END, percent)
78- self .listbox .update_idletasks ()
79-
80- for file in file_written :
81- self ._popup ("Update" , str (file )+ " UPLOADED SUCCESSFULLY" )
82-
83- tree = response ["tree" ]
84- self .dir_tree = tree ["dir_tree" ]
85- self .processing = tree ["processing" ]
86- # update on GUI
87-
88- # self._update_canvas()
89-
90- for filename in file_written : #populate listbox again
91- self .listbox .insert (END , filename )
92- # listbox.insert(END, percent)
93- self .listbox .update_idletasks ()
94-
95- # tk.mainloop()
96- # self.window.mainloop()
97- elif response ["status" ] == "NO_UPD" :
98- print (response ["msg" ])
99- time .sleep (self .update_interval )
100-
75+ for file in file_written : #populate listbox again
76+ filename = file [0 ]
77+ file_id = file [1 ]
78+ file_path = file [2 ]
79+ self .file_id_map [filename ] = file_id
80+ self .listbox .insert (tk .END , file_path )
81+ # listbox.insert(END, percent)
82+ self .listbox .update_idletasks ()
83+
84+ tree = response ["tree" ]
85+ self .dir_tree = tree ["dir_tree" ]
86+ self .processing = tree ["processing" ]
87+ print (self .processing )
88+ if len (self .processing ) == 0 :
89+ self .start_update_handler = False
90+ print ("Exiting update handler" )
91+
92+ for file in file_written :
93+ self ._popup ("Update" , str (file [2 ])+ " UPLOADED SUCCESSFULLY" )
94+
95+
96+ # return
97+ # update on GUI
10198
102- except Exception as e :
103- s .close ()
104- print ("Update (write) from MDS failed" )
105- print (e )
106- time .sleep (self .update_interval )
107-
99+ # self._update_gui()
108100
109- finally :
101+ # for filename in file_written: #populate listbox again
102+ # self.listbox.insert(END, filename)
103+ # # listbox.insert(END, percent)
104+ # self.listbox.update_idletasks()
110105
111- time .sleep (self .update_interval )
106+ # tk.mainloop()
107+ # self.window.mainloop()
108+ elif response ["status" ] == "NO_UPD" :
109+ print (response ["msg" ])
110+ time .sleep (self .update_interval )
111+
112+
113+ except Exception as e :
114+ s .close ()
115+ print ("Update (write) from MDS failed" )
116+ print (e )
117+ time .sleep (self .update_interval )
118+
119+
120+ finally :
112121
122+ time .sleep (self .update_interval )
123+
113124
114125
115126 def upload (self , file_path ):
@@ -258,10 +269,10 @@ def _write(self, pg, pg_data):
258269 if osd_response ["status" ] == "RECEIVED" :
259270 print ("file sent to OSD" )
260271 self .processing [pg .pg_id ] = pg_data
261- if self .start_update_handler == False :
262- self .start_update_handler = True
263- self .update_handler ()
264- # threading.Thread(target=self.update_handler())
272+ # if self.start_update_handler == False:
273+ # self.start_update_handler = True
274+ # self.update_handler()
275+ threading .Thread (target = self .update_handler ())
265276 s .close ()
266277 return 0
267278
@@ -403,7 +414,7 @@ def _update_gui(self):
403414
404415
405416 scrollbar .config ( command = self .listbox .yview )
406-
417+ tk . mainloop ()
407418
408419 def browseFiles (self ):
409420 filename = filedialog .askopenfilename (initialdir = "/" ,
@@ -563,7 +574,7 @@ def login():
563574
564575 print ("[ERROR] login failed" )
565576 print (e )
566- _popup ("Login Failed" , response [ "msg" ] )
577+ _popup ("Login Failed" , str ( e ) )
567578
568579 finally :
569580 print ("Exiting login.." )
0 commit comments