Fix in python supervision (#2210)

Control panel configuration : only search for "conf/control_panel.xml".
This commit is contained in:
Fabien-B
2018-01-08 22:21:32 +01:00
committed by Gautier Hattenberger
parent 4a7983370e
commit 751d9c7fcf
2 changed files with 64 additions and 55 deletions
+47 -45
View File
@@ -268,58 +268,16 @@ class Hmi(Widgets.QMainWindow):
# [Hmi methods] Init HMI methods
def init_hmi_data(self):
"""
-> Initialization of a 'Data' object with all necessary data from XML
files found in the 'CONF_PATH' Paparazzi UAV directory.
-> Loading of cache data (last settings used) to restore them.
-> Initialization of main HMI widgets with necessary data found.
"""
init_conf_xml_path()
# Data object creation implies XML parsing in the parser module :
try:
self.data = parser.Data(CONF_PATH)
# Cache parameters extracted from the cache dictionary :
last_geometry = self.data.cache[parser.LAST_GEOMETRY].split(" ")
last_x, last_y, last_width, last_height = map(int, last_geometry)
self.setGeometry(last_x, last_y, last_width, last_height)
last_set_name = self.data.cache[parser.LAST_SET]
self.current_set = self.data.sets[last_set_name]
point_symbol_link_to(self.current_set.name)
last_config_name = self.data.cache[parser.LAST_CONFIG]
self.current_config = self.data.configurations[last_config_name]
last_target_name = self.data.cache[parser.LAST_TARGET]
self.current_target = self.current_config.targets[last_target_name]
self.ui.upload.setEnabled(self.current_target.name
not in self.simulation_targets_names)
last_device_name = self.data.cache[parser.LAST_DEVICE]
self.current_device = self.data.devices[last_device_name]
last_session_name = self.data.cache[parser.LAST_SESSION]
self.current_session = self.data.sessions[last_session_name]
last_log_filters = self.data.cache[parser.LAST_LOG_FILTERS].split(" ")
last_level = last_log_filters[0]
last_default, last_info, last_warning, last_error =\
map(int, last_log_filters[1:])
self.current_log_filter = cs.LogFilter(last_level,
last_default, last_info,
last_warning, last_error)
self.init_hmi_data_core()
except:
" if something goes wrong, delete cache and load again (to be improved)"
LOGGER.error("ERROR while load HMI cache"
"Original message : '%s'.", sys.exc_info()[0])
print("HMI error in cache, load default instead")
parser.delete_cache()
self.init_hmi_data()
self.init_hmi_data_core()
# Run and build Paparazzi versions found by existing program
# './paparazzi_version' and file './var/build_version.txt' :
run_version_cmd = env.RUN_VERSION_EXE
@@ -327,6 +285,50 @@ class Hmi(Widgets.QMainWindow):
build_version_cmd = " ".join(["cat", env.BUILD_VERSION_FILE])
self.build_version = os.popen(build_version_cmd).readline().strip()
def init_hmi_data_core(self):
"""
-> Initialization of a 'Data' object with all necessary data from XML
files found in the 'CONF_PATH' Paparazzi UAV directory.
-> Loading of cache data (last settings used) to restore them.
-> Initialization of main HMI widgets with necessary data found.
"""
init_conf_xml_path()
self.data = parser.Data(CONF_PATH)
# Cache parameters extracted from the cache dictionary :
last_geometry = self.data.cache[parser.LAST_GEOMETRY].split(" ")
last_x, last_y, last_width, last_height = map(int, last_geometry)
self.setGeometry(last_x, last_y, last_width, last_height)
last_set_name = self.data.cache[parser.LAST_SET]
self.current_set = self.data.sets[last_set_name]
point_symbol_link_to(self.current_set.name)
last_config_name = self.data.cache[parser.LAST_CONFIG]
self.current_config = self.data.configurations[last_config_name]
last_target_name = self.data.cache[parser.LAST_TARGET]
self.current_target = self.current_config.targets[last_target_name]
self.ui.upload.setEnabled(self.current_target.name
not in self.simulation_targets_names)
last_device_name = self.data.cache[parser.LAST_DEVICE]
self.current_device = self.data.devices[last_device_name]
last_session_name = self.data.cache[parser.LAST_SESSION]
self.current_session = self.data.sessions[last_session_name]
last_log_filters = self.data.cache[parser.LAST_LOG_FILTERS].split(" ")
last_level = last_log_filters[0]
last_default, last_info, last_warning, last_error =\
map(int, last_log_filters[1:])
self.current_log_filter = cs.LogFilter(last_level,
last_default, last_info,
last_warning, last_error)
def init_hmi_widgets(self):
"""
-> Initialization of all the HMI widgets content.
+17 -10
View File
@@ -381,7 +381,15 @@ def load_init_files(conf_path):
matching with '*conf*.xml', 'control_panel.xml' and 'flash_modes.xml'.
-> Show the result of scan if DEBUG mode is on (main.py)
"""
conf_files, cp_files, devices_files = [], [], []
conf_files, devices_files = [], []
cp_file = None
cp_path = conf_path + "/" + CONTROL_PANEL + XML_EXT
if os.path.exists(cp_path):
cp_file = cp_path
else:
raise Exception("%s not found!"% conf_path)
for root, dirs, files in os.walk(conf_path):
for file in files:
ext = os.path.splitext(file)[1]
@@ -392,12 +400,12 @@ def load_init_files(conf_path):
and xml_file != env.PAPARAZZI_CONF+"/conf.xml":
conf_files.append(xml_file)
elif file == CONTROL_PANEL_FILE and "airframes" not in root:
cp_files.append(xml_file)
pass
elif file == DEVICES_FILE:
devices_files.append(xml_file)
result = "{} startup files found."
files_nb = sum((len(conf_files), len(cp_files), len(devices_files)))
result = "{} startup files found." # exclude control_panel.xml
files_nb = sum((len(conf_files), len(devices_files)))
info = result.format(files_nb)
if logging.DEBUG:
@@ -408,9 +416,8 @@ def load_init_files(conf_path):
for file in devices_files:
LOGGER.debug(file)
LOGGER.debug("'control_panel' file(s) :")
for file in cp_files:
LOGGER.debug(file)
return conf_files, cp_files, devices_files, info
LOGGER.debug(cp_file)
return conf_files, cp_file, devices_files, info
###############################################################################
@@ -812,10 +819,10 @@ class Data(object):
def load_sessions_and_programs(self):
LOGGER.info("Loading programs and sessions...")
if len(self.cp_file) == 1:
if self.cp_file is not None:
self.tools, self.sessions, \
load_info = load_sessions_and_programs(self.cp_file[0])
load_info = load_sessions_and_programs(self.cp_file)
LOGGER.debug(load_info)
LOGGER.info("Programs and sessions loaded.\n")
else:
LOGGER.error("ERROR : Multiple '%s' XML files !", CONTROL_PANEL)
LOGGER.error("ERROR : control_panel.xml not found!")