From febb7f1205451546ad543505d2104bd5fdb0d92e Mon Sep 17 00:00:00 2001 From: "j.delarago" Date: Wed, 15 Jun 2022 11:55:53 +0200 Subject: [PATCH 1/5] temu extra logging for debugging --- cura/CuraPackageManager.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index 87a2935d96..ef36e5c777 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -59,10 +59,12 @@ class CuraPackageManager(PackageManager): def isMaterialBundled(self, file_name: str, guid: str): """ Check if there is a bundled material name with file_name and guid """ + Logger.error(f"Paths: {list(Resources.getSecureSearchPaths())}") for path in Resources.getSecureSearchPaths(): # Secure search paths are install directory paths, if a material is in here it must be bundled. paths = [Path(p) for p in glob.glob(path + '/**/*.xml.fdm_material')] + Logger.error(f"Paths: {[(material.name, str(material)) for material in paths]}") for material in paths: if material.name == file_name: with open(str(material), encoding="utf-8") as f: @@ -73,12 +75,14 @@ class CuraPackageManager(PackageManager): f.read(), "GUID") if guid == parsed_guid: # The material we found matches both filename and GUID + Logger.error("MATERIAL IS BUNDLED") return True return False def getMaterialFilePackageId(self, file_name: str, guid: str) -> str: """Get the id of the installed material package that contains file_name""" + Logger.error(f'Material package search paths {[f for f in os.scandir(self._installation_dirs_dict["materials"]) if f.is_dir()]}') for material_package in [f for f in os.scandir(self._installation_dirs_dict["materials"]) if f.is_dir()]: package_id = material_package.name @@ -87,7 +91,7 @@ class CuraPackageManager(PackageManager): # File with the name we are looking for is not in this directory continue - with open(root + "/" + file_name, encoding="utf-8") as f: + with open(os.path.join(root, file_name), encoding="utf-8") as f: # Make sure the file we found has the same guid as our material # Parsing this xml would be better but the namespace is needed to search it. parsed_guid = PluginRegistry.getInstance().getPluginObject("XmlMaterialProfile").getMetadataFromSerialized( From f7bc55db15d6d567136c8a631c223a59e545d2e1 Mon Sep 17 00:00:00 2001 From: "j.delarago" Date: Wed, 15 Jun 2022 12:53:42 +0200 Subject: [PATCH 2/5] Revert "temu extra logging for debugging" This reverts commit febb7f1205451546ad543505d2104bd5fdb0d92e. --- cura/CuraPackageManager.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index ef36e5c777..87a2935d96 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -59,12 +59,10 @@ class CuraPackageManager(PackageManager): def isMaterialBundled(self, file_name: str, guid: str): """ Check if there is a bundled material name with file_name and guid """ - Logger.error(f"Paths: {list(Resources.getSecureSearchPaths())}") for path in Resources.getSecureSearchPaths(): # Secure search paths are install directory paths, if a material is in here it must be bundled. paths = [Path(p) for p in glob.glob(path + '/**/*.xml.fdm_material')] - Logger.error(f"Paths: {[(material.name, str(material)) for material in paths]}") for material in paths: if material.name == file_name: with open(str(material), encoding="utf-8") as f: @@ -75,14 +73,12 @@ class CuraPackageManager(PackageManager): f.read(), "GUID") if guid == parsed_guid: # The material we found matches both filename and GUID - Logger.error("MATERIAL IS BUNDLED") return True return False def getMaterialFilePackageId(self, file_name: str, guid: str) -> str: """Get the id of the installed material package that contains file_name""" - Logger.error(f'Material package search paths {[f for f in os.scandir(self._installation_dirs_dict["materials"]) if f.is_dir()]}') for material_package in [f for f in os.scandir(self._installation_dirs_dict["materials"]) if f.is_dir()]: package_id = material_package.name @@ -91,7 +87,7 @@ class CuraPackageManager(PackageManager): # File with the name we are looking for is not in this directory continue - with open(os.path.join(root, file_name), encoding="utf-8") as f: + with open(root + "/" + file_name, encoding="utf-8") as f: # Make sure the file we found has the same guid as our material # Parsing this xml would be better but the namespace is needed to search it. parsed_guid = PluginRegistry.getInstance().getPluginObject("XmlMaterialProfile").getMetadataFromSerialized( From 5d0e4238d595056f4f7f51af0a736d17afa94611 Mon Sep 17 00:00:00 2001 From: "j.delarago" Date: Wed, 15 Jun 2022 13:26:29 +0200 Subject: [PATCH 3/5] Use os.path.join instead of appending a "/" since this is os specific. Remove possible bad conversion to str for path. --- cura/CuraPackageManager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index 87a2935d96..12a77fd234 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -65,7 +65,7 @@ class CuraPackageManager(PackageManager): paths = [Path(p) for p in glob.glob(path + '/**/*.xml.fdm_material')] for material in paths: if material.name == file_name: - with open(str(material), encoding="utf-8") as f: + with open(material, encoding="utf-8") as f: # Make sure the file we found has the same guid as our material # Parsing this xml would be better but the namespace is needed to search it. parsed_guid = PluginRegistry.getInstance().getPluginObject( @@ -87,7 +87,7 @@ class CuraPackageManager(PackageManager): # File with the name we are looking for is not in this directory continue - with open(root + "/" + file_name, encoding="utf-8") as f: + with open(os.path.join(root, file_name), encoding="utf-8") as f: # Make sure the file we found has the same guid as our material # Parsing this xml would be better but the namespace is needed to search it. parsed_guid = PluginRegistry.getInstance().getPluginObject("XmlMaterialProfile").getMetadataFromSerialized( From 4e80d170d188863b1d8116e6d5d8470f721565aa Mon Sep 17 00:00:00 2001 From: "j.delarago" Date: Wed, 15 Jun 2022 14:09:05 +0200 Subject: [PATCH 4/5] Add logs for debugging CURA-8610 --- cura/CuraPackageManager.py | 8 ++++++-- plugins/3MFWriter/ThreeMFWriter.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index 12a77fd234..fbede6d08b 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -63,8 +63,10 @@ class CuraPackageManager(PackageManager): # Secure search paths are install directory paths, if a material is in here it must be bundled. paths = [Path(p) for p in glob.glob(path + '/**/*.xml.fdm_material')] + Logger.info(f"All bundled Materials Found: {[str(path) for path in paths]}") for material in paths: if material.name == file_name: + Logger.info(f"Found bundled material: {material.name}. Located in path: {str(material)}") with open(material, encoding="utf-8") as f: # Make sure the file we found has the same guid as our material # Parsing this xml would be better but the namespace is needed to search it. @@ -79,19 +81,21 @@ class CuraPackageManager(PackageManager): def getMaterialFilePackageId(self, file_name: str, guid: str) -> str: """Get the id of the installed material package that contains file_name""" + Logger.info(f'Searching paths for package: {[f for f in os.scandir(self._installation_dirs_dict["materials"]) if f.is_dir()]}') for material_package in [f for f in os.scandir(self._installation_dirs_dict["materials"]) if f.is_dir()]: package_id = material_package.name - for root, _, file_names in os.walk(material_package.path): if file_name not in file_names: # File with the name we are looking for is not in this directory continue - + Logger.info(f"Found file: {file_name}") + Logger.info(f"Attempting to open {os.path.join(root, file_name)}") with open(os.path.join(root, file_name), encoding="utf-8") as f: # Make sure the file we found has the same guid as our material # Parsing this xml would be better but the namespace is needed to search it. parsed_guid = PluginRegistry.getInstance().getPluginObject("XmlMaterialProfile").getMetadataFromSerialized( f.read(), "GUID") + if guid == parsed_guid: return package_id diff --git a/plugins/3MFWriter/ThreeMFWriter.py b/plugins/3MFWriter/ThreeMFWriter.py index 83007177c3..081493cd56 100644 --- a/plugins/3MFWriter/ThreeMFWriter.py +++ b/plugins/3MFWriter/ThreeMFWriter.py @@ -10,6 +10,7 @@ from UM.Logger import Logger from UM.Math.Matrix import Matrix from UM.Application import Application from UM.Message import Message +from UM.Resources import Resources from UM.Scene.SceneNode import SceneNode from cura.CuraApplication import CuraApplication @@ -276,6 +277,8 @@ class ThreeMFWriter(MeshWriter): if not package_data: # We failed to find the package for this material + + Logger.info(f"Secure resource paths searched for: {Resources.getSecureSearchPaths()}") message = Message(catalog.i18nc("@error:material", "It was not possible to store material package information in project file: {material}. This project may not open correctly on other systems.".format(material=extruder.getName())), title=catalog.i18nc("@info:title", "Failed to save material package information"), From 8c2ac9f21ebadd05d04a778027c44da343c6a342 Mon Sep 17 00:00:00 2001 From: "j.delarago" Date: Wed, 15 Jun 2022 15:47:17 +0200 Subject: [PATCH 5/5] Remove excessive logs, make path search recursive for materials. CURA-8610 --- cura/CuraPackageManager.py | 8 +++----- plugins/3MFWriter/ThreeMFWriter.py | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index fbede6d08b..da71021d1f 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -62,8 +62,7 @@ class CuraPackageManager(PackageManager): for path in Resources.getSecureSearchPaths(): # Secure search paths are install directory paths, if a material is in here it must be bundled. - paths = [Path(p) for p in glob.glob(path + '/**/*.xml.fdm_material')] - Logger.info(f"All bundled Materials Found: {[str(path) for path in paths]}") + paths = [Path(p) for p in glob.glob(path + '/**/*.xml.fdm_material', recursive=True)] for material in paths: if material.name == file_name: Logger.info(f"Found bundled material: {material.name}. Located in path: {str(material)}") @@ -81,15 +80,14 @@ class CuraPackageManager(PackageManager): def getMaterialFilePackageId(self, file_name: str, guid: str) -> str: """Get the id of the installed material package that contains file_name""" - Logger.info(f'Searching paths for package: {[f for f in os.scandir(self._installation_dirs_dict["materials"]) if f.is_dir()]}') for material_package in [f for f in os.scandir(self._installation_dirs_dict["materials"]) if f.is_dir()]: package_id = material_package.name + for root, _, file_names in os.walk(material_package.path): if file_name not in file_names: # File with the name we are looking for is not in this directory continue - Logger.info(f"Found file: {file_name}") - Logger.info(f"Attempting to open {os.path.join(root, file_name)}") + with open(os.path.join(root, file_name), encoding="utf-8") as f: # Make sure the file we found has the same guid as our material # Parsing this xml would be better but the namespace is needed to search it. diff --git a/plugins/3MFWriter/ThreeMFWriter.py b/plugins/3MFWriter/ThreeMFWriter.py index 081493cd56..d17218c578 100644 --- a/plugins/3MFWriter/ThreeMFWriter.py +++ b/plugins/3MFWriter/ThreeMFWriter.py @@ -278,7 +278,6 @@ class ThreeMFWriter(MeshWriter): if not package_data: # We failed to find the package for this material - Logger.info(f"Secure resource paths searched for: {Resources.getSecureSearchPaths()}") message = Message(catalog.i18nc("@error:material", "It was not possible to store material package information in project file: {material}. This project may not open correctly on other systems.".format(material=extruder.getName())), title=catalog.i18nc("@info:title", "Failed to save material package information"),