From: Michael Tremer Date: Sat, 19 Jun 2021 13:21:12 +0000 (+0000) Subject: pakfire: Drop old base module X-Git-Tag: 0.9.28~1221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28d8677bea02aeb5e42e2accf2cbec215b69816d;p=people%2Fms%2Fpakfire.git pakfire: Drop old base module Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index c801d54ed..7bf4a7f3e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -128,7 +128,6 @@ install-exec-local: pakfire_PYTHON = \ src/pakfire/__init__.py \ src/pakfire/__version__.py \ - src/pakfire/base.py \ src/pakfire/builder.py \ src/pakfire/client.py \ src/pakfire/cli.py \ diff --git a/src/pakfire/__init__.py b/src/pakfire/__init__.py index 290825a5a..a9759336b 100644 --- a/src/pakfire/__init__.py +++ b/src/pakfire/__init__.py @@ -19,7 +19,7 @@ # # ############################################################################### -from .base import Pakfire +from ._pakfire import Pakfire # Import Exceptions from ._pakfire import CommandExecutionError diff --git a/src/pakfire/base.py b/src/pakfire/base.py deleted file mode 100644 index 07cd0f77c..000000000 --- a/src/pakfire/base.py +++ /dev/null @@ -1,212 +0,0 @@ -#!/usr/bin/python3 -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -############################################################################### - -import logging -import os -import random -import string - -from . import _pakfire -from . import util - -from .system import system - -from .constants import * -from .i18n import _ - -class Pakfire(_pakfire.Pakfire): - __version__ = PAKFIRE_VERSION - - def __enter__(self): - """ - Called to initialize this Pakfire instance when - the context is entered. - """ - return PakfireContext(self) - - def __exit__(self, type, value, traceback): - pass - - -class PakfireContext(object): - """ - This context has functions that require - pakfire to be initialized. - - That means that repository data has to be downloaded - and imported to be searchable, etc. - """ - def __init__(self, pakfire): - self.pakfire = pakfire - - def check(self, **kwargs): - """ - Try to fix any errors in the system. - """ - # Detect any errors in the dependency tree. - # For that we create an empty request and solver and try to solve - # something. - request = _pakfire.Request(self.pakfire) - request.verify() - - return request.solve(**kwargs) - - def info(self, args): - pkgs = [] - - with _pakfire.Repo(self.pakfire, "tmp", clean=True) as r: - for arg in args: - if os.path.exists(arg) and not os.path.isdir(arg): - archive = _pakfire.Archive(self.pakfire, arg) - - # Add the archive to the repository - pkg = r.add_archive(archive) - pkgs.append(pkg) - - else: - pkgs += self.pakfire.whatprovides(arg, name_only=True) - - return sorted(pkgs) - - def provides(self, patterns): - pkgs = [] - - for pattern in patterns: - for pkg in self.pakfire.whatprovides(pattern): - if pkg in pkgs: - continue - - pkgs.append(pkg) - - return sorted(pkgs) - - def search(self, pattern): - return self.pakfire.search(pattern) - - def extract(self, filenames, target=None): - if target and target == "/": - raise ValueError("Cannot extract to: %s" % target) - - archives = [] - - # Open all archives - for filename in filenames: - a = _pakfire.Archive(self.pakfire, filename) - archives.append(a) - - # Nothing to do when no archives where opened - if not archives: - return - - # Extract them all - for archive in archives: - archive.extract(target) - - # Transactions - - def install(self, requires, **kwargs): - request = _pakfire.Request(self.pakfire) - - # XXX handle files and URLs - - for req in requires: - request.install(req) - - return request.solve(**kwargs) - - def reinstall(self, pkgs, strict=False, logger=None): - """ - Reinstall one or more packages - """ - raise NotImplementedError - - def erase(self, pkgs, **kwargs): - request = _pakfire.Request(self.pakfire) - - for pkg in pkgs: - relation = _pakfire.Relation(self.pakfire, pkg) - request.erase(relation) - - return request.solve(**kwargs) - - def update(self, reqs=None, excludes=None, **kwargs): - request = _pakfire.Request(self.pakfire) - - # Add all packages that should be updated to the request - for req in reqs or []: - relation = _pakfire.Relation(self.pakfire, req) - request.upgrade(relation) - - # Otherwise we will try to upgrade everything - else: - request.upgrade_all() - - # Exclude packages that should not be updated - for exclude in excludes or []: - relation = _pakfire.Relation(self.pakfire, exclude) - request.lock(relation) - - return request.solve(**kwargs) - - def downgrade(self, pkgs, logger=None, **kwargs): - assert pkgs - - if logger is None: - logger = logging.getLogger("pakfire") - - # Create a new request. - request = self.pakfire.create_request() - - # Fill request. - for pattern in pkgs: - best = None - for pkg in self.pakfire.repos.whatprovides(pattern): - # Only consider installed packages. - if not pkg.is_installed(): - continue - - if best and pkg > best: - best = pkg - elif best is None: - best = pkg - - if best is None: - logger.warning(_("\"%s\" package does not seem to be installed.") % pattern) - else: - rel = self.pakfire.create_relation("%s < %s" % (best.name, best.friendly_version)) - request.install(rel) - - # Solve the request. - solver = self.pakfire.solve(request, allow_downgrade=True, **kwargs) - assert solver.status is True - - # Create the transaction. - t = transaction.Transaction.from_solver(self.pakfire, solver) - t.dump(logger=logger) - - if not t: - logger.info(_("Nothing to do")) - return - - if not t.cli_yesno(): - return - - t.run() diff --git a/src/pakfire/builder.py b/src/pakfire/builder.py index 03ea2d64d..66469015e 100644 --- a/src/pakfire/builder.py +++ b/src/pakfire/builder.py @@ -24,7 +24,6 @@ import os import uuid from . import _pakfire -from . import base from . import logger from . import util @@ -74,7 +73,7 @@ class Builder(object): self.log.debug("Entering %s" % self) # Initialise Pakfire instance - pakfire = base.Pakfire( + pakfire = _pakfire.Pakfire( arch=self.arch, conf=self.conf, diff --git a/src/pakfire/cli.py b/src/pakfire/cli.py index ba19b2fda..fe0307f69 100644 --- a/src/pakfire/cli.py +++ b/src/pakfire/cli.py @@ -29,7 +29,7 @@ import sys import tempfile import time -from . import base +from . import _pakfire from . import builder from . import client from . import config @@ -196,7 +196,7 @@ class Cli(object): help=_("Run pakfire in offline mode.")) def pakfire(self, ns): - p = base.Pakfire( + p = _pakfire.Pakfire( arch=ns.arch, conf=ns.config, path=ns.root if "root" in ns else self.default_path, diff --git a/src/pakfire/daemon.py b/src/pakfire/daemon.py index ce4e0d466..87aab8fec 100644 --- a/src/pakfire/daemon.py +++ b/src/pakfire/daemon.py @@ -9,14 +9,12 @@ import sys import tempfile import time -import pakfire.base import pakfire.builder import pakfire.util from .system import system from . import _pakfire -from . import base from . import config from . import http from . import hub