This commit is contained in:
Maxim Slipenko 2024-01-17 15:36:11 +03:00
parent dc54853fc7
commit 85cda3e705
7 changed files with 87 additions and 39 deletions

View File

@ -6,7 +6,6 @@ RUN apt-get update && apt-get install -y \
alien \ alien \
pip && \ pip && \
wget -O- https://eepm.ru/epm.sh | bash /dev/stdin ei wget -O- https://eepm.ru/epm.sh | bash /dev/stdin ei
# && rm -rf /var/lib/apt/lists/*
COPY requirements.txt . COPY requirements.txt .
RUN pip --no-cache-dir install -r requirements.txt RUN pip --no-cache-dir install -r requirements.txt

View File

@ -13,6 +13,8 @@ def _get_file(directory):
class BaseProvider: class BaseProvider:
disabled = False
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
@ -23,11 +25,7 @@ class BaseProvider:
return self._name return self._name
def get_version(self): def get_version(self):
url = utils.run([ url = utils.eget([
'epm',
'--silent',
'tool',
'eget',
'--get-real-url', '--get-real-url',
self.get_download_url(), self.get_download_url(),
]) ])
@ -42,24 +40,27 @@ class BaseProvider:
def get_download_url(self): def get_download_url(self):
return self.DOWNLOAD_URL return self.DOWNLOAD_URL
def get_download_name(self):
return ""
def download(self): def download(self):
download_directory = tempfile.mkdtemp() download_directory = tempfile.mkdtemp()
repacked_directory = tempfile.mkdtemp() repacked_directory = tempfile.mkdtemp()
utils.run([ args = []
'epm',
'--silent', download_name = self.get_download_name()
'tool',
'eget', if download_name:
'-q', args += ["-O", download_name]
self.get_download_url(),
], cwd=download_directory) args += [self.get_download_url()]
utils.eget(args, cwd=download_directory)
file = _get_file(download_directory) file = _get_file(download_directory)
utils.run([ utils.epm([
'epm',
'--silent',
'-y', '-y',
'repack', 'repack',
file, file,
@ -69,9 +70,7 @@ class BaseProvider:
file = _get_file(repacked_directory) file = _get_file(repacked_directory)
utils.run([ utils.epm([
'epm',
'--silent',
'repo', 'repo',
'pkgadd', 'pkgadd',
self.config.get('repo_path'), self.config.get('repo_path'),

View File

@ -8,11 +8,7 @@ class GithubReleasesProvider(BaseProvider):
_repo = '' _repo = ''
def _last_release_url(self): def _last_release_url(self):
return utils.run([ return utils.eget([
'epm',
'--silent',
'tool',
'eget',
'--get-real-url', '--get-real-url',
f'https://github.com/{self._repo}/releases/latest' f'https://github.com/{self._repo}/releases/latest'
]) ])

View File

@ -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']

View File

@ -14,8 +14,7 @@ from autorepacked.config import Config
def create_repo(config: Config): def create_repo(config: Config):
utils.run([ utils.epm([
'epm',
'repo', 'repo',
'create', 'create',
config.get('repo_path') config.get('repo_path')
@ -23,8 +22,7 @@ def create_repo(config: Config):
def update_epm(): def update_epm():
utils.run([ utils.epm([
'epm',
'ei' 'ei'
]) ])
@ -69,6 +67,7 @@ def update():
module = importlib.import_module(f'providers.{module_name}') module = importlib.import_module(f'providers.{module_name}')
if hasattr(module, 'get_provider'): if hasattr(module, 'get_provider'):
provider = module.get_provider(config) # type: BaseProvider provider = module.get_provider(config) # type: BaseProvider
if not provider.disabled:
name = provider.get_name() name = provider.get_name()
print(f"request version of {name}") print(f"request version of {name}")
version = provider.get_version() version = provider.get_version()
@ -83,9 +82,8 @@ def update():
current_date = datetime.datetime.utcnow() current_date = datetime.datetime.utcnow()
if need_update_index: if need_update_index:
utils.run( utils.epm(
args=[ args=[
'epm',
'repo', 'repo',
'index', 'index',
config.get('repo_path'), config.get('repo_path'),

View File

@ -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)

View File

@ -7,3 +7,12 @@ def run(args, cwd=None):
cwd=cwd, cwd=cwd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
).stdout.decode('utf-8') ).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)