diff --git a/Dockerfile b/Dockerfile index b9dab27..f7af149 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ FROM registry.altlinux.org/alt/python:p10 RUN apt-get update && apt-get install -y \ - eepm \ wget \ apt-repo-tools \ alien \ - pip + pip && \ + wget -O- https://eepm.ru/epm.sh | bash /dev/stdin ei # && rm -rf /var/lib/apt/lists/* COPY requirements.txt . diff --git a/autorepacked/base_provider.py b/autorepacked/common_providers/base_provider.py similarity index 100% rename from autorepacked/base_provider.py rename to autorepacked/common_providers/base_provider.py diff --git a/autorepacked/common_providers/github_releases_provider.py b/autorepacked/common_providers/github_releases_provider.py new file mode 100644 index 0000000..9f91bcc --- /dev/null +++ b/autorepacked/common_providers/github_releases_provider.py @@ -0,0 +1,39 @@ +import re + +from autorepacked import utils +from autorepacked.common_providers.base_provider import BaseProvider + + +class GithubReleasesProvider(BaseProvider): + _repo = '' + + def _last_release_url(self): + return utils.run([ + 'epm', + '--silent', + 'tool', + 'eget', + '--get-real-url', + f'https://github.com/{self._repo}/releases/latest' + ]) + + def _last_tag_name(self): + return self.get_version() + + def _get_release_filename(self): + return '' + + def get_version(self): + url = self._last_release_url() + + pattern = r'\d+\.\d+\.\d+' + match = re.search(pattern, url) + if match: + return match.group() + else: + return "not found" + + def get_download_url(self): + return (f"https://github.com/" + f"{self._repo}/releases/download/" + f"{self._last_tag_name()}/{self._get_release_filename()}") diff --git a/autorepacked/main.py b/autorepacked/main.py index 5739504..6b08db0 100644 --- a/autorepacked/main.py +++ b/autorepacked/main.py @@ -9,7 +9,7 @@ import uvicorn from fastapi_utils.tasks import repeat_every from autorepacked import utils -from autorepacked.base_provider import BaseProvider +from autorepacked.common_providers.base_provider import BaseProvider from autorepacked.config import Config @@ -22,6 +22,13 @@ def create_repo(config: Config): ]) +def update_epm(): + utils.run([ + 'epm', + 'ei' + ]) + + @asynccontextmanager async def lifespan(app: FastAPI): await update_repeat() @@ -51,6 +58,8 @@ def update(): update_task_started = False return + update_epm() + providers_path = os.path.join(os.getcwd(), 'autorepacked/providers') modules = os.listdir(providers_path) diff --git a/autorepacked/providers/code/__init__.py b/autorepacked/providers/code/__init__.py index 2abb9fd..3e8b3c8 100644 --- a/autorepacked/providers/code/__init__.py +++ b/autorepacked/providers/code/__init__.py @@ -1,4 +1,4 @@ -from autorepacked.base_provider import BaseProvider +from autorepacked.common_providers.base_provider import BaseProvider class CodeProvider(BaseProvider): diff --git a/autorepacked/providers/discord/__init__.py b/autorepacked/providers/discord/__init__.py index 3485a68..77e7792 100644 --- a/autorepacked/providers/discord/__init__.py +++ b/autorepacked/providers/discord/__init__.py @@ -1,4 +1,4 @@ -from autorepacked.base_provider import BaseProvider +from autorepacked.common_providers.base_provider import BaseProvider class DiscordProvider(BaseProvider): diff --git a/autorepacked/providers/rustdesk/__init__.py b/autorepacked/providers/rustdesk/__init__.py index 693538d..3d7e0ae 100644 --- a/autorepacked/providers/rustdesk/__init__.py +++ b/autorepacked/providers/rustdesk/__init__.py @@ -1,30 +1,13 @@ -import subprocess - -from autorepacked.base_provider import BaseProvider +from autorepacked.common_providers.github_releases_provider import GithubReleasesProvider -class RustdeskProvider(BaseProvider): +class RustdeskProvider(GithubReleasesProvider): _name = 'rustdesk' - _release_url = 'https://github.com/rustdesk/rustdesk/releases' - _release_file = '[0-9]/rustdesk-[0-9].[0-9].[0-9].deb' - def get_download_url(self): - url = subprocess.run( - args=[ - 'epm', - '--silent', - 'tool', - 'eget', - '--list', - '--latest', - '--get-real-url', - self._release_url, - self._release_file, - ], - stdout=subprocess.PIPE - ).stdout.decode('utf-8') + _repo = 'rustdesk/rustdesk' - return url + def _get_release_filename(self): + return f'rustdesk-{self.get_version()}-x86_64.deb' def get_provider(config): diff --git a/autorepacked/providers/trezor_suite/__init__.py b/autorepacked/providers/trezor_suite/__init__.py new file mode 100644 index 0000000..4027bd1 --- /dev/null +++ b/autorepacked/providers/trezor_suite/__init__.py @@ -0,0 +1,17 @@ +from autorepacked.common_providers.github_releases_provider import GithubReleasesProvider + + +class TrezorSuiteProvider(GithubReleasesProvider): + _name = 'Trezor-Suite' + + _repo = 'trezor/trezor-suite' + + def _last_tag_name(self): + return f'v{self.get_version()}' + + def _get_release_filename(self): + return f'Trezor-Suite-{self.get_version()}-linux-x86_64.AppImage' + + +def get_provider(config): + return TrezorSuiteProvider(config)