diff --git a/Ccs/ccs_function_lib.py b/Ccs/ccs_function_lib.py index 3e432684a0c260bc90406f529cb7ae2c4d606a39..5ede9f222a279c7a127a06c0bbea07904ba95410 100644 --- a/Ccs/ccs_function_lib.py +++ b/Ccs/ccs_function_lib.py @@ -1,21 +1,17 @@ import gi gi.require_version('Gtk', '3.0') gi.require_version('Notify', '0.7') + from gi.repository import Gtk, GLib, Notify, GdkPixbuf import subprocess import struct -# import configparser import crcmod import datetime import dateutil.parser as duparser import io -# import itertools import types import sys -# import threading -# import queue import select -# import traceback import json import time import dbus @@ -31,21 +27,14 @@ from s2k_partypes import ptt, ptype_parameters, ptype_values import confignator import importlib -#check_cfg = configparser.ConfigParser() -#check_cfg.read('egse.cfg') -#check_cfg.source = 'egse.cfg' cfg = confignator.get_config(file_path=confignator.get_option('config-files', 'ccs')) -#cfg = confignator.get_config() PCPREFIX = 'packet_config_' project = cfg.get('ccs-database', 'project') -project = PCPREFIX + str(project) -packet_config = importlib.import_module(project) - -#cfg = confignator.get_config(file_path=confignator.get_option('config-files', 'ccs')) -#cfg.source = confignator.get_option('config-files', 'ccs').split('/')[-1] # Used to write into the config file +project_cfg = PCPREFIX + str(project) +packet_config = importlib.import_module(project_cfg) PUS_VERSION, TMHeader, TCHeader, PHeader, TM_HEADER_LEN, TC_HEADER_LEN, P_HEADER_LEN, PEC_LEN, MAX_PKT_LEN, timepack,\ @@ -61,8 +50,7 @@ PLM_PKT_SUFFIX = packet_config.PLM_PKT_SUFFIX FMT_TYPE_PARAM = packet_config.FMT_TYPE_PARAM if cfg.has_section('ccs-user_defined_packets'): - user_tm_decoders = {k: json.loads(cfg['ccs-user_defined_packets'][k]) - for k in cfg['ccs-user_defined_packets']} + user_tm_decoders = {k: json.loads(cfg['ccs-user_defined_packets'][k]) for k in cfg['ccs-user_defined_packets']} else: user_tm_decoders = {} @@ -89,7 +77,7 @@ fmtlist = {'INT8': 'b', 'UINT8': 'B', 'INT16': 'h', 'UINT16': 'H', 'INT32': 'i', personal_fmtlist = ['uint', 'int', 'ascii', 'oct'] fmtlengthlist = {'b': 1, 'B': 1, 'h': 2, 'H': 2, 'i': 4, 'I': 4, 'q': 8, - 'Q': 8, 'f': 4, 'd': 8, 'i24': 3, 'I24': 3} + 'Q': 8, 'f': 4, 'd': 8, 'i24': 3, 'I24': 3} # get format and offset of HK SID SID_FORMAT = {1: '>B', 2: '>H', 4: '>I'} @@ -279,14 +267,13 @@ def start_logging(name): rootLogger = logging.getLogger('') rootLogger.setLevel(loglevel) - socketHandler = logging.handlers.SocketHandler('localhost', - logging.handlers.DEFAULT_TCP_LOGGING_PORT) - # don't bother with a formatter, since a socket handler sends the event as - # an unformatted pickle + socketHandler = logging.handlers.SocketHandler('localhost', logging.handlers.DEFAULT_TCP_LOGGING_PORT) + # don't bother with a formatter, since a socket handler sends the event as an unformatted pickle rootLogger.addHandler(socketHandler) log = logging.getLogger(name) return log + # This returns a dbus connection to a given Application-Name def dbus_connection(name, instance=1): if instance == 0: @@ -314,6 +301,7 @@ def dbus_connection(name, instance=1): logger.warning('Connection to ' + str(name) + ' is not possible') return False + # Returns True if application is running or False if not def is_open(name, instance=1): dbus_type = dbus.SessionBus() @@ -326,6 +314,7 @@ def is_open(name, instance=1): except: return False + def show_functions(conn, filter=None): """ Show all available functions for a CCS application @@ -352,6 +341,7 @@ def show_functions(conn, filter=None): return method_list2 + def ConnectionCheck(dbus_con, argument=None): """ The user friendly version to use the ConnectionCheck method exported by all CCS applications via DBus, checks if the diff --git a/Ccs/editor.py b/Ccs/editor.py index 59e9564238746044ea0923f216a993c9c56ff975..4e652f6055ad177762fefe0bfa2b524f921c675a 100644 --- a/Ccs/editor.py +++ b/Ccs/editor.py @@ -305,7 +305,7 @@ class CcsEditor(Gtk.Window): if not conn.Variables('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.logger.warning('Application {} is not in the same project as {}: Can not communicate'.format( self.my_bus_name, self.cfg['ccs-dbus_names'][application] + str(instance))) return @@ -964,7 +964,7 @@ class CcsEditor(Gtk.Window): page_num = self.editor_notebook.get_current_page() nb_page = self.editor_notebook.get_nth_page(page_num) buf = nb_page.get_child().get_buffer() - if filename == None: + if filename is None: buf.connect('changed', self._notebook_buffer_modified, None, label) hbox.show_all() @@ -973,7 +973,7 @@ class CcsEditor(Gtk.Window): view = self._get_active_view() begin = buf.get_iter_at_line(0) - self._set_play_mark(view, begin); + self._set_play_mark(view, begin) return sourceview @@ -1034,7 +1034,7 @@ class CcsEditor(Gtk.Window): """ save the buffer and reconnect the "changed" signal signal """ def _notebook_save_helper(self, filename, label=None): - if label == None or (not hasattr(label, 'page_num')): + if label is None or (not hasattr(label, 'page_num')): page_num = self.editor_notebook.get_current_page() else: page_num = label.page_num @@ -1044,7 +1044,7 @@ class CcsEditor(Gtk.Window): start, end = buf.get_bounds() text = buf.get_text(start, end, True) - if label == None: + if label is None: label = self._notebookt_current_get_label() label.set_text(label.get_text().strip('*')) buf.connect('changed', self._notebook_buffer_modified, None, label) @@ -1067,7 +1067,7 @@ class CcsEditor(Gtk.Window): return nb_label.get_children()[0] def on_menu_file_save(self, widget=None, label=None): - if label == None: + if label is None: label = self._notebookt_current_get_label() filename = label.get_tooltip_text() @@ -1092,7 +1092,7 @@ class CcsEditor(Gtk.Window): if response == Gtk.ResponseType.OK: filename = dialog.get_filename() self._notebook_save_helper(filename, label=label) - if label == None: + if label is None: label = self._notebookt_current_get_label() label.set_text(filename.split('/')[-1]) label.set_tooltip_text(filename) @@ -1216,7 +1216,7 @@ class CcsEditor(Gtk.Window): try: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(button_img_path, 36, 36) except: - self.logger.info('Could not load image {}'.format(button_img_path)) + self.logger.warning('Could not load image {}'.format(button_img_path)) pixmap_path = os.path.join(pixmap_folder, 'action.png') pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(pixmap_path, 36, 36) icon = Gtk.Image.new_from_pixbuf(pixbuf) @@ -1431,6 +1431,11 @@ class CcsEditor(Gtk.Window): conn_button.connect("clicked", self.on_communication_dialog) vbox.pack_start(conn_button, True, True, 0) + # Add the configuration manager option + conn_button = Gtk.Button.new_with_label('Preferences') + conn_button.connect("clicked", cfl.start_config_editor) + vbox.pack_start(conn_button, True, True, 0) + # Add the option to see the Credits about_button = Gtk.Button.new_with_label('About') about_button.connect("clicked", self._on_select_about_dialog) @@ -1452,10 +1457,8 @@ class CcsEditor(Gtk.Window): self.popover.popup() def on_communication_dialog(self, button): - cfl.change_communication_func(main_instance=self.main_instance, parentwin=self) - - #self._to_console("cfl.communication = " + str(cfl.communication)) + # self._to_console("cfl.communication = " + str(cfl.communication)) def on_button_nextline(self, widget=None, data=None): self.button_run_nextline.set_sensitive(False) @@ -1732,7 +1735,7 @@ class CcsEditor(Gtk.Window): action_name = widget.get_name() if not (self.cfg.has_option('ccs-actions', action_name) and self.cfg.get('ccs-actions', action_name) != ''): - self.logger.info(action_name + ': not defined!') + self.logger.warning(action_name + ': not defined!') return action = os.path.join(action_folder, self.cfg.get('ccs-actions', action_name)) diff --git a/Ccs/pus_datapool.py b/Ccs/pus_datapool.py index 9790fe42fb5d6e8aaf4060388aee39de0097bef6..906e060012eed0aeca5bd44fedca0c77c83ecfdf 100644 --- a/Ccs/pus_datapool.py +++ b/Ccs/pus_datapool.py @@ -402,7 +402,7 @@ class DatapoolManager: try: sockfd.connect((host, port)) except ConnectionRefusedError: - self.logger.warning("Connection to {}:{} refused".format(host, port)) + self.logger.error("Connection to {}:{} refused".format(host, port)) return self.connections[pool_name] = {'socket': sockfd, 'recording': True, 'protocol': protocol} diff --git a/Tst/start_config_editor.py b/Tst/start_config_editor.py deleted file mode 100755 index 31010aba06e0c256b56e3ecab3794cc66706a817..0000000000000000000000000000000000000000 --- a/Tst/start_config_editor.py +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env python3 -import ccs_function_lib as cfl - -if __name__ == '__main__': - cfl.start_config_editor()