From 261600121a5c0402cd9e90c6593144a77f61122c Mon Sep 17 00:00:00 2001 From: Aleksei S Date: Mon, 17 Sep 2018 15:29:02 +0200 Subject: [PATCH 01/10] Created Cura setting visibility test --- scripts/check_setting_visibility.py | 113 ++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 scripts/check_setting_visibility.py diff --git a/scripts/check_setting_visibility.py b/scripts/check_setting_visibility.py new file mode 100644 index 0000000000..489b00747e --- /dev/null +++ b/scripts/check_setting_visibility.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +# +# This script check correctness of settings visibility list +# +from typing import Dict +import os +import sys +import json +import configparser +import glob + +# Directory where this python file resides +SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) + + +# The order of settings type. If the setting is in basic list then it also should be in expert +setting_visibility = ["basic", "advanced", "expert"] + + +class SettingVisibilityInspection: + + + def __init__(self) -> None: + self.all_settings_keys = [] + self.all_settings_categories = [] + + + def defineAllCuraSettings(self, fdmprinter_json_path: str) -> None: + + with open(fdmprinter_json_path) as f: + json_data = json.load(f) + self._flattenAllSettings(json_data) + + + def _flattenAllSettings(self, json_file: Dict[str, str]) -> None: + for key, data in json_file["settings"].items(): # top level settings are categories + self._flattenSettings(data["children"]) # actual settings are children of top level category-settings + + def _flattenSettings(self, settings: Dict[str, str]) -> None: + for key, setting in settings.items(): + + if "type" in setting and setting["type"] != "category": + self.all_settings_keys.append(key) + else: + self.all_settings_categories.append(key) + + if "children" in setting: + self._flattenSettings(setting["children"]) + + + def getSettingsFromSettingVisibilityFile(self, file_path: str): + parser = configparser.ConfigParser(allow_no_value = True) + parser.read([file_path]) + + if not parser.has_option("general", "name") or not parser.has_option("general", "weight"): + raise NotImplementedError("Visibility setting file missing general data") + + settings = {} + for section in parser.sections(): + if section == 'general': + continue + + if section not in settings: + settings[section] = [] + + for option in parser[section].keys(): + settings[section].append(option) + + return settings + + def validateSettingsVisibility(self, setting_visibility_items: Dict): + + for visibility_type in setting_visibility: + item = setting_visibility_items[visibility_type] + + for category, settings in item.items(): + ss = 3 + + + + +if __name__ == "__main__": + + all_setting_visibility_files = glob.glob(os.path.join(os.path.join(SCRIPT_DIR, "..", "resources", "setting_visibility"), '*.cfg')) + fdmprinter_def_path = os.path.join(SCRIPT_DIR, "..", "resources", "definitions", "fdmprinter.def.json") + + inspector = SettingVisibilityInspection() + inspector.defineAllCuraSettings(fdmprinter_def_path) + + setting_visibility_items = {} + for file_path in all_setting_visibility_files: + temp = inspector.getSettingsFromSettingVisibilityFile(all_setting_visibility_files[0]) + + base_name = os.path.basename(file_path) + visibility_type = base_name.split('.')[0] + + setting_visibility_items[visibility_type] = temp + + + inspector.validateSettingsVisibility(setting_visibility_items) + + found_error = False + # Validate settings + # for item in setting_visibility: + + + + + + + + + sys.exit(0 if not found_error else 1) From c764b31e06d4899e90758b9042941f5ecfcd2858 Mon Sep 17 00:00:00 2001 From: Aleksei S Date: Tue, 18 Sep 2018 11:10:24 +0200 Subject: [PATCH 02/10] Update unit test for 'visibilit_settings' and removed unused settings from expert.cfv CURA-5734 --- resources/setting_visibility/expert.cfg | 2 - scripts/check_setting_visibility.py | 119 ++++++++++++++++++------ 2 files changed, 93 insertions(+), 28 deletions(-) diff --git a/resources/setting_visibility/expert.cfg b/resources/setting_visibility/expert.cfg index 0ca2cbab70..437790ef74 100644 --- a/resources/setting_visibility/expert.cfg +++ b/resources/setting_visibility/expert.cfg @@ -110,7 +110,6 @@ material_extrusion_cool_down_speed default_material_bed_temperature material_bed_temperature material_bed_temperature_layer_0 -material_diameter material_adhesion_tendency material_surface_energy material_flow @@ -360,7 +359,6 @@ coasting_min_volume coasting_speed skin_alternate_rotation cross_infill_pocket_size -cross_infill_apply_pockets_alternatingly spaghetti_infill_enabled spaghetti_infill_stepped spaghetti_max_infill_angle diff --git a/scripts/check_setting_visibility.py b/scripts/check_setting_visibility.py index 489b00747e..37e489c072 100644 --- a/scripts/check_setting_visibility.py +++ b/scripts/check_setting_visibility.py @@ -21,9 +21,7 @@ class SettingVisibilityInspection: def __init__(self) -> None: - self.all_settings_keys = [] - self.all_settings_categories = [] - + self.all_settings_keys = {} def defineAllCuraSettings(self, fdmprinter_json_path: str) -> None: @@ -34,18 +32,20 @@ class SettingVisibilityInspection: def _flattenAllSettings(self, json_file: Dict[str, str]) -> None: for key, data in json_file["settings"].items(): # top level settings are categories - self._flattenSettings(data["children"]) # actual settings are children of top level category-settings - def _flattenSettings(self, settings: Dict[str, str]) -> None: + if "type" in data and data["type"] == "category": + + self.all_settings_keys[key] = [] + self._flattenSettings(data["children"], key) # actual settings are children of top level category-settings + + def _flattenSettings(self, settings: Dict[str, str], category) -> None: for key, setting in settings.items(): if "type" in setting and setting["type"] != "category": - self.all_settings_keys.append(key) - else: - self.all_settings_categories.append(key) + self.all_settings_keys[category].append(key) if "children" in setting: - self._flattenSettings(setting["children"]) + self._flattenSettings(setting["children"], category) def getSettingsFromSettingVisibilityFile(self, file_path: str): @@ -70,13 +70,92 @@ class SettingVisibilityInspection: def validateSettingsVisibility(self, setting_visibility_items: Dict): + not_valid_categories = {} + not_valid_setting_by_category = {} + not_valid_setting_by_order = {} + + visible_settings_order = [] # This list is used to make sure that the settings are in the correct order. + # basic.cfg -> advanced.cfg -> expert.cfg. Like: if the setting 'layer_height' in 'basic.cfg' then the same setting + # also should be in 'advanced.cfg' + + all_settings_categories = list(self.all_settings_keys.keys()) + + # visibility_type = basic, advanced, expert for visibility_type in setting_visibility: item = setting_visibility_items[visibility_type] - for category, settings in item.items(): - ss = 3 + not_valid_setting_by_category[visibility_type] = [] # this list is for keeping invalid settings. + not_valid_categories[visibility_type] = [] + + for category, category_settings in item.items(): + + # Validate Category, If category is not defined then the test will fail + if category not in all_settings_categories: + not_valid_categories[visibility_type].append(category) + + for setting in category_settings: + + # Check whether the setting exist in fdmprinter.def.json or not. + # If the setting is defined in the wrong category or does not exist there then the test will fail + if setting not in self.all_settings_keys[category]: + not_valid_setting_by_category[visibility_type].append(setting) + + # Add the 'basic' settings to the list + if visibility_type == "basic": + visible_settings_order.append(setting) + # Check whether the settings are added in right order or not. + # The basic settings should be in advanced, and advanced in expert + for visibility_type in setting_visibility: + + # Skip the basic because it cannot be compared to previous list + if visibility_type == 'basic': + continue + + all_settings_in_this_type = [] + not_valid_setting_by_order[visibility_type] = [] + + item = setting_visibility_items[visibility_type] + for category, category_settings in item.items(): + all_settings_in_this_type.extend(category_settings) + + + for setting in visible_settings_order: + if setting not in all_settings_in_this_type: + not_valid_setting_by_order[visibility_type].append(setting) + + + # If any of the settings is defined not correctly then the test is failed + has_invalid_settings = False + + for type, settings in not_valid_categories.items(): + if len(settings) > 0: + has_invalid_settings = True + print("The following categories are defined incorrectly") + print(" Visibility type : '%s'" % (type)) + print(" Incorrect categories : '%s'" % (settings)) + print() + + + + for type, settings in not_valid_setting_by_category.items(): + if len(settings) > 0: + has_invalid_settings = True + print("The following settings do not exist anymore in fdmprinter definition or in wrong category") + print(" Visibility type : '%s'" % (type)) + print(" Incorrect settings : '%s'" % (settings)) + print() + + + for type, settings in not_valid_setting_by_order.items(): + if len(settings) > 0: + has_invalid_settings = True + print("The following settings are defined in the incorrect order in setting visibility definitions") + print(" Visibility type : '%s'" % (type)) + print(" Incorrect settings : '%s'" % (settings)) + + return has_invalid_settings if __name__ == "__main__": @@ -89,25 +168,13 @@ if __name__ == "__main__": setting_visibility_items = {} for file_path in all_setting_visibility_files: - temp = inspector.getSettingsFromSettingVisibilityFile(all_setting_visibility_files[0]) + temp = inspector.getSettingsFromSettingVisibilityFile(file_path) base_name = os.path.basename(file_path) visibility_type = base_name.split('.')[0] setting_visibility_items[visibility_type] = temp + has_invalid_settings = inspector.validateSettingsVisibility(setting_visibility_items) - inspector.validateSettingsVisibility(setting_visibility_items) - - found_error = False - # Validate settings - # for item in setting_visibility: - - - - - - - - - sys.exit(0 if not found_error else 1) + sys.exit(0 if not has_invalid_settings else 1) From cb49ffa2d283038d7e1a83e20426bccbc36e2632 Mon Sep 17 00:00:00 2001 From: Aleksei S Date: Tue, 18 Sep 2018 17:42:01 +0200 Subject: [PATCH 03/10] Updated the script according to the requested changes CURA-5734 --- scripts/check_setting_visibility.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/check_setting_visibility.py b/scripts/check_setting_visibility.py index 37e489c072..974b922fbd 100644 --- a/scripts/check_setting_visibility.py +++ b/scripts/check_setting_visibility.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# This script check correctness of settings visibility list +# This script checks the correctness of the list of visibility settings # from typing import Dict import os @@ -168,12 +168,12 @@ if __name__ == "__main__": setting_visibility_items = {} for file_path in all_setting_visibility_files: - temp = inspector.getSettingsFromSettingVisibilityFile(file_path) + all_settings_from_visibility_type = inspector.getSettingsFromSettingVisibilityFile(file_path) base_name = os.path.basename(file_path) - visibility_type = base_name.split('.')[0] + visibility_type = base_name.split(".")[0] - setting_visibility_items[visibility_type] = temp + setting_visibility_items[visibility_type] = all_settings_from_visibility_type has_invalid_settings = inspector.validateSettingsVisibility(setting_visibility_items) From eb114a8529764ac8a19b6467a141f329cce68884 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 20 Sep 2018 13:50:06 +0200 Subject: [PATCH 04/10] chmod a+x check_setting_visibility.py --- scripts/check_setting_visibility.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/check_setting_visibility.py diff --git a/scripts/check_setting_visibility.py b/scripts/check_setting_visibility.py old mode 100644 new mode 100755 From 2c571d58865697b32f6cb97085e57424a0869417 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 20 Sep 2018 15:11:41 +0200 Subject: [PATCH 05/10] Rework check_setting_visibility.py --- scripts/check_setting_visibility.py | 296 +++++++++++++++++----------- 1 file changed, 178 insertions(+), 118 deletions(-) diff --git a/scripts/check_setting_visibility.py b/scripts/check_setting_visibility.py index 974b922fbd..41b1dc9095 100755 --- a/scripts/check_setting_visibility.py +++ b/scripts/check_setting_visibility.py @@ -2,179 +2,239 @@ # # This script checks the correctness of the list of visibility settings # -from typing import Dict +import collections +import configparser +import json import os import sys -import json -import configparser -import glob +from typing import Any, Dict, List # Directory where this python file resides SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) -# The order of settings type. If the setting is in basic list then it also should be in expert -setting_visibility = ["basic", "advanced", "expert"] - - +# +# This class +# class SettingVisibilityInspection: - def __init__(self) -> None: - self.all_settings_keys = {} + # The order of settings type. If the setting is in basic list then it also should be in expert + self._setting_visibility_order = ["basic", "advanced", "expert"] - def defineAllCuraSettings(self, fdmprinter_json_path: str) -> None: + # This is dictionary with categories as keys and all setting keys as values. + self.all_settings_keys = {} # type: Dict[str, List[str]] - with open(fdmprinter_json_path) as f: + # Load all Cura setting keys from the given fdmprinter.json file + def loadAllCuraSettingKeys(self, fdmprinter_json_path: str) -> None: + with open(fdmprinter_json_path, "r", encoding = "utf-8") as f: json_data = json.load(f) - self._flattenAllSettings(json_data) - - - def _flattenAllSettings(self, json_file: Dict[str, str]) -> None: - for key, data in json_file["settings"].items(): # top level settings are categories + # Get all settings keys in each category + for key, data in json_data["settings"].items(): # top level settings are categories if "type" in data and data["type"] == "category": - self.all_settings_keys[key] = [] self._flattenSettings(data["children"], key) # actual settings are children of top level category-settings - def _flattenSettings(self, settings: Dict[str, str], category) -> None: + def _flattenSettings(self, settings: Dict[str, str], category: str) -> None: for key, setting in settings.items(): - if "type" in setting and setting["type"] != "category": self.all_settings_keys[category].append(key) if "children" in setting: self._flattenSettings(setting["children"], category) + # Loads the given setting visibility file and returns a dict with categories as keys and a list of setting keys as + # values. + def _loadSettingVisibilityConfigFile(self, file_name: str) -> Dict[str, List[str]]: + with open(file_name, "r", encoding = "utf-8") as f: + parser = configparser.ConfigParser(allow_no_value = True) + parser.read_file(f) - def getSettingsFromSettingVisibilityFile(self, file_path: str): - parser = configparser.ConfigParser(allow_no_value = True) - parser.read([file_path]) - - if not parser.has_option("general", "name") or not parser.has_option("general", "weight"): - raise NotImplementedError("Visibility setting file missing general data") - - settings = {} - for section in parser.sections(): - if section == 'general': + data_dict = {} + for category, option_dict in parser.items(): + if category in (parser.default_section, "general"): continue - if section not in settings: - settings[section] = [] + data_dict[category] = [] + for key in option_dict: + data_dict[category].append(key) - for option in parser[section].keys(): - settings[section].append(option) + return data_dict - return settings + def validateSettingsVisibility(self, setting_visibility_files: Dict[str, str]) -> Dict[str, Dict[str, Any]]: + # First load all setting visibility files into the dict "setting_visibility_dict" in the following structure: + # -> -> + # "basic" -> "info" + setting_visibility_dict = {} # type: Dict[str, Dict[str, List[str]]] + for visibility_name, file_path in setting_visibility_files.items(): + setting_visibility_dict[visibility_name] = self._loadSettingVisibilityConfigFile(file_path) - def validateSettingsVisibility(self, setting_visibility_items: Dict): + # The result is in the format: + # -> dict + # "basic" -> "file_name": "basic.cfg" + # "is_valid": True / False + # "invalid_categories": List[str] + # "invalid_settings": Dict[category -> List[str]] + # "missing_categories_from_previous": List[str] + # "missing_settings_from_previous": Dict[category -> List[str]] + all_result_dict = dict() # type: Dict[str, Dict[str, Any]] - not_valid_categories = {} - not_valid_setting_by_category = {} - not_valid_setting_by_order = {} + previous_result = None + previous_visibility_dict = None + is_all_valid = True + for visibility_name in self._setting_visibility_order: + invalid_categories = [] + invalid_settings = collections.defaultdict(list) - visible_settings_order = [] # This list is used to make sure that the settings are in the correct order. - # basic.cfg -> advanced.cfg -> expert.cfg. Like: if the setting 'layer_height' in 'basic.cfg' then the same setting - # also should be in 'advanced.cfg' + this_visibility_dict = setting_visibility_dict[visibility_name] + # Check if categories and keys exist at all + for category, key_list in this_visibility_dict.items(): + if category not in self.all_settings_keys: + invalid_categories.append(category) + continue # If this category doesn't exist at all, not need to check for details - all_settings_categories = list(self.all_settings_keys.keys()) + for key in key_list: + if key not in self.all_settings_keys[category]: + invalid_settings[category].append(key) - # visibility_type = basic, advanced, expert - for visibility_type in setting_visibility: - item = setting_visibility_items[visibility_type] + is_settings_valid = len(invalid_categories) == 0 and len(invalid_settings) == 0 + file_path = setting_visibility_files[visibility_name] + result_dict = {"file_name": os.path.basename(file_path), + "is_valid": is_settings_valid, + "invalid_categories": invalid_categories, + "invalid_settings": invalid_settings, + "missing_categories_from_previous": list(), + "missing_settings_from_previous": dict(), + } - not_valid_setting_by_category[visibility_type] = [] # this list is for keeping invalid settings. - not_valid_categories[visibility_type] = [] + # If this is not the first item in the list, check if the settings are defined in the previous + # visibility file. + # A visibility with more details SHOULD add more settings. It SHOULD NOT remove any settings defined + # in the less detailed visibility. + if previous_visibility_dict is not None: + missing_categories_from_previous = [] + missing_settings_from_previous = collections.defaultdict(list) - for category, category_settings in item.items(): + for prev_category, prev_key_list in previous_visibility_dict.items(): + # Skip the categories that are invalid + if prev_category in previous_result["invalid_categories"]: + continue + if prev_category not in this_visibility_dict: + missing_categories_from_previous.append(prev_category) + continue - # Validate Category, If category is not defined then the test will fail - if category not in all_settings_categories: - not_valid_categories[visibility_type].append(category) + this_key_list = this_visibility_dict[prev_category] + for key in prev_key_list: + # Skip the settings that are invalid + if key in previous_result["invalid_settings"][prev_category]: + continue - for setting in category_settings: + if key not in this_key_list: + missing_settings_from_previous[prev_category].append(key) - # Check whether the setting exist in fdmprinter.def.json or not. - # If the setting is defined in the wrong category or does not exist there then the test will fail - if setting not in self.all_settings_keys[category]: - not_valid_setting_by_category[visibility_type].append(setting) + result_dict["missing_categories_from_previous"] = missing_categories_from_previous + result_dict["missing_settings_from_previous"] = missing_settings_from_previous + is_settings_valid = len(missing_categories_from_previous) == 0 and len(missing_settings_from_previous) == 0 + result_dict["is_valid"] = result_dict["is_valid"] and is_settings_valid - # Add the 'basic' settings to the list - if visibility_type == "basic": - visible_settings_order.append(setting) + # Update the complete result dict + all_result_dict[visibility_name] = result_dict + previous_result = result_dict + previous_visibility_dict = this_visibility_dict + is_all_valid = is_all_valid and result_dict["is_valid"] - # Check whether the settings are added in right order or not. - # The basic settings should be in advanced, and advanced in expert - for visibility_type in setting_visibility: + all_result_dict["all_results"] = {"is_valid": is_all_valid} - # Skip the basic because it cannot be compared to previous list - if visibility_type == 'basic': + return all_result_dict + + def printResults(self, all_result_dict: Dict[str, Dict[str, Any]]) -> None: + print("") + print("Setting Visibility Check Results:") + + prev_visibility_name = None + for visibility_name in self._setting_visibility_order: + if visibility_name not in all_result_dict: continue - all_settings_in_this_type = [] - not_valid_setting_by_order[visibility_type] = [] + result_dict = all_result_dict[visibility_name] + print("=============================") + result_str = "OK" if result_dict["is_valid"] else "INVALID" + print("[%s] : [%s] : %s" % (visibility_name, result_dict["file_name"], result_str)) - item = setting_visibility_items[visibility_type] - for category, category_settings in item.items(): - all_settings_in_this_type.extend(category_settings) + if result_dict["is_valid"]: + continue + + # Print details of invalid settings + if result_dict["invalid_categories"]: + print("It has the following non-existing CATEGORIES:") + for category in result_dict["invalid_categories"]: + print(" - [%s]" % category) + + if result_dict["invalid_settings"]: + print("") + print("It has the following non-existing SETTINGS:") + for category, key_list in result_dict["invalid_settings"].items(): + for key in key_list: + print(" - [%s / %s]" % (category, key)) + + if prev_visibility_name is not None: + if result_dict["missing_categories_from_previous"]: + print("") + print("The following CATEGORIES are defined in the previous visibility [%s] but not here:" % prev_visibility_name) + for category in result_dict["missing_categories_from_previous"]: + print(" - [%s]" % category) + + if result_dict["missing_settings_from_previous"]: + print("") + print("The following SETTINGS are defined in the previous visibility [%s] but not here:" % prev_visibility_name) + for category, key_list in result_dict["missing_settings_from_previous"].items(): + for key in key_list: + print(" - [%s / %s]" % (category, key)) + + print("") + prev_visibility_name = visibility_name - for setting in visible_settings_order: - if setting not in all_settings_in_this_type: - not_valid_setting_by_order[visibility_type].append(setting) +# +# Returns a dictionary of setting visibility .CFG files in the given search directory. +# The dict has the name of the visibility type as the key (such as "basic", "advanced", "expert"), and +# the actual file path (absolute path). +# +def getAllSettingVisiblityFiles(search_dir: str) -> Dict[str, str]: + visibility_file_dict = dict() + extension = ".cfg" + for file_name in os.listdir(search_dir): + file_path = os.path.join(search_dir, file_name) + + # Only check files that has the .cfg extension + if not os.path.isfile(file_path): + continue + if not file_path.endswith(extension): + continue + + base_filename = os.path.basename(file_name)[:-len(extension)] + visibility_file_dict[base_filename] = file_path + return visibility_file_dict - # If any of the settings is defined not correctly then the test is failed - has_invalid_settings = False +def main() -> None: + setting_visibility_files_dir = os.path.abspath(os.path.join(SCRIPT_DIR, "..", "resources", "setting_visibility")) + fdmprinter_def_path = os.path.abspath(os.path.join(SCRIPT_DIR, "..", "resources", "definitions", "fdmprinter.def.json")) - for type, settings in not_valid_categories.items(): - if len(settings) > 0: - has_invalid_settings = True - print("The following categories are defined incorrectly") - print(" Visibility type : '%s'" % (type)) - print(" Incorrect categories : '%s'" % (settings)) - print() + setting_visibility_files_dict = getAllSettingVisiblityFiles(setting_visibility_files_dir) + print("--- ", setting_visibility_files_dict) + inspector = SettingVisibilityInspection() + inspector.loadAllCuraSettingKeys(fdmprinter_def_path) + check_result = inspector.validateSettingsVisibility(setting_visibility_files_dict) + is_result_valid = not check_result["all_results"]["is_valid"] + inspector.printResults(check_result) - for type, settings in not_valid_setting_by_category.items(): - if len(settings) > 0: - has_invalid_settings = True - print("The following settings do not exist anymore in fdmprinter definition or in wrong category") - print(" Visibility type : '%s'" % (type)) - print(" Incorrect settings : '%s'" % (settings)) - print() - - - for type, settings in not_valid_setting_by_order.items(): - if len(settings) > 0: - has_invalid_settings = True - print("The following settings are defined in the incorrect order in setting visibility definitions") - print(" Visibility type : '%s'" % (type)) - print(" Incorrect settings : '%s'" % (settings)) - - return has_invalid_settings + sys.exit(0 if is_result_valid else 1) if __name__ == "__main__": - - all_setting_visibility_files = glob.glob(os.path.join(os.path.join(SCRIPT_DIR, "..", "resources", "setting_visibility"), '*.cfg')) - fdmprinter_def_path = os.path.join(SCRIPT_DIR, "..", "resources", "definitions", "fdmprinter.def.json") - - inspector = SettingVisibilityInspection() - inspector.defineAllCuraSettings(fdmprinter_def_path) - - setting_visibility_items = {} - for file_path in all_setting_visibility_files: - all_settings_from_visibility_type = inspector.getSettingsFromSettingVisibilityFile(file_path) - - base_name = os.path.basename(file_path) - visibility_type = base_name.split(".")[0] - - setting_visibility_items[visibility_type] = all_settings_from_visibility_type - - has_invalid_settings = inspector.validateSettingsVisibility(setting_visibility_items) - - sys.exit(0 if not has_invalid_settings else 1) + main() From 72b3f9eb2a861ff6037a9ac82b5e3e2566f46909 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 20 Sep 2018 15:12:54 +0200 Subject: [PATCH 06/10] Remove debugging lines --- scripts/check_setting_visibility.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/check_setting_visibility.py b/scripts/check_setting_visibility.py index 41b1dc9095..fde1c2fb81 100755 --- a/scripts/check_setting_visibility.py +++ b/scripts/check_setting_visibility.py @@ -224,7 +224,6 @@ def main() -> None: fdmprinter_def_path = os.path.abspath(os.path.join(SCRIPT_DIR, "..", "resources", "definitions", "fdmprinter.def.json")) setting_visibility_files_dict = getAllSettingVisiblityFiles(setting_visibility_files_dir) - print("--- ", setting_visibility_files_dict) inspector = SettingVisibilityInspection() inspector.loadAllCuraSettingKeys(fdmprinter_def_path) From 884c5dea6733f35f19dcfb13eee0e60ac1f8bcf5 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 20 Sep 2018 15:14:50 +0200 Subject: [PATCH 07/10] Add check_setting_visibility.py to Jenkinsfile --- Jenkinsfile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 8837fdf487..4f755dcae2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,6 +14,7 @@ parallel_nodes(['linux && cura', 'windows && cura']) { catchError { stage('Pre Checks') { if (isUnix()) { + // Check shortcut keys try { sh """ echo 'Check for duplicate shortcut keys in all translation files.' @@ -22,6 +23,16 @@ parallel_nodes(['linux && cura', 'windows && cura']) { } catch(e) { currentBuild.result = "UNSTABLE" } + + // Check setting visibilities + try { + sh """ + echo 'Check for duplicate shortcut keys in all translation files.' + ${env.CURA_ENVIRONMENT_PATH}/master/bin/python3 scripts/check_setting_visibility.py + """ + } catch(e) { + currentBuild.result = "UNSTABLE" + } } } From 0bc91132edf721564e49b7d23b79229f4c807361 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 20 Sep 2018 15:18:58 +0200 Subject: [PATCH 08/10] Fix check_setting_visibility return value --- scripts/check_setting_visibility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_setting_visibility.py b/scripts/check_setting_visibility.py index fde1c2fb81..8fb5d5b293 100755 --- a/scripts/check_setting_visibility.py +++ b/scripts/check_setting_visibility.py @@ -229,7 +229,7 @@ def main() -> None: inspector.loadAllCuraSettingKeys(fdmprinter_def_path) check_result = inspector.validateSettingsVisibility(setting_visibility_files_dict) - is_result_valid = not check_result["all_results"]["is_valid"] + is_result_valid = check_result["all_results"]["is_valid"] inspector.printResults(check_result) sys.exit(0 if is_result_valid else 1) From 2d300ab39539149398716b74a4d2052482215eae Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Thu, 20 Sep 2018 18:34:08 +0200 Subject: [PATCH 09/10] Revert "Fix plugins import in CuraApplication" This reverts commit e87f3d7ca9cf135142bee488f188b9639c8b38fd. --- cura/CuraApplication.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index cdb640c3e2..c7d7fff518 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -82,6 +82,7 @@ from cura.Settings.SettingInheritanceManager import SettingInheritanceManager from cura.Settings.SimpleModeSettingsManager import SimpleModeSettingsManager from cura.Machines.VariantManager import VariantManager +from plugins.SliceInfoPlugin.SliceInfo import SliceInfo from .SingleInstance import SingleInstance from .AutoSave import AutoSave @@ -112,10 +113,6 @@ from cura.ObjectsModel import ObjectsModel from UM.FlameProfiler import pyqtSlot -if TYPE_CHECKING: - from plugins.SliceInfoPlugin.SliceInfo import SliceInfo - - numpy.seterr(all = "ignore") try: From 4bd5d29970f19aa2e038fb7f6e49860ce5a0d725 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Thu, 20 Sep 2018 18:41:30 +0200 Subject: [PATCH 10/10] Don't crash if the plugin is not found (maybe some error while loading). In that case it's better not to show the dialog than crashing. --- cura/CuraApplication.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index c7d7fff518..74c8e805af 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -13,6 +13,7 @@ from PyQt5.QtGui import QColor, QIcon from PyQt5.QtWidgets import QMessageBox from PyQt5.QtQml import qmlRegisterUncreatableType, qmlRegisterSingletonType, qmlRegisterType +from UM.PluginError import PluginNotFoundError from UM.Scene.SceneNode import SceneNode from UM.Scene.Camera import Camera from UM.Math.Vector import Vector @@ -1704,7 +1705,11 @@ class CuraApplication(QtApplication): @pyqtSlot() def showMoreInformationDialogForAnonymousDataCollection(self): - cast(SliceInfo, self._plugin_registry.getPluginObject("SliceInfoPlugin")).showMoreInfoDialog() + try: + slice_info = cast(SliceInfo, self._plugin_registry.getPluginObject("SliceInfoPlugin")) + slice_info.showMoreInfoDialog() + except PluginNotFoundError: + Logger.log("w", "Plugin SliceInfo was not found, so not able to show the info dialog.") def addSidebarCustomMenuItem(self, menu_item: dict) -> None: self._sidebar_custom_menu_items.append(menu_item)