Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 55 additions & 47 deletions AddonCatalogCacheCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand Down
30 changes: 30 additions & 0 deletions IconAliases/AIGenFurniture-e5d2e146.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions IconAliases/Assembly3-139af500.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions IconAliases/BillOfMaterials-08c04065.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions IconAliases/Cubinets-c7d1e95b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions IconAliases/DFM-557ecf6f.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading