mirror of
https://github.com/Maks1mS/altlinux-autorepacked.git
synced 2024-12-23 14:42:59 +03:00
Compare commits
2 Commits
657c424bf1
...
85cda3e705
Author | SHA1 | Date | |
---|---|---|---|
85cda3e705 | |||
dc54853fc7 |
@ -1,12 +1,11 @@
|
||||
FROM registry.altlinux.org/alt/python:p10
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
eepm \
|
||||
wget \
|
||||
apt-repo-tools \
|
||||
alien \
|
||||
pip
|
||||
# && rm -rf /var/lib/apt/lists/*
|
||||
pip && \
|
||||
wget -O- https://eepm.ru/epm.sh | bash /dev/stdin ei
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip --no-cache-dir install -r requirements.txt
|
||||
|
@ -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'),
|
35
autorepacked/common_providers/github_releases_provider.py
Normal file
35
autorepacked/common_providers/github_releases_provider.py
Normal file
@ -0,0 +1,35 @@
|
||||
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.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()}")
|
35
autorepacked/common_providers/snap_provider.py
Normal file
35
autorepacked/common_providers/snap_provider.py
Normal 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']
|
@ -9,19 +9,24 @@ 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
|
||||
|
||||
|
||||
def create_repo(config: Config):
|
||||
utils.run([
|
||||
'epm',
|
||||
utils.epm([
|
||||
'repo',
|
||||
'create',
|
||||
config.get('repo_path')
|
||||
])
|
||||
|
||||
|
||||
def update_epm():
|
||||
utils.epm([
|
||||
'ei'
|
||||
])
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
await update_repeat()
|
||||
@ -51,6 +56,8 @@ def update():
|
||||
update_task_started = False
|
||||
return
|
||||
|
||||
update_epm()
|
||||
|
||||
providers_path = os.path.join(os.getcwd(), 'autorepacked/providers')
|
||||
modules = os.listdir(providers_path)
|
||||
|
||||
@ -60,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'),
|
||||
|
@ -1,4 +1,4 @@
|
||||
from autorepacked.base_provider import BaseProvider
|
||||
from autorepacked.common_providers.base_provider import BaseProvider
|
||||
|
||||
|
||||
class CodeProvider(BaseProvider):
|
||||
|
@ -1,4 +1,4 @@
|
||||
from autorepacked.base_provider import BaseProvider
|
||||
from autorepacked.common_providers.base_provider import BaseProvider
|
||||
|
||||
|
||||
class DiscordProvider(BaseProvider):
|
||||
|
@ -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):
|
||||
|
12
autorepacked/providers/singularityapp/__init__.py
Normal file
12
autorepacked/providers/singularityapp/__init__.py
Normal 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)
|
17
autorepacked/providers/trezor_suite/__init__.py
Normal file
17
autorepacked/providers/trezor_suite/__init__.py
Normal file
@ -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)
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user