Skip to content

Commit

Permalink
logo: download from GH
Browse files Browse the repository at this point in the history
Avoid to keep double copy of the same file.
Local copy still has the precedence.
  • Loading branch information
gsanchietti committed May 10, 2023
1 parent f28af71 commit 75de903
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions createrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
# if a file is not present, download from git repository:
# assume the source package is hosted on GithHub under NethServer organization
if not os.path.isfile(metadata_file):
print(f'Downloading metadata for {metadata["name"]}')
url = f'https://raw.githubusercontent.com/NethServer/ns8-{metadata["name"]}/main/ui/public/metadata.json'
res = urllib.request.urlopen(urllib.request.Request(url))
with open(metadata_file, 'wb') as metadata_fpw:
Expand All @@ -90,11 +91,20 @@
# merge defaults and JSON file, the latter one has precedence
metadata = {**metadata, **json.load(metadata_fp)}

# add logo if the file is present and it's a PNG
# download logo if not present
# add it only if it's a PNG
logo = os.path.join(entry_name, "logo.png")
if os.path.isfile(logo):
if imghdr.what(logo) == "png":
metadata["logo"] = "logo.png"
if not os.path.isfile(logo):
print(f'Downloading logo for {metadata["name"]}')
url = f'https://raw.githubusercontent.com/NethServer/ns8-{metadata["name"]}/main/ui/src/assets/module_default_logo.png'
try:
res = urllib.request.urlopen(urllib.request.Request(url))
with open(logo, 'wb') as logo_fpw:
logo_fpw.write(res.read())
if imghdr.what(logo) == "png":
metadata["logo"] = "logo.png"
except:
pass

# add screenshots if pngs are available inside the screenshots directory
screenshot_dirs = os.path.join(entry_name, "screenshots")
Expand Down

0 comments on commit 75de903

Please sign in to comment.