diff --git a/Ccs/poolview_sql.py b/Ccs/poolview_sql.py index c5ff8ae83b7238e6da8948ab897cca95c7f74270..733c57f6e1a9cc089b05a3a825d3b66b17534a2d 100644 --- a/Ccs/poolview_sql.py +++ b/Ccs/poolview_sql.py @@ -274,15 +274,15 @@ class TMPoolView(Gtk.Window): def quit_func(self, *args): #Check if Poolmanager is running otherwise just close viewer - pmgr = cfl.dbus_connection('poolmanager', cfl.communication['poolmanager']) - if not pmgr: + if not cfl.is_open('poolmanager', cfl.communication['poolmanager']): self.close_terminal_connection() self.update_all_connections_quit() Gtk.main_quit() return False + pmgr = cfl.dbus_connection('poolmanager', cfl.communication['poolmanager']) # Check if Gui and only close poolviewer if it is - if pmgr.Variables('gui_running'): + if cfl.Variables(pmgr, 'gui_running'): self.close_terminal_connection() self.update_all_connections_quit() Gtk.main_quit() @@ -361,7 +361,7 @@ class TMPoolView(Gtk.Window): def set_pool_from_pmgr(self): try: poolmgr = cfl.dbus_connection('poolmanager', cfl.communication['poolmanager']) - pools = poolmgr.Functions('loaded_pools_export_func') + pools = cfl.Functions(poolmgr, 'loaded_pools_export_func') for pool in pools: self.set_pool(pool[0]) except: @@ -373,8 +373,8 @@ class TMPoolView(Gtk.Window): poolmgr = cfl.dbus_connection('poolmanager', cfl.communication['poolmanager']) if not poolmgr: raise TypeError - self.Active_Pool_Info_append(poolmgr.Dictionaries('loaded_pools', pool_name)) - poolmgr.Functions('loaded_pools_func', self.active_pool_info.pool_name, self.active_pool_info) + self.Active_Pool_Info_append(cfl.Dictionaries(poolmgr, 'loaded_pools', pool_name)) + cfl.Functions(poolmgr, 'loaded_pools_func', self.active_pool_info.pool_name, self.active_pool_info) except: if '/' in pool_name: pool_name = pool_name.split('/')[-1] @@ -455,7 +455,7 @@ class TMPoolView(Gtk.Window): conn = cfl.dbus_connection(application, instance) # Both are not in the same project do not change - if not conn.Variables('main_instance') == self.main_instance: + if not cfl.Variables(conn, 'main_instance') == self.main_instance: print('Both are not running in the same project, no change possible') self.logger.info('Application {} is not in the same project as {}: Can not communicate'.format( self.my_bus_name, self.cfg['ccs-dbus_names'][application] + str(instance))) @@ -2114,7 +2114,7 @@ class TMPoolView(Gtk.Window): poolmgr = cfl.dbus_connection('poolmanager', cfl.communication['poolmanager']) if not poolmgr: raise TypeError - self.Active_Pool_Info_append(poolmgr.Dictionaries('loaded_pools', pool_name)) + self.Active_Pool_Info_append(cfl.Dictionaries(poolmgr, 'loaded_pools', pool_name)) except: new_session = self.session_factory_storage @@ -2279,7 +2279,7 @@ class TMPoolView(Gtk.Window): # Instance has to be used only here, explanation is found in pus_datapool where this function is called if instance: poolmgr = cfl.dbus_connection('poolmanager', instance) - poolmgr.Functions('loaded_pools_func', self.active_pool_info.pool_name, self.active_pool_info) + cfl.Functions(poolmgr, 'loaded_pools_func', self.active_pool_info.pool_name, self.active_pool_info) return @@ -2770,7 +2770,8 @@ class TMPoolView(Gtk.Window): # Whole function is now done in Poolmgr def load_pool(self, widget=None, filename=None, brute=False, force_db_import=False, protocol='PUS'): if cfl.is_open('poolmanager', cfl.communication['poolmanager']): - poolmgr = cfl.dbus_connection('poolmanager', cfl.communication['poolmanager']) + #poolmgr = cfl.dbus_connection('poolmanager', cfl.communication['poolmanager']) + pass else: cfl.start_pmgr(True, '--nogui') #path_pm = os.path.join(confignator.get_option('paths', 'ccs'), 'pus_datapool.py') @@ -2822,7 +2823,7 @@ class TMPoolView(Gtk.Window): if filename is not None and filename: pool_name = filename.split('/')[-1] try: - new_pool = poolmgr.Functions('load_pool_poolviewer', pool_name, filename, brute, force_db_import, + new_pool = cfl.Functions(poolmgr, 'load_pool_poolviewer', pool_name, filename, brute, force_db_import, self.count_current_pool_rows(), self.my_bus_name[-1], protocol) except: @@ -2860,7 +2861,7 @@ class TMPoolView(Gtk.Window): package_type == 'SPW' ## package_type defines which type was selected by the user, if any was selected - new_pool = poolmgr.Functions('load_pool_poolviewer', pool_name, filename, isbrute, force_db_import, + new_pool = cfl.Functions(poolmgr, 'load_pool_poolviewer', pool_name, filename, isbrute, force_db_import, self.count_current_pool_rows(), self.my_bus_name[-1], package_type) dialog.destroy() @@ -3180,6 +3181,22 @@ class TMPoolView(Gtk.Window): return + def stop_all_recording(self): + """ + Poolmanager is closed and therefore all "Live" Pools become static pools + Functions is normally called by the poolmanager when it is closing + """ + # If active pool is live change it to static + if self.active_pool_info.live: + self.active_pool_info = ActivePoolInfo(self.active_pool_info.file_name, self.active_pool_info.modification_time, self.active_pool_info.pool_name, False) + + iter = self.pool_selector.get_active_iter() + mod = self.pool_selector.get_model() + if mod is not None: + mod[iter][1] = self.live_signal[self.active_pool_info.live] + self.stop_butt.set_sensitive(False) + return + def refresh_treeview(self, pool_name): # thread = threading.Thread(target=self.refresh_treeview_worker, args=[pool_name]) # thread.daemon = True @@ -3192,7 +3209,7 @@ class TMPoolView(Gtk.Window): poolmgr = cfl.dbus_connection('poolmanager', cfl.communication ['poolmanager']) # while not self.pool.recordingThread.stopRecording: # Get value of dict connections, with key self.active... and key recording, True to get - pool_connection_recording = poolmgr.Dictionaries('connections', self.active_pool_info.pool_name, 'recording', True) + pool_connection_recording = cfl.Dictionaries(poolmgr, 'connections', self.active_pool_info.pool_name, 'recording', True) type = self.decoding_type #while self.pool.connections[self.active_pool_info.pool_name]['recording']: while pool_connection_recording: @@ -3204,13 +3221,20 @@ class TMPoolView(Gtk.Window): self.stop_recording() def refresh_treeview_worker2(self, pool_name): - poolmgr = cfl.dbus_connection('poolmanager', cfl.communication['poolmanager']) - if pool_name != self.active_pool_info.pool_name: return False + + if not self.active_pool_info.live: + return False + + if cfl.is_open('poolmanager', cfl.communication['poolmanager']): + poolmgr = cfl.dbus_connection('poolmanager', cfl.communication['poolmanager']) + else: + return False + # Get value of dict connections, with key self.active... and key recording, True to get pool_connection_recording = poolmgr.Dictionaries('connections', self.active_pool_info.pool_name, 'recording', - True) + True, ignore_reply=True) #pool_connection = poolmgr.Dictionaries('connections', self.active_pool_info.pool_name) if pool_connection_recording: #if self.pool.connections[self.active_pool_info.pool_name]['recording']: diff --git a/Ccs/pus_datapool.py b/Ccs/pus_datapool.py index c3b31c277393adcf1cc1e2538c1ccd621104a554..9c91f2b40db722df5186890ba650987c8dd4cd8e 100644 --- a/Ccs/pus_datapool.py +++ b/Ccs/pus_datapool.py @@ -1862,7 +1862,6 @@ class DatapoolManager: self.quit_func() def quit_func(self): - pv = cfl.dbus_connection('poolviewer') for service in dbus.SessionBus().list_names(): if service.startswith(self.cfg['ccs-dbus_names']['editor']): editor = cfl.dbus_connection(service[0:-1].split('.')[1], service[-1]) @@ -1871,9 +1870,19 @@ class DatapoolManager: if nr == str(1): nr = '' editor.Functions('_to_console_via_socket', 'del(pmgr' + str(nr) + ')') - self.update_all_connections_quit() - Gtk.main_quit() + if cfl.is_open('poolviewer', cfl.communication['poolviewer']): + pv = cfl.dbus_connection('poolviewer', cfl.communication['poolviewer']) + # Ignore_reply = True not recommended, but it is checked here that it is working + pv.Functions('stop_all_recording', ignore_reply=True) # Tell poolviewer that pool is no longer live + time.sleep(1) + + try: + self.update_all_connections_quit() + except: + self.logger.warning('Communication Variable could not be changed for all running applicaitons') + finally: + Gtk.main_quit() return True def update_all_connections_quit(self): @@ -1882,12 +1891,14 @@ class DatapoolManager: available :return: ''' - our_con = [] # All connections to running applications without communicions form the same applications as this + + our_con = [] # All connections to running applications without communications from the same applications as this my_con = [] # All connections to same applications as this for service in dbus.SessionBus().list_names(): if service.split('.')[1] in self.cfg['ccs-dbus_names']: # Check if connection belongs to CCS if service == self.my_bus_name: # If own allplication do nothing continue + self.logger.debug(type(service)) conn = cfl.dbus_connection(service.split('.')[1], service[-1]) if cfl.Variables(conn,'main_instance') == self.main_instance: # Check if running in same project if service.startswith(self.my_bus_name[:-1]): # Check if it is same application type diff --git a/Tst/prep_test_env.py b/Tst/prep_test_env.py index f58104086cc451ed60427bfe215a166eb3ea8caa..3c3f948ca463b1f73bd224a95a599eed48076bf3 100755 --- a/Tst/prep_test_env.py +++ b/Tst/prep_test_env.py @@ -40,6 +40,8 @@ def run(pool_name): logger.info('2) ------------------- Start the PoolManager -------------------') if not cfl.is_open('poolmanager'): cfl.start_pmgr() + else: + time.sleep(2) pm = connect_apps.connect_to_app('poolmanager', logger=logger) logger.info('4) ------------------- Connect the Poolmanager to OBC & TMpool database-------------------') if pm is not False: @@ -53,6 +55,8 @@ def run(pool_name): logger.info('3) ------------------- Start the PoolViewer -------------------') if not cfl.is_open('poolviewer'): cfl.start_pv() + else: + time.sleep(2) pv = connect_apps.connect_to_app('poolviewer', logger=logger) if pv is not False: diff --git a/Tst/start_tst.py b/Tst/start_tst.py index 74b7a0c4f60a10ee3746ee5dddeecb8bd121adb4..84e8872c1c3a865e20b7383f2767bd043038edd2 100755 --- a/Tst/start_tst.py +++ b/Tst/start_tst.py @@ -1,5 +1,10 @@ #!/usr/bin/env python3 -from tst import tst +import confignator +import sys +sys.path.append(confignator.get_option('paths', 'ccs')) +import ccs_function_lib as cfl +cfl.add_tst_import_paths() +import tst if __name__ == '__main__': tst.run()