Skip to content

Commit

Permalink
Adjust plugin filename scan for better performance (#3514)
Browse files Browse the repository at this point in the history
* Adjust plugin filename scan for better performance

* reorder

* lint

* Update custom_components/hacs/repositories/plugin.py

Co-authored-by: J. Nick Koston <[email protected]>

* Update custom_components/hacs/repositories/plugin.py

Co-authored-by: J. Nick Koston <[email protected]>

---------

Co-authored-by: J. Nick Koston <[email protected]>
  • Loading branch information
ludeeus and bdraco authored May 23, 2024
1 parent 9ad1e76 commit 69e197c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions custom_components/hacs/repositories/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ async def get_package_content(self):

def update_filenames(self) -> None:
"""Get the filename to target."""
# Handler for plug requirement 3
if self.repository_manifest.filename:
valid_filenames = (self.repository_manifest.filename,)
content_in_root = self.repository_manifest.content_in_root
if specific_filename := self.repository_manifest.filename:
valid_filenames = (specific_filename,)
else:
valid_filenames = (
f"{self.data.name.replace('lovelace-', '')}.js",
Expand All @@ -110,7 +110,7 @@ def update_filenames(self) -> None:
f"{self.data.name}-bundle.js",
)

if not self.repository_manifest.content_in_root:
if not content_in_root:
if self.releases.objects:
release = self.releases.objects[0]
if release.assets:
Expand All @@ -124,11 +124,13 @@ def update_filenames(self) -> None:
self.content.path.remote = "release"
return

for location in ("",) if self.repository_manifest.content_in_root else ("dist", ""):
for filename in valid_filenames:
if f"{location+'/' if location else ''}{filename}" in [
x.full_path for x in self.tree
]:
self.data.file_name = filename.split("/")[-1]
self.content.path.remote = location
break
all_paths = {x.full_path for x in self.tree}
for filename in valid_filenames:
if filename in all_paths:
self.data.file_name = filename
self.content.path.remote = ""
return
if not content_in_root and f"dist/{filename}" in all_paths:
self.data.file_name = filename.split("/")[-1]
self.content.path.remote = "dist"
return

0 comments on commit 69e197c

Please sign in to comment.