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 \
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

View File

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

View File

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

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):
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'),

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