mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 07:17:17 +00:00
allow to run single command for multiple architectures at the same time
This commit is contained in:
parent
2cef540cc0
commit
a288986450
@ -23,7 +23,7 @@ optdepends=('aws-cli: sync to s3'
|
|||||||
source=("https://github.com/arcan1s/ahriman/releases/download/$pkgver/$pkgname-$pkgver-src.tar.xz"
|
source=("https://github.com/arcan1s/ahriman/releases/download/$pkgver/$pkgname-$pkgver-src.tar.xz"
|
||||||
'ahriman.sysusers'
|
'ahriman.sysusers'
|
||||||
'ahriman.tmpfiles')
|
'ahriman.tmpfiles')
|
||||||
sha512sums=('21a1a216af25aeb580f5f2f574e9eed6eb79b74a1038c40a2e1594f18ca0afcd8a64358d11494b87a9a9ea25d5f6be27c39591b124a6ae2d7d4e78fbe44fdd1d'
|
sha512sums=('1af6c022bb1cf3bb55cb3ba426673ee73f98bd1a4de2191033a2d09bd73c6afb10c2a14ac3c70daa6ecbf7a62385178005f5276ee6a9942dc295d7c49d7ed412'
|
||||||
'13718afec2c6786a18f0b223ef8e58dccf0688bca4cdbe203f14071f5031ed20120eb0ce38b52c76cfd6e8b6581a9c9eaa2743eb11abbaca637451a84c33f075'
|
'13718afec2c6786a18f0b223ef8e58dccf0688bca4cdbe203f14071f5031ed20120eb0ce38b52c76cfd6e8b6581a9c9eaa2743eb11abbaca637451a84c33f075'
|
||||||
'55b20f6da3d66e7bbf2add5d95a3b60632df121717d25a993e56e737d14f51fe063eb6f1b38bd81cc32e05db01c0c1d80aaa720c45cde87f238d8b46cdb8cbc4')
|
'55b20f6da3d66e7bbf2add5d95a3b60632df121717d25a993e56e737d14f51fe063eb6f1b38bd81cc32e05db01c0c1d80aaa720c45cde87f238d8b46cdb8cbc4')
|
||||||
backup=('etc/ahriman.ini'
|
backup=('etc/ahriman.ini'
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#
|
#
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
from multiprocessing import Pool
|
||||||
|
|
||||||
import ahriman.version as version
|
import ahriman.version as version
|
||||||
|
|
||||||
from ahriman.application.application import Application
|
from ahriman.application.application import Application
|
||||||
@ -26,64 +28,81 @@ from ahriman.application.lock import Lock
|
|||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
|
|
||||||
|
|
||||||
def add(args: argparse.Namespace, config: Configuration) -> None:
|
def _call(args: argparse.Namespace, architecture: str, config: Configuration) -> None:
|
||||||
|
'''
|
||||||
|
additional function to wrap all calls for multiprocessing library
|
||||||
|
:param args: command line args
|
||||||
|
:param architecture: repository architecture
|
||||||
|
:param config: configuration instance
|
||||||
|
'''
|
||||||
|
with Lock(args.lock, architecture, args.force, config):
|
||||||
|
args.fn(args, architecture, config)
|
||||||
|
|
||||||
|
|
||||||
|
def add(args: argparse.Namespace, architecture: str, config: Configuration) -> None:
|
||||||
'''
|
'''
|
||||||
add packages callback
|
add packages callback
|
||||||
:param args: command line args
|
:param args: command line args
|
||||||
|
:param architecture: repository architecture
|
||||||
:param config: configuration instance
|
:param config: configuration instance
|
||||||
'''
|
'''
|
||||||
Application.from_args(args, config).add(args.package, args.without_dependencies)
|
Application(architecture, config).add(args.package, args.without_dependencies)
|
||||||
|
|
||||||
|
|
||||||
def rebuild(args: argparse.Namespace, config: Configuration) -> None:
|
def rebuild(args: argparse.Namespace, architecture: str, config: Configuration) -> None:
|
||||||
'''
|
'''
|
||||||
world rebuild callback
|
world rebuild callback
|
||||||
:param args: command line args
|
:param args: command line args
|
||||||
|
:param architecture: repository architecture
|
||||||
:param config: configuration instance
|
:param config: configuration instance
|
||||||
'''
|
'''
|
||||||
app = Application.from_args(args, config)
|
app = Application(architecture, config)
|
||||||
packages = app.repository.packages()
|
packages = app.repository.packages()
|
||||||
app.update(packages)
|
app.update(packages)
|
||||||
|
|
||||||
|
|
||||||
def remove(args: argparse.Namespace, config: Configuration) -> None:
|
def remove(args: argparse.Namespace, architecture: str, config: Configuration) -> None:
|
||||||
'''
|
'''
|
||||||
remove packages callback
|
remove packages callback
|
||||||
:param args: command line args
|
:param args: command line args
|
||||||
|
:param architecture: repository architecture
|
||||||
:param config: configuration instance
|
:param config: configuration instance
|
||||||
'''
|
'''
|
||||||
Application.from_args(args, config).remove(args.package)
|
Application(architecture, config).remove(args.package)
|
||||||
|
|
||||||
|
|
||||||
def report(args: argparse.Namespace, config: Configuration) -> None:
|
def report(args: argparse.Namespace, architecture: str, config: Configuration) -> None:
|
||||||
'''
|
'''
|
||||||
generate report callback
|
generate report callback
|
||||||
:param args: command line args
|
:param args: command line args
|
||||||
|
:param architecture: repository architecture
|
||||||
:param config: configuration instance
|
:param config: configuration instance
|
||||||
'''
|
'''
|
||||||
Application.from_args(args, config).report(args.target)
|
Application(architecture, config).report(args.target)
|
||||||
|
|
||||||
|
|
||||||
def sync(args: argparse.Namespace, config: Configuration) -> None:
|
def sync(args: argparse.Namespace, architecture: str, config: Configuration) -> None:
|
||||||
'''
|
'''
|
||||||
sync to remote server callback
|
sync to remote server callback
|
||||||
:param args: command line args
|
:param args: command line args
|
||||||
|
:param architecture: repository architecture
|
||||||
:param config: configuration instance
|
:param config: configuration instance
|
||||||
'''
|
'''
|
||||||
Application.from_args(args, config).sync(args.target)
|
Application(architecture, config).sync(args.target)
|
||||||
|
|
||||||
|
|
||||||
def update(args: argparse.Namespace, config: Configuration) -> None:
|
def update(args: argparse.Namespace, architecture: str, config: Configuration) -> None:
|
||||||
'''
|
'''
|
||||||
update packages callback
|
update packages callback
|
||||||
:param args: command line args
|
:param args: command line args
|
||||||
|
:param architecture: repository architecture
|
||||||
:param config: configuration instance
|
:param config: configuration instance
|
||||||
'''
|
'''
|
||||||
# typing workaround
|
# typing workaround
|
||||||
def log_fn(line: str) -> None:
|
def log_fn(line: str) -> None:
|
||||||
return print(line) if args.dry_run else app.logger.info(line)
|
return print(line) if args.dry_run else app.logger.info(line)
|
||||||
|
|
||||||
app = Application.from_args(args, config)
|
app = Application(architecture, config)
|
||||||
packages = app.get_updates(args.package, args.no_aur, args.no_manual, args.no_vcs, log_fn)
|
packages = app.get_updates(args.package, args.no_aur, args.no_manual, args.no_vcs, log_fn)
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
return
|
return
|
||||||
@ -91,20 +110,21 @@ def update(args: argparse.Namespace, config: Configuration) -> None:
|
|||||||
app.update(packages)
|
app.update(packages)
|
||||||
|
|
||||||
|
|
||||||
def web(args: argparse.Namespace, config: Configuration) -> None:
|
def web(args: argparse.Namespace, architecture: str, config: Configuration) -> None:
|
||||||
'''
|
'''
|
||||||
web server callback
|
web server callback
|
||||||
:param args: command line args
|
:param args: command line args
|
||||||
|
:param architecture: repository architecture
|
||||||
:param config: configuration instance
|
:param config: configuration instance
|
||||||
'''
|
'''
|
||||||
from ahriman.web.web import run_server, setup_service
|
from ahriman.web.web import run_server, setup_service
|
||||||
app = setup_service(args.architecture, config)
|
app = setup_service(architecture, config)
|
||||||
run_server(app, args.architecture)
|
run_server(app, architecture)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(prog='ahriman', description='ArcHlinux ReposItory MANager')
|
parser = argparse.ArgumentParser(prog='ahriman', description='ArcHlinux ReposItory MANager')
|
||||||
parser.add_argument('-a', '--architecture', help='target architecture', required=True)
|
parser.add_argument('-a', '--architecture', help='target architectures', action='append')
|
||||||
parser.add_argument('-c', '--config', help='configuration path', default='/etc/ahriman.ini')
|
parser.add_argument('-c', '--config', help='configuration path', default='/etc/ahriman.ini')
|
||||||
parser.add_argument('--force', help='force run, remove file lock', action='store_true')
|
parser.add_argument('--force', help='force run, remove file lock', action='store_true')
|
||||||
parser.add_argument('--lock', help='lock file', default='/tmp/ahriman.lock')
|
parser.add_argument('--lock', help='lock file', default='/tmp/ahriman.lock')
|
||||||
@ -118,7 +138,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
check_parser = subparsers.add_parser('check', description='check for updates')
|
check_parser = subparsers.add_parser('check', description='check for updates')
|
||||||
check_parser.add_argument('package', help='filter check by packages', nargs='*')
|
check_parser.add_argument('package', help='filter check by packages', nargs='*')
|
||||||
check_parser.set_defaults(fn=update, no_aur=False, no_manual=True, no_vcs=False, dry_run=True)
|
check_parser.add_argument('--no-vcs', help='do not check VCS packages', action='store_true')
|
||||||
|
check_parser.set_defaults(fn=update, no_aur=False, no_manual=True, dry_run=True)
|
||||||
|
|
||||||
rebuild_parser = subparsers.add_parser('rebuild', description='rebuild whole repository')
|
rebuild_parser = subparsers.add_parser('rebuild', description='rebuild whole repository')
|
||||||
rebuild_parser.set_defaults(fn=rebuild)
|
rebuild_parser.set_defaults(fn=rebuild)
|
||||||
@ -153,5 +174,5 @@ if __name__ == '__main__':
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
config = Configuration.from_path(args.config)
|
config = Configuration.from_path(args.config)
|
||||||
with Lock(args.lock, args.architecture, args.force, config):
|
with Pool(len(args.architecture)) as pool:
|
||||||
args.fn(args, config)
|
pool.starmap(_call, [(args, architecture, config) for architecture in args.architecture])
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#
|
#
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@ -53,16 +52,6 @@ class Application:
|
|||||||
self.architecture = architecture
|
self.architecture = architecture
|
||||||
self.repository = Repository(architecture, config)
|
self.repository = Repository(architecture, config)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_args(cls: Type[Application], args: argparse.Namespace, config: Configuration) -> Application:
|
|
||||||
'''
|
|
||||||
constructor which has to be used to build instance from command line args
|
|
||||||
:param args: command line args
|
|
||||||
:param config: configuration instance
|
|
||||||
:return: application instance
|
|
||||||
'''
|
|
||||||
return cls(args.architecture, config)
|
|
||||||
|
|
||||||
def _known_packages(self) -> Set[str]:
|
def _known_packages(self) -> Set[str]:
|
||||||
'''
|
'''
|
||||||
load packages from repository and pacman repositories
|
load packages from repository and pacman repositories
|
||||||
|
@ -25,7 +25,7 @@ from dataclasses import dataclass
|
|||||||
@dataclass
|
@dataclass
|
||||||
class RepositoryPaths:
|
class RepositoryPaths:
|
||||||
'''
|
'''
|
||||||
repository paths holder
|
repository paths holder. For the most operations with paths you want to use this object
|
||||||
:ivar root: repository root (i.e. ahriman home)
|
:ivar root: repository root (i.e. ahriman home)
|
||||||
:ivar architecture: repository architecture
|
:ivar architecture: repository architecture
|
||||||
'''
|
'''
|
||||||
@ -38,6 +38,7 @@ class RepositoryPaths:
|
|||||||
'''
|
'''
|
||||||
:return: directory for devtools chroot
|
:return: directory for devtools chroot
|
||||||
'''
|
'''
|
||||||
|
# for the chroot directory devtools will create own tree and we don't have to specify architecture here
|
||||||
return os.path.join(self.root, 'chroot')
|
return os.path.join(self.root, 'chroot')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -45,14 +46,14 @@ class RepositoryPaths:
|
|||||||
'''
|
'''
|
||||||
:return: directory for manual updates (i.e. from add command)
|
:return: directory for manual updates (i.e. from add command)
|
||||||
'''
|
'''
|
||||||
return os.path.join(self.root, 'manual')
|
return os.path.join(self.root, 'manual', self.architecture)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def packages(self) -> str:
|
def packages(self) -> str:
|
||||||
'''
|
'''
|
||||||
:return: directory for built packages
|
:return: directory for built packages
|
||||||
'''
|
'''
|
||||||
return os.path.join(self.root, 'packages')
|
return os.path.join(self.root, 'packages', self.architecture)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def repository(self) -> str:
|
def repository(self) -> str:
|
||||||
@ -66,7 +67,7 @@ class RepositoryPaths:
|
|||||||
'''
|
'''
|
||||||
:return: directory for downloaded PKGBUILDs for current build
|
:return: directory for downloaded PKGBUILDs for current build
|
||||||
'''
|
'''
|
||||||
return os.path.join(self.root, 'sources')
|
return os.path.join(self.root, 'sources', self.architecture)
|
||||||
|
|
||||||
def create_tree(self) -> None:
|
def create_tree(self) -> None:
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user