import transaction
from constants import *
-from errors import BuildError
+from errors import BuildError, PakfireError
from i18n import _
__version__ = 0.1
class Pakfire(object):
- def __init__(self, path="/tmp/pakfire", builder=False, configs=[]):
+ def __init__(self, path="/tmp/pakfire", builder=False, configs=[],
+ disable_repos=None):
# The path where we are operating in
self.path = path
# Run plugins that implement an initialization method.
self.plugins.run("init")
- # XXX disable repositories if passed on command line
+ # Disable repositories if passed on command line
+ if disable_repos:
+ for repo in disable_repos:
+ self.repos.disable_repo(repo)
+
+ # Check if there is at least one enabled repository.
+ if len(self.repos) < 2:
+ raise PakfireError, "No repositories were configured."
+
+ # Update all indexes of the repositories (not force) so that we will
+ # always work with valid data.
+ self.repos.update_indexes()
def check_build_mode(self):
"""
self.pakfire = Pakfire(
self.args.instroot,
configs = [self.args.config],
+ disable_repos = self.args.disable_repo,
)
self.action2func = {
self.parser.add_argument("-c", "--config", nargs="?",
help=_("Path to a configuration file to load."))
+ self.parser.add_argument("--disable-repo", nargs="*", metavar="REPO",
+ help=_("Disable a repository temporarily."))
+
def parse_command_install(self):
# Implement the "install" command.
sub_install = self.sub_commands.add_parser("install",
self.pakfire = Pakfire(
builder = True,
configs = [self.args.config],
+ disable_repos = self.args.disable_repo,
)
self.action2func = {
class DownloadError(Error):
pass
+class PakfireError(Error):
+ pass
+
for repo_name, repo_args in self.config.get_repos():
self._parse(repo_name, repo_args)
- self.update_indexes()
+ def __len__(self):
+ """
+ Return the count of enabled repositories.
+ """
+ i = 0
+ for repo in self.enabled:
+ i += 1
+
+ return i
def _parse(self, name, args):
# XXX need to make variable expansion
yield repo
+ def disable_repo(self, name):
+ for repo in self.enabled:
+ if repo.name == name:
+ logging.debug("Disabled repository '%s'" % repo.name)
+ repo.enabled = False
+ continue
+
def update_indexes(self, force=False):
logging.debug("Updating all repository indexes (force=%s)" % force)
self.name, self.description = name, description
+ # All repositories are enabled by default
+ self.enabled = True
+
# Add link to distro object
self.distro = pakfire.distro #distro.Distribution()
class LocalRepository(RepositoryFactory):
- enabled = True
-
def __init__(self, pakfire):
RepositoryFactory.__init__(self, pakfire, "installed", "Installed packages")