mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 07:17:17 +00:00
smart remove function and use built-in packages() function everywhere
This commit is contained in:
parent
8e72ee05ba
commit
aad893fe69
@ -44,22 +44,21 @@ class Application:
|
|||||||
def get_updates(self, no_aur: bool, no_manual: bool, no_vcs: bool,
|
def get_updates(self, no_aur: bool, no_manual: bool, no_vcs: bool,
|
||||||
log_fn: Callable[[str], None]) -> List[Package]:
|
log_fn: Callable[[str], None]) -> List[Package]:
|
||||||
updates = []
|
updates = []
|
||||||
checked: List[str] = []
|
|
||||||
|
|
||||||
if not no_aur:
|
if not no_aur:
|
||||||
updates.extend(self.repository.updates_aur(no_vcs, checked))
|
updates.extend(self.repository.updates_aur(no_vcs))
|
||||||
if not no_manual:
|
if not no_manual:
|
||||||
updates.extend(self.repository.updates_manual(checked))
|
updates.extend(self.repository.updates_manual())
|
||||||
|
|
||||||
for package in updates:
|
for package in updates:
|
||||||
log_fn(f'{package.name} = {package.version}')
|
log_fn(f'{package.base} = {package.version}')
|
||||||
|
|
||||||
return updates
|
return updates
|
||||||
|
|
||||||
def add(self, names: List[str]) -> None:
|
def add(self, names: List[str]) -> None:
|
||||||
def add_manual(name: str) -> None:
|
def add_manual(name: str) -> None:
|
||||||
package = Package.load(name, self.config.get('aur', 'url'))
|
package = Package.load(name, self.config.get('aur', 'url'))
|
||||||
Task.fetch(os.path.join(self.repository.paths.manual, package.name), package.url)
|
Task.fetch(os.path.join(self.repository.paths.manual, package.base), package.url)
|
||||||
|
|
||||||
def add_archive(src: str) -> None:
|
def add_archive(src: str) -> None:
|
||||||
dst = os.path.join(self.repository.paths.packages, os.path.basename(src))
|
dst = os.path.join(self.repository.paths.packages, os.path.basename(src))
|
||||||
|
@ -46,7 +46,7 @@ class Task:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def git_path(self) -> str:
|
def git_path(self) -> str:
|
||||||
return os.path.join(self.paths.sources, self.package.name)
|
return os.path.join(self.paths.sources, self.package.base)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fetch(local: str, remote: str) -> None:
|
def fetch(local: str, remote: str) -> None:
|
||||||
@ -58,17 +58,17 @@ class Task:
|
|||||||
cmd.extend(self.archbuild_flags)
|
cmd.extend(self.archbuild_flags)
|
||||||
cmd.extend(['--'] + self.makechrootpkg_flags)
|
cmd.extend(['--'] + self.makechrootpkg_flags)
|
||||||
cmd.extend(['--'] + self.makepkg_flags)
|
cmd.extend(['--'] + self.makepkg_flags)
|
||||||
self.logger.info(f'using {cmd} for {self.package.name}')
|
self.logger.info(f'using {cmd} for {self.package.base}')
|
||||||
|
|
||||||
check_output(
|
check_output(
|
||||||
*cmd,
|
*cmd,
|
||||||
exception=BuildFailed(self.package.name),
|
exception=BuildFailed(self.package.base),
|
||||||
cwd=self.git_path,
|
cwd=self.git_path,
|
||||||
logger=self.build_logger)
|
logger=self.build_logger)
|
||||||
|
|
||||||
# well it is not actually correct, but we can deal with it
|
# well it is not actually correct, but we can deal with it
|
||||||
return check_output('makepkg', '--packagelist',
|
return check_output('makepkg', '--packagelist',
|
||||||
exception=BuildFailed(self.package.name),
|
exception=BuildFailed(self.package.base),
|
||||||
cwd=self.git_path).splitlines()
|
cwd=self.git_path).splitlines()
|
||||||
|
|
||||||
def clone(self, path: Optional[str] = None) -> None:
|
def clone(self, path: Optional[str] = None) -> None:
|
||||||
|
@ -46,13 +46,12 @@ class RepoWrapper:
|
|||||||
cwd=self.paths.repository,
|
cwd=self.paths.repository,
|
||||||
logger=self.logger)
|
logger=self.logger)
|
||||||
|
|
||||||
def remove(self, path: str, package: str) -> None:
|
def remove(self, prefix: str, package: str) -> None:
|
||||||
os.remove(path)
|
for fn in filter(lambda f: f.startswith(prefix), os.listdir(self.paths.repository)):
|
||||||
sign_path = f'{path}.sig'
|
full_path = os.path.join(self.paths.repository, fn)
|
||||||
if os.path.exists(sign_path):
|
os.remove(full_path)
|
||||||
os.remove(sign_path)
|
|
||||||
check_output(
|
check_output(
|
||||||
'repo-remove', *self.sign_args, self.repo_path, package,
|
'repo-remove', *self.sign_args, self.repo_path, package,
|
||||||
exception=BuildFailed(path),
|
exception=BuildFailed(package),
|
||||||
cwd=self.paths.repository,
|
cwd=self.paths.repository,
|
||||||
logger=self.logger)
|
logger=self.logger)
|
||||||
|
@ -40,7 +40,7 @@ class HTML(Report):
|
|||||||
|
|
||||||
# base template vars
|
# base template vars
|
||||||
if SignSettings.from_option(config.get('sign', 'enabled')) != SignSettings.Disabled:
|
if SignSettings.from_option(config.get('sign', 'enabled')) != SignSettings.Disabled:
|
||||||
self.pgp_key = config.get('sign', 'key')
|
self.pgp_key = config.get('sign', 'key', fallback=None)
|
||||||
else:
|
else:
|
||||||
self.pgp_key = None
|
self.pgp_key = None
|
||||||
self.homepage = config.get(section, 'homepage', fallback=None)
|
self.homepage = config.get(section, 'homepage', fallback=None)
|
||||||
|
@ -70,9 +70,7 @@ class Repository:
|
|||||||
full_path = os.path.join(self.paths.repository, fn)
|
full_path = os.path.join(self.paths.repository, fn)
|
||||||
try:
|
try:
|
||||||
local = Package.load(full_path, self.aur_url)
|
local = Package.load(full_path, self.aur_url)
|
||||||
if local.name in result:
|
result.setdefault(local.base, local).packages.update(local.packages)
|
||||||
continue
|
|
||||||
result[local.name] = local
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self.logger.exception(f'could not load package from {fn}', exc_info=True)
|
self.logger.exception(f'could not load package from {fn}', exc_info=True)
|
||||||
continue
|
continue
|
||||||
@ -91,7 +89,7 @@ class Repository:
|
|||||||
try:
|
try:
|
||||||
build_single(package)
|
build_single(package)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.logger.exception(f'{package.name} ({self.architecture}) build exception', exc_info=True)
|
self.logger.exception(f'{package.base} ({self.architecture}) build exception', exc_info=True)
|
||||||
continue
|
continue
|
||||||
self._clear_build()
|
self._clear_build()
|
||||||
|
|
||||||
@ -101,19 +99,21 @@ class Repository:
|
|||||||
]
|
]
|
||||||
|
|
||||||
def process_remove(self, packages: List[str]) -> str:
|
def process_remove(self, packages: List[str]) -> str:
|
||||||
for fn in os.listdir(self.paths.repository):
|
def remove_single(package: str) -> None:
|
||||||
if not package_like(fn):
|
|
||||||
continue
|
|
||||||
|
|
||||||
full_path = os.path.join(self.paths.repository, fn)
|
|
||||||
try:
|
try:
|
||||||
local = Package.load(full_path, self.aur_url)
|
self.wrapper.remove(package, package)
|
||||||
if local.name not in packages:
|
|
||||||
continue
|
|
||||||
self.wrapper.remove(full_path, local.name)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self.logger.exception(f'could not load package from {fn}', exc_info=True)
|
self.logger.exception(f'could not remove {package}', exc_info=True)
|
||||||
continue
|
|
||||||
|
for local in self.packages():
|
||||||
|
if local.base in packages:
|
||||||
|
to_remove = local.packages
|
||||||
|
elif local.packages.intersection(packages):
|
||||||
|
to_remove = local.packages.intersection(packages)
|
||||||
|
else:
|
||||||
|
to_remove = set()
|
||||||
|
for package in to_remove:
|
||||||
|
remove_single(package)
|
||||||
|
|
||||||
return self.wrapper.repo_path
|
return self.wrapper.repo_path
|
||||||
|
|
||||||
@ -141,43 +141,33 @@ class Repository:
|
|||||||
|
|
||||||
return self.wrapper.repo_path
|
return self.wrapper.repo_path
|
||||||
|
|
||||||
def updates_aur(self, no_vcs: bool, checked: List[str]) -> List[Package]:
|
def updates_aur(self, no_vcs: bool) -> List[Package]:
|
||||||
result: List[Package] = []
|
result: List[Package] = []
|
||||||
ignore_list = self.config.get_list(
|
ignore_list = self.config.get_list(
|
||||||
self.config.get_section_name('build', self.architecture), 'ignore_packages')
|
self.config.get_section_name('build', self.architecture), 'ignore_packages')
|
||||||
|
|
||||||
for fn in os.listdir(self.paths.repository):
|
for local in self.packages():
|
||||||
if not package_like(fn):
|
if local.base in ignore_list:
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
local = Package.load(os.path.join(self.paths.repository, fn), self.aur_url)
|
|
||||||
remote = Package.load(local.name, self.aur_url)
|
|
||||||
except Exception:
|
|
||||||
self.logger.exception(f'could not load package from {fn}', exc_info=True)
|
|
||||||
continue
|
|
||||||
if local.name in checked:
|
|
||||||
continue
|
|
||||||
if local.name in ignore_list:
|
|
||||||
continue
|
continue
|
||||||
if local.is_vcs and no_vcs:
|
if local.is_vcs and no_vcs:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
remote = Package.load(local.base, self.aur_url)
|
||||||
if local.is_outdated(remote):
|
if local.is_outdated(remote):
|
||||||
result.append(remote)
|
result.append(remote)
|
||||||
checked.append(local.name)
|
except Exception:
|
||||||
|
self.logger.exception(f'could not load remote package {local.base}', exc_info=True)
|
||||||
|
continue
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def updates_manual(self, checked: List[str]) -> List[Package]:
|
def updates_manual(self) -> List[Package]:
|
||||||
result: List[Package] = []
|
result: List[Package] = []
|
||||||
|
|
||||||
for fn in os.listdir(self.paths.manual):
|
for fn in os.listdir(self.paths.manual):
|
||||||
local = Package.load(os.path.join(self.paths.manual, fn), self.aur_url)
|
local = Package.load(os.path.join(self.paths.manual, fn), self.aur_url)
|
||||||
if local.name in checked:
|
|
||||||
continue
|
|
||||||
result.append(local)
|
result.append(local)
|
||||||
checked.append(local.name)
|
|
||||||
self._clear_manual()
|
self._clear_manual()
|
||||||
|
|
||||||
return result
|
return result
|
@ -26,9 +26,9 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from configparser import RawConfigParser
|
from configparser import RawConfigParser
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
from srcinfo.parse import parse_srcinfo
|
from srcinfo.parse import parse_srcinfo
|
||||||
from typing import Type
|
from typing import Set, Type
|
||||||
|
|
||||||
from ahriman.core.exceptions import InvalidPackageInfo
|
from ahriman.core.exceptions import InvalidPackageInfo
|
||||||
from ahriman.core.util import check_output
|
from ahriman.core.util import check_output
|
||||||
@ -36,19 +36,19 @@ from ahriman.core.util import check_output
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Package:
|
class Package:
|
||||||
name: str
|
base: str
|
||||||
version: str
|
version: str
|
||||||
url: str
|
url: str
|
||||||
remote: bool
|
packages: Set[str] = field(default_factory=set)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_vcs(self) -> bool:
|
def is_vcs(self) -> bool:
|
||||||
return self.name.endswith('-bzr') \
|
return self.base.endswith('-bzr') \
|
||||||
or self.name.endswith('-csv')\
|
or self.base.endswith('-csv')\
|
||||||
or self.name.endswith('-darcs')\
|
or self.base.endswith('-darcs')\
|
||||||
or self.name.endswith('-git')\
|
or self.base.endswith('-git')\
|
||||||
or self.name.endswith('-hg')\
|
or self.base.endswith('-hg')\
|
||||||
or self.name.endswith('-svn')
|
or self.base.endswith('-svn')
|
||||||
|
|
||||||
# additional method to handle vcs versions
|
# additional method to handle vcs versions
|
||||||
def actual_version(self) -> str:
|
def actual_version(self) -> str:
|
||||||
@ -74,13 +74,14 @@ class Package:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_archive(cls: Type[Package], path: str, aur_url: str) -> Package:
|
def from_archive(cls: Type[Package], path: str, aur_url: str) -> Package:
|
||||||
name, version = check_output('expac', '-p', '%e %v', path, exception=None).split()
|
package, base, version = check_output('expac', '-p', '%n %e %v', path, exception=None).split()
|
||||||
return cls(name, version, f'{aur_url}/{name}.git', False)
|
return cls(base, version, f'{aur_url}/{base}.git', packages={package})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_aur(cls: Type[Package], name: str, aur_url: str)-> Package:
|
def from_aur(cls: Type[Package], name: str, aur_url: str)-> Package:
|
||||||
package = aur.info(name)
|
package = aur.info(name)
|
||||||
return cls(package.package_base, package.version, f'{aur_url}/{package.package_base}.git', True)
|
return cls(package.package_base, package.version, f'{aur_url}/{package.package_base}.git',
|
||||||
|
packages={package.name})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_build(cls: Type[Package], path: str) -> Package:
|
def from_build(cls: Type[Package], path: str) -> Package:
|
||||||
@ -91,9 +92,10 @@ class Package:
|
|||||||
src_info, errors = parse_srcinfo(fn.read())
|
src_info, errors = parse_srcinfo(fn.read())
|
||||||
if errors:
|
if errors:
|
||||||
raise InvalidPackageInfo(errors)
|
raise InvalidPackageInfo(errors)
|
||||||
|
packages = set(src_info['packages'].keys())
|
||||||
|
|
||||||
return cls(src_info['pkgbase'], f'{src_info["pkgver"]}-{src_info["pkgrel"]}',
|
return cls(src_info['pkgbase'], f'{src_info["pkgver"]}-{src_info["pkgrel"]}',
|
||||||
git_config.get('remote "origin"', 'url'), False)
|
git_config.get('remote "origin"', 'url'), packages-packages)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls: Type[Package], path: str, aur_url: str) -> Package:
|
def load(cls: Type[Package], path: str, aur_url: str) -> Package:
|
||||||
|
Loading…
Reference in New Issue
Block a user