Skip to content

Commit

Permalink
Add DownloadPageAPI to the autoupdater to download from HTML web pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Salamandar committed Aug 28, 2024
1 parent 9863a82 commit 9ed6ccc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tools/autoupdate_app_sources/autoupdate_app_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
GithubAPI,
GitlabAPI,
GiteaForgejoAPI,
DownloadPageAPI,
RefType,
) # noqa: E402,E501 pylint: disable=import-error,wrong-import-position
import appslib.logging_sender # noqa: E402 pylint: disable=import-error,wrong-import-position
Expand All @@ -49,6 +50,7 @@
"latest_forgejo_release",
"latest_forgejo_tag",
"latest_forgejo_commit",
"latest_webpage_link",
]


Expand Down Expand Up @@ -466,7 +468,7 @@ def get_latest_version_and_asset(
allow_prereleases = autoupdate.get("allow_prereleases", False)
_, remote_type, revision_type = strategy.split("_")

api: Union[GithubAPI, GitlabAPI, GiteaForgejoAPI]
api: Union[GithubAPI, GitlabAPI, GiteaForgejoAPI, DownloadPageAPI]
if remote_type == "github":
assert upstream and upstream.startswith(
"https://github.com/"
Expand Down Expand Up @@ -575,6 +577,14 @@ def get_latest_version_and_asset(
latest_commit["sha"], self.get_old_ref(infos), RefType.commits
),
)

if remote_type == "webpage" and revision_type == "link":
api = DownloadPageAPI(upstream)
links = api.get_web_page_links()
latest_version_orig, latest_version = self.relevant_versions(list(links.keys()), self.app_id, version_re)
latest_url = links[latest_version_orig]
return latest_version, latest_url, ""

return None

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions tools/autoupdate_app_sources/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ requests
PyGithub
toml
tqdm
beautifulsoup4
lxml
17 changes: 17 additions & 0 deletions tools/autoupdate_app_sources/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from enum import Enum
from typing import Any, Optional

from bs4 import BeautifulSoup
from urllib.parse import urljoin
import requests


Expand Down Expand Up @@ -206,3 +208,18 @@ def changelog_for_ref(self, new_ref: str, old_ref: str, ref_type: RefType) -> st
)
else:
return f"{self.forge_root}/{self.project_path}/releases/tag/{new_ref}"


class DownloadPageAPI:
def __init__(self, upstream: str) -> None:
self.web_page = upstream

def get_web_page_links(self) -> dict[str, str]:
r = requests.get(self.web_page)
r.raise_for_status()
soup = BeautifulSoup(r.text, features="lxml")

return {
link.string: urljoin(self.web_page, link.get("href"))
for link in soup.find_all('a')
}

0 comments on commit 9ed6ccc

Please sign in to comment.