From 85cda3e705b06032c69ddf7fffe9be5621c27434 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Wed, 17 Jan 2024 15:36:11 +0300 Subject: [PATCH] wip --- Dockerfile | 1 - .../common_providers/base_provider.py | 37 +++++++++---------- .../github_releases_provider.py | 6 +-- .../common_providers/snap_provider.py | 35 ++++++++++++++++++ autorepacked/main.py | 26 ++++++------- .../providers/singularityapp/__init__.py | 12 ++++++ autorepacked/utils.py | 9 +++++ 7 files changed, 87 insertions(+), 39 deletions(-) create mode 100644 autorepacked/common_providers/snap_provider.py create mode 100644 autorepacked/providers/singularityapp/__init__.py diff --git a/Dockerfile b/Dockerfile index f7af149..9a7a38d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,6 @@ RUN apt-get update && apt-get install -y \ alien \ pip && \ wget -O- https://eepm.ru/epm.sh | bash /dev/stdin ei -# && rm -rf /var/lib/apt/lists/* COPY requirements.txt . RUN pip --no-cache-dir install -r requirements.txt diff --git a/autorepacked/common_providers/base_provider.py b/autorepacked/common_providers/base_provider.py index ffddd56..1b42c7d 100644 --- a/autorepacked/common_providers/base_provider.py +++ b/autorepacked/common_providers/base_provider.py @@ -13,6 +13,8 @@ def _get_file(directory): class BaseProvider: + disabled = False + def __init__(self, config): self.config = config @@ -23,11 +25,7 @@ class BaseProvider: return self._name def get_version(self): - url = utils.run([ - 'epm', - '--silent', - 'tool', - 'eget', + url = utils.eget([ '--get-real-url', self.get_download_url(), ]) @@ -42,24 +40,27 @@ class BaseProvider: def get_download_url(self): return self.DOWNLOAD_URL + def get_download_name(self): + return "" + def download(self): download_directory = tempfile.mkdtemp() repacked_directory = tempfile.mkdtemp() - utils.run([ - 'epm', - '--silent', - 'tool', - 'eget', - '-q', - self.get_download_url(), - ], cwd=download_directory) + args = [] + + download_name = self.get_download_name() + + if download_name: + args += ["-O", download_name] + + args += [self.get_download_url()] + + utils.eget(args, cwd=download_directory) file = _get_file(download_directory) - utils.run([ - 'epm', - '--silent', + utils.epm([ '-y', 'repack', file, @@ -69,9 +70,7 @@ class BaseProvider: file = _get_file(repacked_directory) - utils.run([ - 'epm', - '--silent', + utils.epm([ 'repo', 'pkgadd', self.config.get('repo_path'), diff --git a/autorepacked/common_providers/github_releases_provider.py b/autorepacked/common_providers/github_releases_provider.py index 9f91bcc..22b6eb1 100644 --- a/autorepacked/common_providers/github_releases_provider.py +++ b/autorepacked/common_providers/github_releases_provider.py @@ -8,11 +8,7 @@ class GithubReleasesProvider(BaseProvider): _repo = '' def _last_release_url(self): - return utils.run([ - 'epm', - '--silent', - 'tool', - 'eget', + return utils.eget([ '--get-real-url', f'https://github.com/{self._repo}/releases/latest' ]) diff --git a/autorepacked/common_providers/snap_provider.py b/autorepacked/common_providers/snap_provider.py new file mode 100644 index 0000000..6a94538 --- /dev/null +++ b/autorepacked/common_providers/snap_provider.py @@ -0,0 +1,35 @@ +import json +import urllib + +from autorepacked.common_providers.base_provider import BaseProvider +from urllib.request import Request, urlopen + +class SnapProvider(BaseProvider): + _package_name = "package" + _channel = "stable" + _arch = "amd64" + + def _get_snap_info(self): + request = Request( + f"http://api.snapcraft.io/v2/snaps/info/{self._package_name}", + headers={"Content-Type": "application/json", "Snap-Device-Series": "16"}, + ) + response = urlopen(request).read() + return json.loads(response) + + def get_download_name(self): + return f"{self._package_name}-{self.get_version()}.snap" + + def get_version(self): + snap_info = self._get_snap_info() + for channel_map in snap_info["channel-map"]: + if (channel_map["channel"]["name"] == self._channel + and channel_map["channel"]["architecture"] == self._arch): + return channel_map['version'] + + def get_download_url(self): + snap_info = self._get_snap_info() + for channel_map in snap_info["channel-map"]: + if (channel_map["channel"]["name"] == self._channel + and channel_map["channel"]["architecture"] == self._arch): + return channel_map['download']['url'] diff --git a/autorepacked/main.py b/autorepacked/main.py index 6b08db0..4d5553b 100644 --- a/autorepacked/main.py +++ b/autorepacked/main.py @@ -14,8 +14,7 @@ from autorepacked.config import Config def create_repo(config: Config): - utils.run([ - 'epm', + utils.epm([ 'repo', 'create', config.get('repo_path') @@ -23,8 +22,7 @@ def create_repo(config: Config): def update_epm(): - utils.run([ - 'epm', + utils.epm([ 'ei' ]) @@ -69,23 +67,23 @@ def update(): module = importlib.import_module(f'providers.{module_name}') if hasattr(module, 'get_provider'): provider = module.get_provider(config) # type: BaseProvider - name = provider.get_name() - print(f"request version of {name}") - version = provider.get_version() - if name not in versions or versions[name] != version: - print(f'{name} has new version {version}') - versions[name] = version - provider.download() - need_update_index = True + if not provider.disabled: + name = provider.get_name() + print(f"request version of {name}") + version = provider.get_version() + if name not in versions or versions[name] != version: + print(f'{name} has new version {version}') + versions[name] = version + provider.download() + need_update_index = True repo_data['versions'] = versions current_date = datetime.datetime.utcnow() if need_update_index: - utils.run( + utils.epm( args=[ - 'epm', 'repo', 'index', config.get('repo_path'), diff --git a/autorepacked/providers/singularityapp/__init__.py b/autorepacked/providers/singularityapp/__init__.py new file mode 100644 index 0000000..fa85cdd --- /dev/null +++ b/autorepacked/providers/singularityapp/__init__.py @@ -0,0 +1,12 @@ +from autorepacked.common_providers.snap_provider import SnapProvider + + +class SingularityApp(SnapProvider): + disabled = True + + _name = 'singularityapp' + _package_name = 'singularityapp' + + +def get_provider(config): + return SingularityApp(config) \ No newline at end of file diff --git a/autorepacked/utils.py b/autorepacked/utils.py index 34dca5f..0b21496 100644 --- a/autorepacked/utils.py +++ b/autorepacked/utils.py @@ -7,3 +7,12 @@ def run(args, cwd=None): cwd=cwd, stdout=subprocess.PIPE, ).stdout.decode('utf-8') + + +def epm(args, cwd=None): + return run(["epm"] + args, cwd=cwd) + + +def eget(args, cwd=None): + return epm(["tool", "eget"] + args, cwd=cwd) +