mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-23 02:39:57 +00:00
clear code, allow to set overrides for each architecture
This commit is contained in:
@ -36,26 +36,7 @@ class Application:
|
||||
self.architecture = architecture
|
||||
self.repository = Repository(architecture, config)
|
||||
|
||||
def add(self, names: List[str]) -> None:
|
||||
for name in names:
|
||||
package = Package.load(name, self.config.get('aur', 'url'))
|
||||
task = Task(package, self.architecture, self.config, self.repository.paths)
|
||||
task.fetch(os.path.join(self.repository.paths.manual, package.name))
|
||||
|
||||
def remove(self, names: List[str]) -> None:
|
||||
self.repository.process_remove(names)
|
||||
|
||||
def report(self, target: Optional[List[str]] = None) -> None:
|
||||
targets = target or None
|
||||
self.repository.process_report(targets)
|
||||
|
||||
def sync(self, target: Optional[List[str]] = None) -> None:
|
||||
targets = target or None
|
||||
self.repository.process_sync(targets)
|
||||
|
||||
def update(self, updates: List[Package]) -> None:
|
||||
packages = self.repository.process_build(updates)
|
||||
self.repository.process_update(packages)
|
||||
def _finalize(self) -> None:
|
||||
self.report()
|
||||
self.sync()
|
||||
|
||||
@ -72,3 +53,27 @@ class Application:
|
||||
log_fn(f'{package.name} = {package.version}')
|
||||
|
||||
return updates
|
||||
|
||||
def add(self, names: List[str]) -> None:
|
||||
for name in names:
|
||||
package = Package.load(name, self.config.get('aur', 'url'))
|
||||
task = Task(package, self.architecture, self.config, self.repository.paths)
|
||||
task.fetch(os.path.join(self.repository.paths.manual, package.name))
|
||||
|
||||
def remove(self, names: List[str]) -> None:
|
||||
self.repository.process_remove(names)
|
||||
self._finalize()
|
||||
|
||||
def report(self, target: Optional[List[str]] = None) -> None:
|
||||
targets = target or None
|
||||
self.repository.process_report(targets)
|
||||
|
||||
def sync(self, target: Optional[List[str]] = None) -> None:
|
||||
targets = target or None
|
||||
self.repository.process_sync(targets)
|
||||
|
||||
def update(self, updates: List[Package]) -> None:
|
||||
packages = self.repository.process_build(updates)
|
||||
self.repository.process_update(packages)
|
||||
self._finalize()
|
||||
|
||||
|
@ -25,7 +25,7 @@ from typing import List, Optional
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import BuildFailed
|
||||
from ahriman.core.util import check_output, options_list
|
||||
from ahriman.core.util import check_output
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
@ -38,11 +38,11 @@ class Task:
|
||||
self.package = package
|
||||
self.paths = paths
|
||||
|
||||
section = f'build_{architecture}'
|
||||
self.archbuild_flags = options_list(config, section, 'archbuild_flags')
|
||||
section = config.get_section_name('build', architecture)
|
||||
self.archbuild_flags = config.get_list(section, 'archbuild_flags')
|
||||
self.build_command = config.get(section, 'build_command')
|
||||
self.makepkg_flags = options_list(config, section, 'makepkg_flags')
|
||||
self.makechrootpkg_flags = options_list(config, section, 'makechrootpkg_flags')
|
||||
self.makepkg_flags = config.get_list(section, 'makepkg_flags')
|
||||
self.makechrootpkg_flags = config.get_list(section, 'makechrootpkg_flags')
|
||||
|
||||
@property
|
||||
def git_path(self) -> str:
|
||||
|
@ -21,9 +21,7 @@ import configparser
|
||||
import os
|
||||
|
||||
from logging.config import fileConfig
|
||||
from typing import Dict, Optional
|
||||
|
||||
from ahriman.core.exceptions import MissingConfiguration
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
# built-in configparser extension
|
||||
@ -37,6 +35,16 @@ class Configuration(configparser.RawConfigParser):
|
||||
def include(self) -> str:
|
||||
return self.get('settings', 'include')
|
||||
|
||||
def get_list(self, section: str, key: str) -> List[str]:
|
||||
raw = self.get(section, key, fallback=None)
|
||||
if not raw: # empty string or none
|
||||
return []
|
||||
return raw.split()
|
||||
|
||||
def get_section_name(self, prefix: str, suffix: str) -> str:
|
||||
probe = f'{prefix}_{suffix}'
|
||||
return probe if self.has_section(probe) else prefix
|
||||
|
||||
def load(self, path: str) -> None:
|
||||
self.path = path
|
||||
self.read(self.path)
|
||||
|
@ -25,11 +25,12 @@ from ahriman.core.report.report import Report
|
||||
|
||||
class HTML(Report):
|
||||
|
||||
def __init__(self, config: Configuration) -> None:
|
||||
Report.__init__(self, config)
|
||||
self.report_path = config.get('html', 'path')
|
||||
self.css_path = config.get('html', 'css_path')
|
||||
self.link_path = config.get('html', 'link_path')
|
||||
def __init__(self, architecture: str, config: Configuration) -> None:
|
||||
Report.__init__(self, architecture, config)
|
||||
section = self.config.get_section_name('html', self.architecture)
|
||||
self.report_path = config.get(section, 'path')
|
||||
self.css_path = config.get(section, 'css_path')
|
||||
self.link_path = config.get(section, 'link_path')
|
||||
self.title = config.get('repository', 'name')
|
||||
|
||||
def generate(self, path: str) -> None:
|
||||
|
@ -26,19 +26,20 @@ from ahriman.models.report_settings import ReportSettings
|
||||
|
||||
class Report:
|
||||
|
||||
def __init__(self, config: Configuration) -> None:
|
||||
def __init__(self, architecture: str, config: Configuration) -> None:
|
||||
self.architecture = architecture
|
||||
self.config = config
|
||||
self.logger = logging.getLogger('builder')
|
||||
|
||||
@staticmethod
|
||||
def run(config: Configuration, target: str, path: str) -> None:
|
||||
def run(architecture: str, config: Configuration, target: str, path: str) -> None:
|
||||
provider = ReportSettings.from_option(target)
|
||||
if provider == ReportSettings.HTML:
|
||||
from ahriman.core.report.html import HTML
|
||||
report: Report = HTML(config)
|
||||
report: Report = HTML(architecture, config)
|
||||
else:
|
||||
from ahriman.core.report.dummy import Dummy
|
||||
report = Dummy(config)
|
||||
report = Dummy(architecture, config)
|
||||
|
||||
try:
|
||||
report.generate(path)
|
||||
|
@ -29,7 +29,6 @@ from ahriman.core.repo.repo_wrapper import RepoWrapper
|
||||
from ahriman.core.report.report import Report
|
||||
from ahriman.core.sign.gpg_wrapper import GPGWrapper
|
||||
from ahriman.core.upload.uploader import Uploader
|
||||
from ahriman.core.util import options_list
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
@ -120,15 +119,15 @@ class Repository:
|
||||
|
||||
def process_report(self, targets: Optional[List[str]]) -> None:
|
||||
if targets is None:
|
||||
targets = options_list(self.config, 'report', 'target')
|
||||
targets = self.config.get_list('report', 'target')
|
||||
for target in targets:
|
||||
Report.run(self.config, target, self.paths.repository)
|
||||
Report.run(self.architecture, self.config, target, self.paths.repository)
|
||||
|
||||
def process_sync(self, targets: Optional[List[str]]) -> None:
|
||||
if targets is None:
|
||||
targets = options_list(self.config, 'upload', 'target')
|
||||
targets = self.config.get_list('upload', 'target')
|
||||
for target in targets:
|
||||
Uploader.run(self.config, target, self.paths.repository)
|
||||
Uploader.run(self.architecture, self.config, target, self.paths.repository)
|
||||
|
||||
def process_update(self, packages: List[str]) -> str:
|
||||
for package in packages:
|
||||
|
@ -24,9 +24,10 @@ from ahriman.core.util import check_output
|
||||
|
||||
class Rsync(Uploader):
|
||||
|
||||
def __init__(self, config: Configuration) -> None:
|
||||
Uploader.__init__(self, config)
|
||||
self.remote = self.config.get('rsync', 'remote')
|
||||
def __init__(self, architecture: str, config: Configuration) -> None:
|
||||
Uploader.__init__(self, architecture, config)
|
||||
section = self.config.get_section_name('rsync', self.architecture)
|
||||
self.remote = self.config.get(section, 'remote')
|
||||
|
||||
def sync(self, path: str) -> None:
|
||||
check_output('rsync', '--archive', '--verbose', '--compress', '--partial', '--progress', '--delete', path, self.remote,
|
||||
|
@ -24,12 +24,13 @@ from ahriman.core.util import check_output
|
||||
|
||||
class S3(Uploader):
|
||||
|
||||
def __init__(self, config: Configuration) -> None:
|
||||
Uploader.__init__(self, config)
|
||||
self.bucket = self.config.get('s3', 'bucket')
|
||||
def __init__(self, architecture: str, config: Configuration) -> None:
|
||||
Uploader.__init__(self, architecture, config)
|
||||
section = self.config.get_section_name('s3', self.architecture)
|
||||
self.bucket = self.config.get(section, 'bucket')
|
||||
|
||||
def sync(self, path: str) -> None:
|
||||
# TODO rewrite to boto, but it is bullshit
|
||||
check_output('aws', 's3', 'sync', path, self.bucket,
|
||||
check_output('aws', 's3', 'sync', '--delete', path, self.bucket,
|
||||
exception=None,
|
||||
logger=self.logger)
|
||||
|
@ -26,22 +26,23 @@ from ahriman.models.upload_settings import UploadSettings
|
||||
|
||||
class Uploader:
|
||||
|
||||
def __init__(self, config: Configuration) -> None:
|
||||
def __init__(self, architecture: str, config: Configuration) -> None:
|
||||
self.architecture = architecture
|
||||
self.config = config
|
||||
self.logger = logging.getLogger('builder')
|
||||
|
||||
@staticmethod
|
||||
def run(config: Configuration, target: str, path: str) -> None:
|
||||
def run(architecture: str, config: Configuration, target: str, path: str) -> None:
|
||||
provider = UploadSettings.from_option(target)
|
||||
if provider == UploadSettings.Rsync:
|
||||
from ahriman.core.upload.rsync import Rsync
|
||||
uploader: Uploader = Rsync(config)
|
||||
uploader: Uploader = Rsync(architecture, config)
|
||||
elif provider == UploadSettings.S3:
|
||||
from ahriman.core.upload.s3 import S3
|
||||
uploader = S3(config)
|
||||
uploader = S3(architecture, config)
|
||||
else:
|
||||
from ahriman.core.upload.dummy import Dummy
|
||||
uploader = Dummy(config)
|
||||
uploader = Dummy(architecture, config)
|
||||
|
||||
try:
|
||||
uploader.sync(path)
|
||||
|
@ -20,9 +20,7 @@
|
||||
import subprocess
|
||||
|
||||
from logging import Logger
|
||||
from typing import List, Optional
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def check_output(*args: str, exception: Optional[Exception],
|
||||
@ -39,10 +37,3 @@ def check_output(*args: str, exception: Optional[Exception],
|
||||
logger.debug(line)
|
||||
raise exception or e
|
||||
return result
|
||||
|
||||
|
||||
def options_list(config: Configuration, section: str, key: str) -> List[str]:
|
||||
raw = config.get(section, key, fallback=None)
|
||||
if not raw: # empty string or none
|
||||
return []
|
||||
return raw.split()
|
Reference in New Issue
Block a user