diff options
author | j.delarago <joeydelarago@gmail.com> | 2022-05-30 18:29:59 +0300 |
---|---|---|
committer | j.delarago <joeydelarago@gmail.com> | 2022-05-30 18:29:59 +0300 |
commit | 21d59e93492dc66198312bdd8dd17d91bc44d252 (patch) | |
tree | f5544f4323eebfd3423d068d9253d5574d26ffa5 /cura/CuraPackageManager.py | |
parent | 596c24657d39804c8bc94e6e8f99436115d7e411 (diff) |
Write active material metadata to ufp when saving.CURA-8610_save_package_metadata
Add function to fetch package_id using only information from XmlMaterialProfile material container.
The only piece of information associating the material container and the package together is the file_name. To find the package that owns a material we have to search each of the material package paths.
It would be great to find a cleaner solution (preferable one that doesn't require invalidating the cached containers).
CURA-8610
Diffstat (limited to 'cura/CuraPackageManager.py')
-rw-r--r-- | cura/CuraPackageManager.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index 17d6832ac6..b23422fbbd 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -1,5 +1,6 @@ # Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +import os from typing import Any, cast, Dict, List, Set, Tuple, TYPE_CHECKING, Optional @@ -51,6 +52,25 @@ class CuraPackageManager(PackageManager): super().initialize() + def getMaterialFilePackageId(self, file_name: str, guid: str) -> str: + """Get the id of the material package that contains file_name""" + 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 + + 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. + if guid in f.read(): + return package_id + continue + + + def getMachinesUsingPackage(self, package_id: str) -> Tuple[List[Tuple[GlobalStack, str, str]], List[Tuple[GlobalStack, str, str]]]: """Returns a list of where the package is used |