Skip to content

Commit 1e793d3

Browse files
committed
host selected packages (hbchannel & updater) on site
1 parent 5715474 commit 1e793d3

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

pelicanconf.py

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@
8484
('utility', 'Utilities'),
8585
]
8686

87+
# Following packages will have their IPKs downloaded and hosted on the site
88+
HOST_PACKAGES: set[str] = {
89+
'org.webosbrew.hbchannel',
90+
'org.webosbrew.safeupdate'
91+
}
92+
8793
DEFAULT_PAGINATION = 20
8894

8995
# Uncomment following line if you want document-relative URLs when developing

repogen/apidata.py

+29-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import os
55
import urllib.parse
66
from pathlib import Path
7-
from typing import List
7+
from typing import List, Set
88

99
import more_itertools
10+
import requests
1011
from markdown import Markdown
1112

1213
from repogen import pkg_info
@@ -31,10 +32,27 @@ def fix_manifest_url(item: PackageInfo, app_dir: Path):
3132
item['manifestUrl'] = manifest_url[manifest_url.find('/api/apps'):]
3233

3334

34-
def generate(packages: List[PackageInfo], outdir: Path):
35+
def save_ipk(item: PackageInfo, apps_dir: Path, site_url: str):
36+
"""
37+
Save the ipk file to the apps directory, and modify PackageInfo to point to the local file.
38+
"""
39+
manifest = item['manifest']
40+
app_ipk = apps_dir.joinpath(item["id"], 'releases', f'{manifest["ipkHash"]["sha256"]}.ipk')
41+
if not app_ipk.parent.exists():
42+
app_ipk.parent.mkdir(parents=True, exist_ok=True)
43+
# Not likely to happen, but just in case someday we host some ipk files by ourselves directly.
44+
if site_url and manifest['ipkUrl'].startswith(site_url):
45+
return
46+
with requests.get(manifest['ipkUrl'], allow_redirects=True) as resp:
47+
with ensure_open(app_ipk, 'wb') as f:
48+
f.write(resp.content)
49+
manifest['ipkUrl'] = f'{site_url.removesuffix("/")}/{"/".join(app_ipk.parts[-4:])}'
50+
51+
52+
def generate(packages: List[PackageInfo], api_dir: Path, apps_dir: Path = None, host_packages: Set[str] = None):
3553
markdown = Markdown()
3654

37-
appsdir: Path = outdir.joinpath('apps')
55+
appsdir: Path = api_dir.joinpath('apps')
3856
site_url = siteurl()
3957

4058
def package_item(p_info: PackageInfo, in_apps_dir: bool, is_details: bool) -> PackageInfo:
@@ -56,7 +74,7 @@ def package_item(p_info: PackageInfo, in_apps_dir: bool, is_details: bool) -> Pa
5674
max_page = math.ceil(packages_length / ITEMS_PER_PAGE)
5775

5876
def save_page(page: int, items: [PackageInfo]):
59-
json_file = appsdir.joinpath('%d.json' % page) if page > 1 else outdir.joinpath('apps.json')
77+
json_file = appsdir.joinpath('%d.json' % page) if page > 1 else api_dir.joinpath('apps.json')
6078
with ensure_open(json_file, 'w', encoding='utf-8') as pf:
6179
json.dump({
6280
'paging': {
@@ -71,13 +89,16 @@ def save_page(page: int, items: [PackageInfo]):
7189
chunks = more_itertools.chunked(packages, ITEMS_PER_PAGE) if packages else [[]]
7290
for index, chunk in enumerate(chunks):
7391
for item in chunk:
74-
app_dir = appsdir.joinpath(item['id'])
75-
releases_dir = app_dir.joinpath('releases')
76-
fix_manifest_url(item, app_dir)
92+
api_app_dir = appsdir.joinpath(item['id'])
93+
releases_dir = api_app_dir.joinpath('releases')
94+
if host_packages and item['id'] in host_packages:
95+
save_ipk(item, apps_dir, site_url)
96+
fix_manifest_url(item, api_app_dir)
97+
# This will be used by dev-manager-desktop
7798
app_info = releases_dir.joinpath('latest.json')
7899
with ensure_open(app_info, 'w', encoding='utf-8') as f:
79100
json.dump(package_item(item, True, True), f)
80-
desc_html = app_dir.joinpath('full_description.html')
101+
desc_html = api_app_dir.joinpath('full_description.html')
81102
with ensure_open(desc_html, 'w', encoding='utf-8') as f:
82103
f.write(markdown.convert(item['description']))
83104
save_page(index + 1, chunk)

repogen/downloadipk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
except (requests.exceptions.JSONDecodeError, json.decoder.JSONDecodeError) as e:
2121
print(f'Could not parse manifest: {e}')
2222
exit(2)
23-
except (IOError) as e:
23+
except IOError as e:
2424
print(f'Could not open package info file: {e.strerror}')
2525
exit(3)
2626
except ValidationError as e:

repogen/plugin.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def read(self, filename: str):
3030
info['manifest']['iconUri'] = info['iconUri']
3131
metadata = {
3232
'title': info['title'],
33-
'override_save_as': f'apps/{info["id"]}.html',
33+
'override_save_as': f'apps/{info["id"]}/index.html',
3434
'template': 'app',
3535
'status': 'hidden',
3636
'modified': info['lastmodified'],
@@ -93,12 +93,14 @@ def apps_list_href(page):
9393

9494
def add_app_api_data(generator: StaticGenerator):
9595
packages = generator.settings['PACKAGES'].values()
96+
output_path = generator.settings['OUTPUT_PATH']
97+
host_packages = generator.settings.get('HOST_PACKAGES', None)
9698

9799
def pool_list(pool: str):
98100
return list(sorted(filter(lambda pkg: pkg['pool'] == pool, packages), key=lambda pkg: pkg['title'].lower()))
99101

100-
apidata.generate(pool_list('main'), Path(generator.settings['OUTPUT_PATH'], 'api'))
101-
apidata.generate(pool_list('non-free'), Path(generator.settings['OUTPUT_PATH'], 'api', 'non-free'))
102+
apidata.generate(pool_list('main'), Path(output_path, 'api'), Path(output_path, 'apps'), host_packages)
103+
apidata.generate(pool_list('non-free'), Path(output_path, 'api', 'non-free'))
102104

103105

104106
def register():

0 commit comments

Comments
 (0)