Beispiel #1
0
def get_yumvars():
    # This is not all the yumvars, but hopefully good enough...

    try:
        import dnf, dnf.rpm
    except ImportError:
        pass
    else:
        return {
            'arch': hawkey.detect_arch(),
            'basearch': dnf.rpm.basearch(hawkey.detect_arch()),
            'releasever': dnf.rpm.detect_releasever('/'),
        }

    try:
        import yum, yum.config, rpmUtils
    except ImportError:
        pass
    else:
        return {
            'arch': rpmUtils.arch.getCanonArch(),
            'basearch': rpmUtils.arch.getBaseArch(),
            'releasever': yum.config._getsysver('/',
                ['system-release(releasever)', 'redhat-release']),
        }

    # Probably not going to work but there's not much else we can do...
    return {
        'arch': '$arch',
        'basearch': '$basearch',
        'releasever': '$releasever',
    }
Beispiel #2
0
    def __init__(self, section='main', parser=None):
        # pylint: disable=R0915
        config = libdnf.conf.ConfigMain()
        super(MainConf, self).__init__(config, section, parser)
        self._set_value('pluginpath', [dnf.const.PLUGINPATH], PRIO_DEFAULT)
        self._set_value('pluginconfpath', [dnf.const.PLUGINCONFPATH],
                        PRIO_DEFAULT)
        self.substitutions = dnf.conf.substitutions.Substitutions()
        self.arch = hawkey.detect_arch()
        self._config.system_cachedir().set(PRIO_DEFAULT,
                                           dnf.const.SYSTEM_CACHEDIR)

        # setup different cache and log for non-privileged users
        if dnf.util.am_i_root():
            cachedir = dnf.const.SYSTEM_CACHEDIR
            logdir = '/var/log'
        else:
            try:
                cachedir = logdir = misc.getCacheDir()
            except (IOError, OSError) as e:
                msg = _('Could not set cachedir: {}').format(ucd(e))
                raise dnf.exceptions.Error(msg)

        self._config.cachedir().set(PRIO_DEFAULT, cachedir)
        self._config.logdir().set(PRIO_DEFAULT, logdir)

        # track list of temporary files created
        self.tempfiles = []
Beispiel #3
0
    def __init__(self, section='main', parser=None):
        # pylint: disable=R0915
        config = cfg.ConfigMain()
        super(MainConf, self).__init__(config, section, parser)
        self._get_option('pluginpath')._set([dnf.const.PLUGINPATH],
                                            PRIO_DEFAULT)
        self._get_option('pluginconfpath')._set([dnf.const.PLUGINCONFPATH],
                                                PRIO_DEFAULT)
        self.substitutions = dnf.conf.substitutions.Substitutions()
        self.arch = hawkey.detect_arch()
        self._config.system_cachedir().set(PRIO_DEFAULT,
                                           dnf.const.SYSTEM_CACHEDIR)

        # setup different cache and log for non-priviledged users
        if dnf.util.am_i_root():
            cachedir = dnf.const.SYSTEM_CACHEDIR
            logdir = '/var/log'
        else:
            try:
                cachedir = logdir = misc.getCacheDir()
            except (IOError, OSError) as e:
                msg = _('Could not set cachedir: {}').format(ucd(e))
                raise dnf.exceptions.Error(msg)

        self._config.cachedir().set(PRIO_DEFAULT, cachedir)
        self._config.logdir().set(PRIO_DEFAULT, logdir)
        # TODO move to libdnf
        self.modulesdir = PathOption('/etc/dnf/modules.d', absPath=True)
        # TODO move to libdnf
        self.moduledefaultsdir = PathOption('/etc/dnf/modules.defaults.d',
                                            absPath=True)
Beispiel #4
0
def run(args):
    comparator = args.comparator
    version = None
    release = None

    if args.version:
        if '-' in args.version:
            version, release = args.version.split('-', 1)
        else:
            version = args.version
            release = None

    sack = get_sack()

    subj = dnf.subject.Subject(args.pkg_spec)

    q = subj.get_best_query(sack)
    q_kwargs = {}

    # We only show versions of a package matching a specific architecture, but provide support for matching
    # special 'noarch' packages as well.
    #
    # For example:
    # - if pkg_spec is 'systemd' and detected arch is x86_64, return 'systemd.x86_64' packages.
    # - if pkg_spec is 'systemd.i686', return 'systemd.i686' packages regardless of detected arch.
    # - if pkg_spec is 'tomcat', return 'tomcat.noarch' packages since there is no x86_64 version.
    #
    poss = dnf.util.first(subj.subj.nevra_possibilities_real(sack, allow_globs=True))
    if not poss:
        # no matching packages. we exit success with no output to match dnf-repoquery behavior
        return
    requested_arch = poss.arch

    if requested_arch:
        q_kwargs['arch'] = ['noarch', requested_arch]
    else:
        q_kwargs['arch'] = ['noarch', hawkey.detect_arch()]

    if args.installed:
        q = q.installed()
    else:
        q = q.available()

    if version:
        q_kwargs['version__{}'.format(COMPARATOR_MAP[args.comparator])] = version
    if release:
        q_kwargs['release__{}'.format(COMPARATOR_MAP[args.comparator])] = release

    q = q.filter(**q_kwargs)

    pkgs = dnf.query.latest_limit_pkgs(q, args.latest_limit)
    for pkg in pkgs:
        if args.print_name:
            print '{}-{}:{}-{}.{}'.format(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch)
        else:
            print '{}:{}-{}.{}'.format(pkg.epoch, pkg.version, pkg.release, pkg.arch)
Beispiel #5
0
def query(command):
    sack = get_sack()

    subj = dnf.subject.Subject(command['provides'])
    q = subj.get_best_query(sack, with_provides=True)

    if command['action'] == "whatinstalled":
        q = q.installed()

    if command['action'] == "whatavailable":
        q = q.available()

    if 'epoch' in command:
        # We assume that any glob is "*" so just omit the filter since the dnf libraries have no
        # epoch__glob filter.  That means "?" wildcards in epochs will fail.  The workaround is to
        # not use the version filter here but to put the version with all the globs in the package name.
        if not dnf.util.is_glob_pattern(command['epoch']):
            q = q.filterm(epoch=int(command['epoch']))
    if 'version' in command:
        if dnf.util.is_glob_pattern(command['version']):
            q = q.filterm(version__glob=command['version'])
        else:
            q = q.filterm(version=command['version'])
    if 'release' in command:
        if dnf.util.is_glob_pattern(command['release']):
            q = q.filterm(release__glob=command['release'])
        else:
            q = q.filterm(release=command['release'])

    if 'arch' in command:
        if dnf.util.is_glob_pattern(command['arch']):
            q = q.filterm(arch__glob=command['arch'])
        else:
            q = q.filterm(arch=command['arch'])

    # only apply the default arch query filter if it returns something
    archq = q.filter(arch=['noarch', hawkey.detect_arch()])
    if len(archq.run()) > 0:
        q = archq

    pkgs = q.latest(1).run()

    if not pkgs:
        outpipe.write('{} nil nil\n'.format(
            command['provides'].split().pop(0)))
        outpipe.flush()
    else:
        # make sure we picked the package with the highest version
        pkgs.sort
        pkg = pkgs.pop()
        outpipe.write('{} {}:{}-{} {}\n'.format(pkg.name, pkg.epoch,
                                                pkg.version, pkg.release,
                                                pkg.arch))
        outpipe.flush()
Beispiel #6
0
    def _configure_efi_bootloader(self, isodir):
        """Set up the configuration for an EFI bootloader"""
        if self.__copy_efi_files(isodir):
            shutil.rmtree(isodir + "/EFI")
            logging.warning("Failed to copy EFI files, no EFI Support will be included.")
            return

        cfg = self.__get_basic_efi_config(isolabel = self.fslabel,
                                          timeout = self._timeout)
        cfg += self.__get_efi_image_stanzas(isodir, self.name)

        cfgf = open(isodir + "/EFI/BOOT/grub.cfg", "w")
        cfgf.write(cfg)
        cfgf.close()

        # first gen mactel machines get the bootloader name wrong apparently
        if dnf.rpm.basearch(hawkey.detect_arch()) == "i386":
            os.link(isodir + "/EFI/BOOT/BOOT%s.EFI" % (self.efiarch),
                    isodir + "/EFI/BOOT/BOOT.EFI")
Beispiel #7
0
 def _varSubstitute(option):
     # takes a variable and substitutes like dnf configs do
     arch = hawkey.detect_arch()
     option = option.replace("$basearch", dnf.rpm.basearch(arch))
     option = option.replace("$arch", arch)
     # If the url includes $releasever substitute user's value or
     # current system's version.
     if option.find("$releasever") > -1:
         if self.releasever:
             option = option.replace("$releasever", self.releasever)
         else:
             try:
                 detected_releasever = dnf.rpm.detect_releasever("/")
             except dnf.exceptions.Error:
                 detected_releasever = None
             if detected_releasever:
                 option = option.replace("$releasever", detected_releasever)
             else:
                 raise CreatorError("$releasever in repo url, but no releasever set")
     return option
Beispiel #8
0
def query(command):
    sack = get_sack()

    subj = dnf.subject.Subject(command['provides'])
    q = subj.get_best_query(sack, with_provides=True)

    if command['action'] == "whatinstalled":
        q = q.installed()

    if command['action'] == "whatavailable":
        q = q.available()

    if 'epoch' in command:
        q = q.filterm(epoch=int(command['epoch']))
    if 'version' in command:
        q = q.filterm(version__glob=command['version'])
    if 'release' in command:
        q = q.filterm(release__glob=command['release'])

    if 'arch' in command:
        q = q.filterm(arch__glob=command['arch'])

    # only apply the default arch query filter if it returns something
    archq = q.filter(arch=['noarch', hawkey.detect_arch()])
    if len(archq.run()) > 0:
        q = archq

    pkgs = q.latest(1).run()

    if not pkgs:
        outpipe.write('{} nil nil\n'.format(
            command['provides'].split().pop(0)))
        outpipe.flush()
    else:
        # make sure we picked the package with the highest version
        pkgs.sort
        pkg = pkgs.pop()
        outpipe.write('{} {}:{}-{} {}\n'.format(pkg.name, pkg.epoch,
                                                pkg.version, pkg.release,
                                                pkg.arch))
        outpipe.flush()
Beispiel #9
0
    def init(self):
        print("Loading dnf repos...")

        arch = hawkey.detect_arch()

        to_pop = []
        for key in self._dnf_objects:
            print(f"Loading {key}...")
            try:
                self._dnf_objects[key].conf.gpgcheck = False
                self._dnf_objects[key].conf.substitutions['arch'] = arch
                self._dnf_objects[key].conf.substitutions[
                    'basearch'] = dnf.rpm.basearch(arch)
                if key == "fedora" or key == "rpmfusion":
                    self._dnf_objects[key].conf.substitutions[
                        'releasever'] = '33'
                if key == "openmandriva":
                    self._dnf_objects[key].conf.substitutions[
                        'releasever'] = '4.1'
                if key == "mageia":
                    self._dnf_objects[key].conf.substitutions[
                        'releasever'] = '7'
                self._dnf_objects[key].conf.zchunk = False
                self._dnf_objects[key].conf.reposdir = join(
                    dirname(__file__), key)
                self._dnf_objects[key].conf.cachedir = join(
                    dirname(__file__), "cache", key)
                self._dnf_objects[key].read_all_repos()
                self._dnf_objects[key].fill_sack(load_system_repo=False)
            except Exception as e:
                print(f"Failed to load {key}!")
                print(f"Error:\n>>>\t{e}")
                to_pop.append(key)
                continue
            print(f"Loaded {key}!")

        for i in to_pop:
            self._dnf_objects.pop(i)

        print("Dnf repos loaded!")
Beispiel #10
0
 def _varSubstitute(option):
     # takes a variable and substitutes like dnf configs do
     arch = hawkey.detect_arch()
     option = option.replace("$basearch", dnf.rpm.basearch(arch))
     option = option.replace("$arch", arch)
     # If the url includes $releasever substitute user's value or
     # current system's version.
     if option.find("$releasever") > -1:
         if self.releasever:
             option = option.replace("$releasever", self.releasever)
         else:
             try:
                 detected_releasever = dnf.rpm.detect_releasever("/")
             except dnf.exceptions.Error:
                 detected_releasever = None
             if detected_releasever:
                 option = option.replace("$releasever",
                                         detected_releasever)
             else:
                 raise CreatorError(
                     "$releasever in repo url, but no releasever set")
     return option
Beispiel #11
0
    def __init__(self, section='main', parser=None):
        # pylint: disable=R0915
        config = libdnf.conf.ConfigMain()
        super(MainConf, self).__init__(config, section, parser)
        self._set_value('pluginpath', [dnf.const.PLUGINPATH], PRIO_DEFAULT)
        self._set_value('pluginconfpath', [dnf.const.PLUGINCONFPATH], PRIO_DEFAULT)
        self.substitutions = dnf.conf.substitutions.Substitutions()
        self.arch = hawkey.detect_arch()
        self._config.system_cachedir().set(PRIO_DEFAULT, dnf.const.SYSTEM_CACHEDIR)

        # setup different cache and log for non-priviledged users
        if dnf.util.am_i_root():
            cachedir = dnf.const.SYSTEM_CACHEDIR
            logdir = '/var/log'
        else:
            try:
                cachedir = logdir = misc.getCacheDir()
            except (IOError, OSError) as e:
                msg = _('Could not set cachedir: {}').format(ucd(e))
                raise dnf.exceptions.Error(msg)

        self._config.cachedir().set(PRIO_DEFAULT, cachedir)
        self._config.logdir().set(PRIO_DEFAULT, logdir)
Beispiel #12
0
def query(command):
    sack = get_sack()

    subj = dnf.subject.Subject(command['provides'])
    q = subj.get_best_query(sack, with_provides=True)

    if command['action'] == "whatinstalled":
        q = q.installed()

    if command['action'] == "whatavailable":
        q = q.available()

    if 'epoch' in command:
        q = q.filterm(epoch=int(command['epoch']))
    if 'version' in command:
        q = q.filterm(version__glob=command['version'])
    if 'release' in command:
        q = q.filterm(release__glob=command['release'])

    if 'arch' in command:
        q = q.filterm(arch__glob=command['arch'])

    # only apply the default arch query filter if it returns something
    archq = q.filter(arch=[ 'noarch', hawkey.detect_arch() ])
    if len(archq.run()) > 0:
        q = archq

    pkgs = dnf.query.latest_limit_pkgs(q, 1)

    if not pkgs:
        sys.stdout.write('{} nil nil\n'.format(command['provides'].split().pop(0)))
    else:
        # make sure we picked the package with the highest version
        pkgs.sort
        pkg = pkgs.pop()
        sys.stdout.write('{} {}:{}-{} {}\n'.format(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch))
Beispiel #13
0
 def __init__(self):
     super(Substitutions, self).__init__()
     arch = hawkey.detect_arch()
     self["arch"] = arch
     self["basearch"] = dnf.rpm.basearch(arch)
     self._update_from_env()
Beispiel #14
0
 def efiarch(self):
     if not self._efiarch:
         # for most things, we want them named boot$efiarch
         efiarch = {"aarch64": "AA64"}
         self._efiarch = efiarch[dnf.rpm.basearch(hawkey.detect_arch())]
     return self._efiarch
Beispiel #15
0
import dnf
import fnmatch
import functools
import hawkey
import json
import logging
import os
import rpm
import subprocess

from Pharlap import kerneldetection
from Pharlap.dnfcache import DNFCache
from Pharlap.hwdata import PCI, USB

db = dnf.Base()
system_architecture = dnf.rpm.basearch( hawkey.detect_arch() )

device_pci = PCI()
device_usb = USB()


def load_modalias_map():
    maps = ['./pharlap-modalias.map',
            '/usr/share/pharlap/pharlap-modalias.map']

    modalias_map = {}

    for m in maps:
        try:
            raw_data = open(m)
            modalias_map = json.load(raw_data)
Beispiel #16
0
 def __init__(self):
     super(Substitutions, self).__init__()
     arch = hawkey.detect_arch()
     self['arch'] = arch
     self['basearch'] = dnf.rpm.basearch(arch)
     self._update_from_env()
Beispiel #17
0
 def efiarch(self):
     if not self._efiarch:
         # for most things, we want them named boot$efiarch
         efiarch = {"i386": "IA32", "x86_64": "X64"}
         self._efiarch = efiarch[dnf.rpm.basearch(hawkey.detect_arch())]
     return self._efiarch
Beispiel #18
0
def run(args):
    comparator = args.comparator
    version = None
    release = None

    if args.version:
        if '-' in args.version:
            version, release = args.version.split('-', 1)
        else:
            version = args.version
            release = None

    sack = get_sack()

    subj = dnf.subject.Subject(args.pkg_spec)

    q = subj.get_best_query(sack)
    q_kwargs = {}

    # We only show versions of a package matching a specific architecture, but provide support for matching
    # special 'noarch' packages as well.
    #
    # For example:
    # - if pkg_spec is 'systemd' and detected arch is x86_64, return 'systemd.x86_64' packages.
    # - if pkg_spec is 'systemd.i686', return 'systemd.i686' packages regardless of detected arch.
    # - if pkg_spec is 'tomcat', return 'tomcat.noarch' packages since there is no x86_64 version.
    #
    poss = dnf.util.first(
        subj.subj.nevra_possibilities_real(sack, allow_globs=True))
    if not poss:
        # no matching packages. we exit success with no output to match dnf-repoquery behavior
        return
    requested_arch = poss.arch

    if requested_arch:
        q_kwargs['arch'] = ['noarch', requested_arch]
    else:
        q_kwargs['arch'] = ['noarch', hawkey.detect_arch()]

    if args.installed:
        q = q.installed()
    else:
        q = q.available()

    if version:
        q_kwargs['version__{}'.format(
            COMPARATOR_MAP[args.comparator])] = version
    if release:
        q_kwargs['release__{}'.format(
            COMPARATOR_MAP[args.comparator])] = release

    q = q.filter(**q_kwargs)

    pkgs = dnf.query.latest_limit_pkgs(q, args.latest_limit)
    for pkg in pkgs:
        if args.print_name:
            print '{}-{}:{}-{}.{}'.format(pkg.name, pkg.epoch, pkg.version,
                                          pkg.release, pkg.arch)
        else:
            print '{}:{}-{}.{}'.format(pkg.epoch, pkg.version, pkg.release,
                                       pkg.arch)
Beispiel #19
0
                                                name=self.name,
                                                timeout=self._timeout * 100)

        #
        # FIXME: build 'netboot' images with kernel+initrd, like mk-images.ppc
        #


class ppc64LiveImageCreator(ppcLiveImageCreator):
    def _get_excluded_packages(self):
        # FIXME:
        #   while kernel.ppc and kernel.ppc64 co-exist,
        #   we can't have both
        return ["kernel.ppc"] + \
               ppcLiveImageCreator._get_excluded_packages(self)


arch = dnf.rpm.basearch(hawkey.detect_arch())
if arch in ("i386", "x86_64"):
    LiveImageCreator = x86LiveImageCreator
elif arch in ("ppc", ):
    LiveImageCreator = ppcLiveImageCreator
elif arch in ("ppc64", ):
    LiveImageCreator = ppc64LiveImageCreator
elif arch.startswith(("arm", "aarch64")):
    LiveImageCreator = LiveImageCreatorBase
elif arch in ("riscv64", ):
    LiveImageCreator = LiveImageCreatorBase
else:
    raise CreatorError("Architecture not supported!")
Beispiel #20
0
    def __init__(self, section='main', parser=None):
        # pylint: disable=R0915
        super(MainConf, self).__init__(section, parser)
        self.substitutions = dnf.conf.substitutions.Substitutions()
        self.arch = hawkey.detect_arch()

        # setup different cache and log for non-priviledged users
        if dnf.util.am_i_root():
            cachedir = dnf.const.SYSTEM_CACHEDIR
            logdir = '/var/log'
        else:
            try:
                cachedir = logdir = misc.getCacheDir()
            except (IOError, OSError) as e:
                logger.critical(_('Could not set cachedir: %s'), ucd(e))

        self._add_option('debuglevel', IntOption(2, range_min=0,
                                                 range_max=10))  # :api
        self._add_option('errorlevel', IntOption(2, range_min=0, range_max=10))

        self._add_option('installroot', PathOption('/', abspath=True))  # :api
        self._add_option('config_file_path',
                         PathOption(dnf.const.CONF_FILENAME))  # :api
        self._add_option('plugins', BoolOption(True))
        self._add_option('pluginpath',
                         ListOption([dnf.const.PLUGINPATH]))  # :api
        self._add_option('pluginconfpath',
                         ListOption([dnf.const.PLUGINCONFPATH]))  # :api
        self._add_option('persistdir',
                         PathOption(dnf.const.PERSISTDIR))  # :api
        self._add_option('recent', IntOption(7, range_min=0))
        self._add_option('retries', PositiveIntOption(10, names_of_0=["0"]))
        self._add_option('reset_nice', BoolOption(True))

        self._add_option('cachedir', PathOption(cachedir))  # :api
        self._add_option('system_cachedir',
                         PathOption(dnf.const.SYSTEM_CACHEDIR))  # :api

        self._add_option('keepcache', BoolOption(False))
        self._add_option('logdir', Option(logdir))  # :api
        self._add_option('reposdir',
                         ListOption([
                             '/etc/yum.repos.d', '/etc/yum/repos.d',
                             '/etc/distro.repos.d'
                         ]))  # :api

        self._add_option('debug_solver', BoolOption(False))

        self._add_option('excludepkgs', ListAppendOption())
        self._add_option('includepkgs', ListAppendOption())
        self._add_option('exclude', self._get_option('excludepkgs'))
        # ^ compatibility with yum
        self._add_option('fastestmirror', BoolOption(False))
        self._add_option('proxy',
                         UrlOption(schemes=('http', 'ftp', 'https', 'socks5',
                                            'socks5h', 'socks4', 'socks4a'),
                                   allow_none=True))  # :api
        self._add_option('proxy_username', Option())  # :api
        self._add_option('proxy_password', Option())  # :api
        self._add_option('protected_packages',
                         ListOption("dnf glob:/etc/yum/protected.d/*.conf " \
                                    "glob:/etc/dnf/protected.d/*.conf")) #:api
        self._add_option('username', Option())  # :api
        self._add_option('password', Option())  # :api
        self._add_option('installonlypkgs',
                         ListAppendOption(dnf.const.INSTALLONLYPKGS))
        self._add_option('group_package_types',
                         ListOption(dnf.const.GROUP_PACKAGE_TYPES))
        # NOTE: If you set this to 2, then because it keeps the current
        # kernel it means if you ever install an "old" kernel it'll get rid
        # of the newest one so you probably want to use 3 as a minimum
        # ... if you turn it on.
        self._add_option('installonly_limit',
                         PositiveIntOption(0,
                                           range_min=2,
                                           names_of_0=["0", "<off>"]))  # :api
        self._add_option('tsflags', ListAppendOption())  # :api

        self._add_option('assumeyes', BoolOption(False))  # :api
        self._add_option('assumeno', BoolOption(False))
        self._add_option('check_config_file_age', BoolOption(True))
        self._add_option('defaultyes', BoolOption(False))
        self._add_option('diskspacecheck', BoolOption(True))
        self._add_option('gpgcheck', BoolOption(False))
        self._add_option('repo_gpgcheck', BoolOption(False))
        self._add_option('localpkg_gpgcheck', BoolOption(False))
        self._add_option('obsoletes', BoolOption(True))
        self._add_option('showdupesfromrepos', BoolOption(False))
        self._add_option('enabled', BoolOption(True))
        self._add_option('enablegroups', BoolOption(True))
        self._add_option('exit_on_lock', BoolOption(False))

        self._add_option('bandwidth', BytesOption(0))
        self._add_option('minrate', BytesOption(1000))
        self._add_option(
            'ip_resolve',
            CaselessSelectionOption(choices=('ipv4', 'ipv6', 'whatever'),
                                    mapper={
                                        '4': 'ipv4',
                                        '6': 'ipv6'
                                    }))
        self._add_option('throttle', ThrottleOption(0))
        self._add_option('timeout', SecondsOption(30))
        self._add_option('max_parallel_downloads', IntOption(None,
                                                             range_min=1))

        self._add_option('metadata_expire',
                         SecondsOption(60 * 60 * 48))  # 48 hours
        self._add_option('metadata_timer_sync',
                         SecondsOption(60 * 60 * 3))  #  3 hours
        self._add_option('disable_excludes', ListOption())
        self._add_option('multilib_policy',
                         SelectionOption('best',
                                         choices=('best', 'all')))  # :api
        self._add_option('best', BoolOption(False))  # :api
        self._add_option('install_weak_deps', BoolOption(True))
        self._add_option('bugtracker_url', Option(dnf.const.BUGTRACKER))

        self._add_option(
            'color',
            SelectionOption('auto',
                            choices=('auto', 'never', 'always'),
                            mapper={
                                'on': 'always',
                                'yes': 'always',
                                '1': 'always',
                                'true': 'always',
                                'off': 'never',
                                'no': 'never',
                                '0': 'never',
                                'false': 'never',
                                'tty': 'auto',
                                'if-tty': 'auto'
                            }))
        self._add_option('color_list_installed_older', Option('bold'))
        self._add_option('color_list_installed_newer', Option('bold,yellow'))
        self._add_option('color_list_installed_reinstall', Option('normal'))
        self._add_option('color_list_installed_extra', Option('bold,red'))
        self._add_option('color_list_available_upgrade', Option('bold,blue'))
        self._add_option('color_list_available_downgrade', Option('dim,cyan'))
        self._add_option('color_list_available_reinstall',
                         Option('bold,underline,green'))
        self._add_option('color_list_available_install', Option('normal'))
        self._add_option('color_update_installed', Option('normal'))
        self._add_option('color_update_local', Option('bold'))
        self._add_option('color_update_remote', Option('normal'))
        self._add_option('color_search_match', Option('bold'))

        self._add_option('sslcacert', PathOption())  # :api
        self._add_option('sslverify', BoolOption(True))  # :api
        self._add_option('sslclientcert', Option())  # :api
        self._add_option('sslclientkey', Option())  # :api
        self._add_option('deltarpm', BoolOption(True))
        self._add_option('deltarpm_percentage',
                         PositiveIntOption(75, names_of_0=["0", "<off>"]))

        self._add_option('history_record', BoolOption(True))
        self._add_option('history_record_packages', ListOption(['dnf', 'rpm']))

        self._add_option('rpmverbosity', Option('info'))
        self._add_option('strict', BoolOption(True))  # :api
        self._add_option('skip_broken',
                         BoolOption(False))  # :yum-compatibility
        self._add_option('autocheck_running_kernel',
                         BoolOption(True))  # :yum-compatibility
        self._add_option('clean_requirements_on_remove', BoolOption(True))
        self._add_option(
            'history_list_view',
            SelectionOption('commands',
                            choices=('single-user-commands', 'users',
                                     'commands'),
                            mapper={
                                'cmds': 'commands',
                                'default': 'commands'
                            }))
        self._add_option('upgrade_group_objects_upgrade',
                         BoolOption(True))  # :api

        # runtime only options
        self._add_option('downloadonly', BoolOption(False, runtimeonly=True))
        self._add_option('ignorearch', BoolOption(False))
Beispiel #21
0
    def __init__(self, section='main', parser=None):
        # pylint: disable=R0915
        super(MainConf, self).__init__(section, parser)
        self.substitutions = dnf.conf.substitutions.Substitutions()
        self.arch = hawkey.detect_arch()

        # setup different cache and log for non-priviledged users
        if dnf.util.am_i_root():
            cachedir = dnf.const.SYSTEM_CACHEDIR
            logdir = '/var/log'
        else:
            try:
                cachedir = logdir = misc.getCacheDir()
            except (IOError, OSError) as e:
                logger.critical(_('Could not set cachedir: %s'), ucd(e))

        self._add_option('debuglevel',
                         IntOption(2, range_min=0, range_max=10)) # :api
        self._add_option('errorlevel', IntOption(2, range_min=0, range_max=10))

        self._add_option('installroot', PathOption('/', abspath=True)) # :api
        self._add_option('config_file_path',
                         PathOption(dnf.const.CONF_FILENAME)) # :api
        self._add_option('plugins', BoolOption(True))
        self._add_option('pluginpath', ListOption([dnf.const.PLUGINPATH])) # :api
        self._add_option('pluginconfpath',
                         ListOption([dnf.const.PLUGINCONFPATH])) # :api
        self._add_option('persistdir', PathOption(dnf.const.PERSISTDIR)) # :api
        self._add_option('transformdb', BoolOption(True))  # :api
        self._add_option('recent', IntOption(7, range_min=0))
        self._add_option('retries', PositiveIntOption(10, names_of_0=["0"]))
        self._add_option('reset_nice', BoolOption(True))

        self._add_option('cachedir', PathOption(cachedir)) # :api
        self._add_option('system_cachedir',
                         PathOption(dnf.const.SYSTEM_CACHEDIR)) # :api
        self._add_option('cacheonly', BoolOption(False))

        self._add_option('keepcache', BoolOption(False))
        self._add_option('logdir', Option(logdir)) # :api
        self._add_option('reposdir', ListOption(['/etc/yum.repos.d',
                                                 '/etc/yum/repos.d',
                                                 '/etc/distro.repos.d'])) # :api

        self._add_option('debug_solver', BoolOption(False))

        self._add_option('excludepkgs', ListAppendOption())
        self._add_option('includepkgs', ListAppendOption())
        self._add_option('exclude', self._get_option('excludepkgs'))
            # ^ compatibility with yum
        self._add_option('fastestmirror', BoolOption(False))
        self._add_option('proxy', UrlOption(schemes=('http', 'ftp', 'https',
                                                     'socks5', 'socks5h',
                                                     'socks4', 'socks4a'),
                                            allow_none=True)) # :api
        self._add_option('proxy_username', Option()) # :api
        self._add_option('proxy_password', Option()) # :api
        self._add_option('protected_packages',
                         ListOption("dnf glob:/etc/yum/protected.d/*.conf " \
                                    "glob:/etc/dnf/protected.d/*.conf")) #:api
        self._add_option('username', Option()) # :api
        self._add_option('password', Option()) # :api
        self._add_option('installonlypkgs', ListAppendOption(dnf.const.INSTALLONLYPKGS))
        self._add_option('group_package_types', ListOption(dnf.const.GROUP_PACKAGE_TYPES))
            # NOTE: If you set this to 2, then because it keeps the current
            # kernel it means if you ever install an "old" kernel it'll get rid
            # of the newest one so you probably want to use 3 as a minimum
            # ... if you turn it on.
        self._add_option('installonly_limit',
                         PositiveIntOption(3, range_min=2, names_of_0=["0", "<off>"]))  # :api
        self._add_option('tsflags', ListAppendOption())  # :api

        self._add_option('assumeyes', BoolOption(False)) # :api
        self._add_option('assumeno', BoolOption(False))
        self._add_option('check_config_file_age', BoolOption(True))
        self._add_option('defaultyes', BoolOption(False))
        self._add_option('diskspacecheck', BoolOption(True))
        self._add_option('gpgcheck', BoolOption(False))
        self._add_option('repo_gpgcheck', BoolOption(False))
        self._add_option('localpkg_gpgcheck', BoolOption(False))
        self._add_option('obsoletes', BoolOption(True))
        self._add_option('showdupesfromrepos', BoolOption(False))
        self._add_option('enabled', BoolOption(True))
        self._add_option('enablegroups', BoolOption(True))
        self._add_option('exit_on_lock', BoolOption(False))

        self._add_option('bandwidth', BytesOption(0))
        self._add_option('minrate', BytesOption(1000))
        self._add_option('ip_resolve',
                         CaselessSelectionOption(choices=('ipv4', 'ipv6',
                                                          'whatever'),
                                                 mapper={'4': 'ipv4',
                                                         '6': 'ipv6'}))
        self._add_option('throttle', ThrottleOption(0))
        self._add_option('timeout', SecondsOption(30))
        self._add_option('max_parallel_downloads', IntOption(None, range_min=1))

        self._add_option('metadata_expire',
                         SecondsOption(60 * 60 * 48))    # 48 hours
        self._add_option('metadata_timer_sync',
                         SecondsOption(60 * 60 * 3)) #  3 hours
        self._add_option('disable_excludes', ListOption())
        self._add_option('multilib_policy',
                         SelectionOption('best', choices=('best', 'all'))) # :api
        self._add_option('best', BoolOption(False)) # :api
        self._add_option('install_weak_deps', BoolOption(True))
        self._add_option('bugtracker_url', Option(dnf.const.BUGTRACKER))

        self._add_option('color',
                         SelectionOption('auto',
                                         choices=('auto', 'never', 'always'),
                                         mapper={'on': 'always', 'yes' : 'always',
                                                 '1' : 'always', 'true': 'always',
                                                 'off': 'never', 'no':   'never',
                                                 '0':   'never', 'false': 'never',
                                                 'tty': 'auto', 'if-tty': 'auto'})
                        )
        self._add_option('color_list_installed_older', Option('bold'))
        self._add_option('color_list_installed_newer', Option('bold,yellow'))
        self._add_option('color_list_installed_reinstall', Option('normal'))
        self._add_option('color_list_installed_extra', Option('bold,red'))
        self._add_option('color_list_available_upgrade', Option('bold,blue'))
        self._add_option('color_list_available_downgrade', Option('dim,cyan'))
        self._add_option('color_list_available_reinstall',
                         Option('bold,underline,green'))
        self._add_option('color_list_available_install', Option('normal'))
        self._add_option('color_update_installed', Option('normal'))
        self._add_option('color_update_local', Option('bold'))
        self._add_option('color_update_remote', Option('normal'))
        self._add_option('color_search_match', Option('bold'))

        self._add_option('sslcacert', PathOption()) # :api
        self._add_option('sslverify', BoolOption(True)) # :api
        self._add_option('sslclientcert', Option()) # :api
        self._add_option('sslclientkey', Option()) # :api
        self._add_option('deltarpm', BoolOption(True))
        self._add_option('deltarpm_percentage',
                         PositiveIntOption(75, names_of_0=["0", "<off>"]))

        self._add_option('history_record', BoolOption(True))
        self._add_option('history_record_packages', ListOption(['dnf', 'rpm']))

        self._add_option('rpmverbosity', Option('info'))
        self._add_option('strict', BoolOption(True)) # :api
        self._add_option('skip_broken', BoolOption(False))  # :yum-compatibility
        self._add_option('autocheck_running_kernel', BoolOption(True))  # :yum-compatibility
        self._add_option('clean_requirements_on_remove', BoolOption(True))
        self._add_option('history_list_view',
                         SelectionOption('commands',
                                         choices=('single-user-commands',
                                                  'users', 'commands'),
                                         mapper={'cmds': 'commands',
                                                 'default': 'commands'}))
        self._add_option('upgrade_group_objects_upgrade',
                         BoolOption(True))  # :api
        self._add_option('destdir', PathOption(None))
        self._add_option('comment', Option())
        # runtime only options
        self._add_option('downloadonly', BoolOption(False, runtimeonly=True))
        self._add_option('ignorearch', BoolOption(False))
        self._add_option('cacheonly', BoolOption(False))
Beispiel #22
0
import dnf
import fnmatch
import functools
import hawkey
import json
import logging
import os
import rpm
import subprocess

from Pharlap import kerneldetection
from Pharlap.dnfcache import DNFCache
from Pharlap.hwdata import PCI, USB

db = dnf.Base()
system_architecture = dnf.rpm.basearch(hawkey.detect_arch())

device_pci = PCI()
device_usb = USB()


def load_modalias_map():
    maps = [
        './pharlap-modalias.map', '/usr/share/pharlap/pharlap-modalias.map'
    ]

    modalias_map = {}

    for m in maps:
        try:
            raw_data = open(m)