mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-15 23:09:56 +00:00
use intersection of from_database and depends_on filters for the rebuild subcommand
Old logic used OR condition, i.e. if set from-database, it would ignore the --depends-on flag. In new logic it calculates dependencies based on the package list, which can be retrieved from database
This commit is contained in:
@ -51,10 +51,8 @@ class Rebuild(Handler):
|
||||
application = Application(architecture, configuration, report=report, unsafe=unsafe)
|
||||
application.on_start()
|
||||
|
||||
if args.from_database:
|
||||
updates = Rebuild.extract_packages(application)
|
||||
else:
|
||||
updates = application.repository.packages_depend_on(depends_on)
|
||||
packages = Rebuild.extract_packages(application, from_database=args.from_database)
|
||||
updates = application.repository.packages_depend_on(packages, depends_on)
|
||||
|
||||
Rebuild.check_if_empty(args.exit_code, not updates)
|
||||
if args.dry_run:
|
||||
@ -66,14 +64,17 @@ class Rebuild(Handler):
|
||||
Rebuild.check_if_empty(args.exit_code, result.is_empty)
|
||||
|
||||
@staticmethod
|
||||
def extract_packages(application: Application) -> List[Package]:
|
||||
def extract_packages(application: Application, *, from_database: bool) -> List[Package]:
|
||||
"""
|
||||
extract packages from database file
|
||||
|
||||
Args:
|
||||
application(Application): application instance
|
||||
from_database(bool): extract packages from database instead of repository filesystem
|
||||
|
||||
Returns:
|
||||
List[Package]: list of packages which were stored in database
|
||||
"""
|
||||
if from_database:
|
||||
return application.repository.packages()
|
||||
return [package for (package, _) in application.database.packages_get()]
|
||||
|
@ -99,17 +99,17 @@ class Repository(Executor, UpdateHandler):
|
||||
"""
|
||||
return list(filter(package_like, self.paths.packages.iterdir()))
|
||||
|
||||
def packages_depend_on(self, depends_on: Optional[Iterable[str]]) -> List[Package]:
|
||||
def packages_depend_on(self, packages: List[Package], depends_on: Optional[Iterable[str]]) -> List[Package]:
|
||||
"""
|
||||
extract list of packages which depends on specified package
|
||||
|
||||
Args:
|
||||
packages(List[Package]): list of packages to be filtered
|
||||
depends_on(Optional[Iterable[str]]): dependencies of the packages
|
||||
|
||||
Returns:
|
||||
List[Package]: list of repository packages which depend on specified packages
|
||||
"""
|
||||
packages = self.packages()
|
||||
if depends_on is None:
|
||||
return packages # no list provided extract everything by default
|
||||
depends_on = set(depends_on)
|
||||
|
Reference in New Issue
Block a user