diff --git a/AddonCatalogCacheCreator.py b/AddonCatalogCacheCreator.py index b663aee..615e638 100644 --- a/AddonCatalogCacheCreator.py +++ b/AddonCatalogCacheCreator.py @@ -266,7 +266,7 @@ def generate_cache_entry( path_to_package_xml = self.find_file("package.xml", addon_id, index, catalog_entry) cache_entry = None if path_to_package_xml and os.path.exists(path_to_package_xml): - cache_entry = self.generate_cache_entry_from_package_xml(path_to_package_xml) + cache_entry = self.generate_cache_entry_from_package_xml(addon_id, path_to_package_xml) path_to_requirements = self.find_file("requirements.txt", addon_id, index, catalog_entry) if path_to_requirements and os.path.exists(path_to_requirements): @@ -300,7 +300,7 @@ def generate_cache_entry( return cache_entry def generate_cache_entry_from_package_xml( - self, path_to_package_xml: str + self, addon_id: str, path_to_package_xml: str ) -> Optional[AddonCatalog.CatalogEntryMetadata]: cache_entry = AddonCatalog.CatalogEntryMetadata() with open(path_to_package_xml, "r", encoding="utf-8") as f: @@ -317,52 +317,60 @@ def generate_cache_entry_from_package_xml( return None relative_icon_path = self.get_icon_from_metadata(metadata) - if relative_icon_path is not None: - absolute_icon_path = os.path.join( - os.path.dirname(path_to_package_xml), relative_icon_path - ) - if os.path.exists(absolute_icon_path): - icon_data_is_good = True - with open(absolute_icon_path, "rb") as f: + if relative_icon_path is None: + return cache_entry + + absolute_icon_path = os.path.join(os.path.dirname(path_to_package_xml), relative_icon_path) + if not os.path.exists(absolute_icon_path): + self.icon_errors[metadata.name] = {"bad_icon_path": relative_icon_path} + print(f"ERROR: Could not find icon file {absolute_icon_path}") + return cache_entry + + icon_data = None + with open(absolute_icon_path, "rb") as f: + try: + icon_data = f.read() + except IOError as e: + print(f"ERROR: IO Error while reading icon file {absolute_icon_path}") + print(e) + except Exception as e: + print(f"ERROR: Unknown error while reading icon file {absolute_icon_path}") + print(e) + + if icon_data is not None: + if absolute_icon_path.lower().endswith(".svg"): + try: + if not icon_utils.is_svg_bytes(icon_data): + self.icon_errors[metadata.name] = { + "valid_icon_path": relative_icon_path, + "error_message": "SVG file does not have valid XML header", + } + icon_data = None + except icon_utils.BadIconData as e: + self.icon_errors[metadata.name] = { + "valid_icon_path": relative_icon_path, + "error_message": str(e), + } icon_data = None - try: - icon_data = f.read() - except IOError as e: - print(f"ERROR: IO Error while reading icon file {absolute_icon_path}") - print(e) - icon_data_is_good = False - except Exception as e: - print(f"ERROR: Unknown error while reading icon file {absolute_icon_path}") - print(e) - icon_data_is_good = False - if icon_data is not None: - if absolute_icon_path.lower().endswith(".svg"): - try: - if not icon_utils.is_svg_bytes(icon_data): - self.icon_errors[metadata.name] = { - "valid_icon_path": relative_icon_path, - "error_message": "SVG file does not have valid XML header", - } - icon_data_is_good = False - except icon_utils.BadIconData as e: - self.icon_errors[metadata.name] = { - "valid_icon_path": relative_icon_path, - "error_message": str(e), - } - icon_data_is_good = False - elif absolute_icon_path.lower().endswith(".png"): - if icon_utils.png_has_duplicate_iccp(icon_data): - self.icon_errors[metadata.name] = { - "valid_icon_path": relative_icon_path, - "error_message": "PNG data has duplicate iCCP chunk", - } - icon_data_is_good = False - - if icon_data_is_good: - cache_entry.icon_data = base64.b64encode(icon_data).decode("utf-8") - else: - self.icon_errors[metadata.name] = {"bad_icon_path": relative_icon_path} - print(f"ERROR: Could not find icon file {absolute_icon_path}") + elif absolute_icon_path.lower().endswith(".png"): + if icon_utils.png_has_duplicate_iccp(icon_data): + self.icon_errors[metadata.name] = { + "valid_icon_path": relative_icon_path, + "error_message": "PNG data has duplicate iCCP chunk", + } + icon_data = None + + if icon_data is not None: + base_path = os.path.dirname(os.path.realpath(__file__)) + svg_name = addon_id + "-" + hashlib.sha1(icon_data).hexdigest()[:8] + ".svg" + path = os.path.join(base_path, "IconAliases", svg_name) + if os.path.exists(path): + with open(path, "rb") as f: + icon_data = f.read() + if len(icon_data) > 10000: + print(f'WARNING: icon_data is long, {len(icon_data):,} bytes. Add "{svg_name}"') + cache_entry.icon_data = base64.b64encode(icon_data).decode("utf-8") + return cache_entry def create_local_copy_of_single_addon_with_git( diff --git a/IconAliases/AIGenFurniture-e5d2e146.svg b/IconAliases/AIGenFurniture-e5d2e146.svg new file mode 100644 index 0000000..502dc42 --- /dev/null +++ b/IconAliases/AIGenFurniture-e5d2e146.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/Assembly3-139af500.svg b/IconAliases/Assembly3-139af500.svg new file mode 100644 index 0000000..8b357fa --- /dev/null +++ b/IconAliases/Assembly3-139af500.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/BillOfMaterials-08c04065.svg b/IconAliases/BillOfMaterials-08c04065.svg new file mode 100644 index 0000000..afb23ff --- /dev/null +++ b/IconAliases/BillOfMaterials-08c04065.svg @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/Cubinets-c7d1e95b.svg b/IconAliases/Cubinets-c7d1e95b.svg new file mode 100644 index 0000000..8155ba8 --- /dev/null +++ b/IconAliases/Cubinets-c7d1e95b.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/DFM-557ecf6f.svg b/IconAliases/DFM-557ecf6f.svg new file mode 100644 index 0000000..8f8c458 --- /dev/null +++ b/IconAliases/DFM-557ecf6f.svg @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/DesignSPHysics-4e83d58b.svg b/IconAliases/DesignSPHysics-4e83d58b.svg new file mode 100644 index 0000000..5152f4c --- /dev/null +++ b/IconAliases/DesignSPHysics-4e83d58b.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/Detessellate-ce7a7cf7.svg b/IconAliases/Detessellate-ce7a7cf7.svg new file mode 100644 index 0000000..2c575ab --- /dev/null +++ b/IconAliases/Detessellate-ce7a7cf7.svg @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/EM-3a2d1d01.svg b/IconAliases/EM-3a2d1d01.svg new file mode 100644 index 0000000..ee0a454 --- /dev/null +++ b/IconAliases/EM-3a2d1d01.svg @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/EasyProfileFrame-249ff536.svg b/IconAliases/EasyProfileFrame-249ff536.svg new file mode 100644 index 0000000..5958e98 --- /dev/null +++ b/IconAliases/EasyProfileFrame-249ff536.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/IconAliases/FreeGrid-92890ab7.svg b/IconAliases/FreeGrid-92890ab7.svg new file mode 100644 index 0000000..eda4f96 --- /dev/null +++ b/IconAliases/FreeGrid-92890ab7.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/IconAliases/Freecad-Built-in-themes-beta-a7b3dad5.svg b/IconAliases/Freecad-Built-in-themes-beta-a7b3dad5.svg new file mode 100644 index 0000000..e97a4b9 --- /dev/null +++ b/IconAliases/Freecad-Built-in-themes-beta-a7b3dad5.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/MOOC-62b8f18a.svg b/IconAliases/MOOC-62b8f18a.svg new file mode 100644 index 0000000..a9016d7 --- /dev/null +++ b/IconAliases/MOOC-62b8f18a.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/IconAliases/Machines-7bd6be2a.svg b/IconAliases/Machines-7bd6be2a.svg new file mode 100644 index 0000000..88837d0 --- /dev/null +++ b/IconAliases/Machines-7bd6be2a.svg @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/MakerWorkbench-e11e1a1b.svg b/IconAliases/MakerWorkbench-e11e1a1b.svg new file mode 100644 index 0000000..339f435 --- /dev/null +++ b/IconAliases/MakerWorkbench-e11e1a1b.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/IconAliases/NikraDAP-991b96b7.svg b/IconAliases/NikraDAP-991b96b7.svg new file mode 100644 index 0000000..3ee7408 --- /dev/null +++ b/IconAliases/NikraDAP-991b96b7.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/IconAliases/Ondsel-Lens-9595372d.svg b/IconAliases/Ondsel-Lens-9595372d.svg new file mode 100644 index 0000000..7335de7 --- /dev/null +++ b/IconAliases/Ondsel-Lens-9595372d.svg @@ -0,0 +1,3 @@ + + + diff --git a/IconAliases/PieMenu-811dbfa2.svg b/IconAliases/PieMenu-811dbfa2.svg new file mode 100644 index 0000000..31ae409 --- /dev/null +++ b/IconAliases/PieMenu-811dbfa2.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/Reinforcement-46873d9f.svg b/IconAliases/Reinforcement-46873d9f.svg new file mode 100644 index 0000000..826e9fa --- /dev/null +++ b/IconAliases/Reinforcement-46873d9f.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/Road-ff13f8b3.svg b/IconAliases/Road-ff13f8b3.svg new file mode 100644 index 0000000..46ca4e8 --- /dev/null +++ b/IconAliases/Road-ff13f8b3.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/IconAliases/TitleBlock-bc876961.svg b/IconAliases/TitleBlock-bc876961.svg new file mode 100644 index 0000000..77b86dc --- /dev/null +++ b/IconAliases/TitleBlock-bc876961.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/WebTools-95d3c71b.svg b/IconAliases/WebTools-95d3c71b.svg new file mode 100644 index 0000000..df7c9ad --- /dev/null +++ b/IconAliases/WebTools-95d3c71b.svg @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/boltsfc-0cd39929.svg b/IconAliases/boltsfc-0cd39929.svg new file mode 100644 index 0000000..4508d4e --- /dev/null +++ b/IconAliases/boltsfc-0cd39929.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/IconAliases/frame-4f6a2a3e.svg b/IconAliases/frame-4f6a2a3e.svg new file mode 100644 index 0000000..8f2c43c --- /dev/null +++ b/IconAliases/frame-4f6a2a3e.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/IconAliases/freecad-xr-workbench-05cd4961.svg b/IconAliases/freecad-xr-workbench-05cd4961.svg new file mode 100644 index 0000000..368c065 --- /dev/null +++ b/IconAliases/freecad-xr-workbench-05cd4961.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/IconAliases/freecad.gears-5c1cf364.svg b/IconAliases/freecad.gears-5c1cf364.svg new file mode 100644 index 0000000..7bccd83 --- /dev/null +++ b/IconAliases/freecad.gears-5c1cf364.svg @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IconAliases/freecad.optics_design_workbench-d74baf9d.svg b/IconAliases/freecad.optics_design_workbench-d74baf9d.svg new file mode 100644 index 0000000..39d81e6 --- /dev/null +++ b/IconAliases/freecad.optics_design_workbench-d74baf9d.svg @@ -0,0 +1,3 @@ + + + diff --git a/IconAliases/woodworking-c448e07d.svg b/IconAliases/woodworking-c448e07d.svg new file mode 100644 index 0000000..3927801 --- /dev/null +++ b/IconAliases/woodworking-c448e07d.svg @@ -0,0 +1,9 @@ + + + + + + + + +