import logging
log = logging.getLogger("pakfire")
-from .config import Config
from .constants import *
from .i18n import _
class Pakfire(object):
mode = None
- def __init__(self, path="/", config=None, configs=None, arch=None, **kwargs):
- # Indicates if this instance has already been initialized.
- self.initialized = False
-
+ def __init__(self, path="/", arch=None):
# Check if we are operating as the root user.
self.check_root_user()
if not self.mode and self.path == "/":
self.check_is_ipfire()
- # Get the configuration.
- if config:
- self.config = config
- else:
- self.config = self._load_config(configs)
-
- # Update configuration with additional arguments.
- for section, settings in list(kwargs.items()):
- self.config.update(section, settings)
-
- # Dump the configuration.
- self.config.dump()
+ # Load configuration
+ self.config = config.Config("general.conf")
# Initialize the keyring.
self.keyring = keyring.Keyring(self)
self.pool = satsolver.Pool(self.distro.arch)
self.repos = repository.Repositories(self)
- def initialize(self):
+ def __enter__(self):
"""
- Initialize pakfire instance.
+ Called to initialize this Pakfire instance when
+ the context is entered.
"""
- if self.initialized:
- return
+ # Dump the configuration when we enter the context
+ self.config.dump()
- # Initialize repositories.
+ # Initialize repositories
self.repos.initialize()
- self.initialized = True
+ return self
- def _load_config(self, files=None):
- """
- This method loads all needed configuration files.
- """
- if files is None:
- files = []
-
- return config.Config(*files)
-
- def destroy(self):
+ def __exit__(self, type, value, traceback):
+ # Close repositories
self.repos.shutdown()
- self.initialized = False
-
@property
def supported_arches(self):
return system.supported_arches
return self.mode == "builder"
def install(self, requires, interactive=True, logger=None, signatures_mode=None, **kwargs):
- # Initialize this pakfire instance.
- self.initialize()
-
if not logger:
logger = logging.getLogger("pakfire")
If strict is True, only a package with excatly the same UUID
will replace the currently installed one.
"""
- # Initialize this pakfire instance.
- self.initialize()
-
if logger is None:
logger = logging.getLogger("pakfire")
check indicates, if the method should return after calculation
of the transaction.
"""
- # Initialize this pakfire instance.
- self.initialize()
-
if logger is None:
logger = logging.getLogger("pakfire")
if logger is None:
logger = logging.getLogger("pakfire")
- # Initialize this pakfire instance.
- self.initialize()
-
# Create a new request.
request = self.pool.create_request()
if logger is None:
logger = logging.getLogger("pakfire")
- # Initialize this pakfire instance.
- self.initialize()
-
# Create a new request.
request = self.pool.create_request(remove=pkgs)
t.run()
def info(self, patterns):
- # Initialize this pakfire instance.
- self.initialize()
-
pkgs = []
# For all patterns we run a single search which returns us a bunch
if pkg in pkgs:
continue
- pkgs.append(pkg)
+ pkgs.append(pkg)
return sorted(pkgs)
def search(self, pattern):
- # Initialize this pakfire instance.
- self.initialize()
-
# Do the search.
pkgs = {}
for solv in self.pool.search(pattern, satsolver.SEARCH_STRING|satsolver.SEARCH_FILES):
self.install("@%s" % group, **kwargs)
def grouplist(self, group):
- # Initialize this pakfire instance.
- self.initialize()
-
return self.pool.grouplist(group)
def provides(self, patterns):
- # Initialize this pakfire instance.
- self.initialize()
-
pkgs = []
for pattern in patterns:
for pkg in self.pool.whatprovides(self, pattern):
return pkgs
def resolvdep(self, pkg):
- # Initialize this pakfire instance.
- self.initialize()
-
return self.pool.resolvdep(self, pkg)
def repo_list(self):
- # Initialize this pakfire instance.
- self.initialize()
-
return [r for r in self.repos]
def clean_all(self):
- # Initialize this pakfire instance.
- self.initialize()
-
log.debug("Cleaning up everything...")
# Clean up repository caches.
"""
Try to fix any errors in the system.
"""
- # Initialize this pakfire instance.
- self.initialize()
-
# Detect any errors in the dependency tree.
# For that we create an empty request and solver and try to solve
# something.