Esempio n. 1
0
def query(command):
    base = get_base()

    enabled_repos = base.repos.listEnabled()

    # Handle any repocontrols passed in with our options

    if 'repos' in command:
        for repo in command['repos']:
            if 'enable' in repo:
                base.repos.enableRepo(repo['enable'])
            if 'disable' in repo:
                base.repos.disableRepo(repo['disable'])

    args = {'name': command['provides']}
    do_nevra = False
    if 'epoch' in command:
        args['epoch'] = command['epoch']
        do_nevra = True
    if 'version' in command:
        args['ver'] = command['version']
        do_nevra = True
    if 'release' in command:
        args['rel'] = command['release']
        do_nevra = True
    if 'arch' in command:
        desired_arch = command['arch']
        args['arch'] = command['arch']
        do_nevra = True
    else:
        desired_arch = getBaseArch()

    obj = None
    if command['action'] == "whatinstalled":
        obj = base.rpmdb
    else:
        obj = base.pkgSack

    # if we are given "name == 1.2.3" then we must use the getProvides() API.
    #   - this means that we ignore arch and version properties when given prco tuples as a package_name
    #   - in order to fix this, something would have to happen where getProvides was called first and
    #     then the result was searchNevra'd.  please be extremely careful if attempting to fix that
    #     since searchNevra does not support prco tuples.
    if any(elem in command['provides'] for elem in r"<=>"):
        # handles flags (<, >, =, etc) and versions, but no wildcareds
        pkgs = obj.getProvides(*string_to_prco_tuple(command['provides']))
    elif do_nevra:
        # now if we're given version or arch properties explicitly, then we do a SearchNevra.
        #  - this means that wildcard version in the package_name with an arch property will not work correctly
        #  - again don't try to fix this just by pushing bugs around in the code, you would need to call
        #    returnPackages and searchProvides and then apply the Nevra filters to those results.
        pkgs = obj.searchNevra(**args)
        if (command['action'] == "whatinstalled") and (not pkgs):
            pkgs = obj.searchNevra(name=args['name'], arch=desired_arch)
    else:
        pats = [command['provides']]
        pkgs = obj.returnPackages(patterns=pats)

        if not pkgs:
            # handles wildcards
            pkgs = obj.searchProvides(command['provides'])

    if not pkgs:
        outpipe.write(command['provides'].split().pop(0) + ' nil nil\n')
        outpipe.flush()
    else:
        # make sure we picked the package with the highest version
        pkgs = base.bestPackagesFromList(pkgs, single_name=True)
        pkg = pkgs.pop(0)
        outpipe.write(
            "%(n)s %(e)s:%(v)s-%(r)s %(a)s\n" % {
                'n': pkg.name,
                'e': pkg.epoch,
                'v': pkg.version,
                'r': pkg.release,
                'a': pkg.arch
            })
        outpipe.flush()

    # Reset any repos we were passed in enablerepo/disablerepo to the original state in enabled_repos
    if 'repos' in command:
        for repo in command['repos']:
            if 'enable' in repo:
                if base.repos.getRepo(repo['enable']) not in enabled_repos:
                    base.repos.disableRepo(repo['enable'])
            if 'disable' in repo:
                if base.repos.getRepo(repo['disable']) in enabled_repos:
                    base.repos.enableRepo(repo['disable'])
Esempio n. 2
0
def query(command):
    base = get_base()

    enabled_repos = base.repos.listEnabled()

    # Handle any repocontrols passed in with our options

    if 'repos' in command:
      for repo in command['repos']:
        if 'enable' in repo:
          base.repos.enableRepo(repo['enable'])
        if 'disable' in repo:
          base.repos.disableRepo(repo['disable'])

    args = { 'name': command['provides'] }
    do_nevra = False
    if 'epoch' in command:
        args['epoch'] = command['epoch']
        do_nevra = True
    if 'version' in command:
        args['ver'] = command['version']
        do_nevra = True
    if 'release' in command:
        args['rel'] = command['release']
        do_nevra = True
    if 'arch' in command:
        desired_arch = command['arch']
        args['arch'] = command['arch']
        do_nevra = True
    else:
        desired_arch = getBaseArch()

    obj = None
    if command['action'] == "whatinstalled":
        obj = base.rpmdb
    else:
        obj = base.pkgSack

    # if we are given "name == 1.2.3" then we must use the getProvides() API.
    #   - this means that we ignore arch and version properties when given prco tuples as a package_name
    #   - in order to fix this, something would have to happen where getProvides was called first and
    #     then the result was searchNevra'd.  please be extremely careful if attempting to fix that
    #     since searchNevra does not support prco tuples.
    if bool(re.search('\\s+', command['provides'])):
        # handles flags (<, >, =, etc) and versions, but no wildcareds
        # raises error for any invalid input like: 'FOO BAR BAZ' 
        pkgs = obj.getProvides(*string_to_prco_tuple(command['provides']))
    elif do_nevra:
        # now if we're given version or arch properties explicitly, then we do a SearchNevra.
        #  - this means that wildcard version in the package_name with an arch property will not work correctly
        #  - again don't try to fix this just by pushing bugs around in the code, you would need to call
        #    returnPackages and searchProvides and then apply the Nevra filters to those results.
        pkgs = obj.searchNevra(**args)
        if (command['action'] == "whatinstalled") and (not pkgs):
          pkgs = obj.searchNevra(name=args['name'], arch=desired_arch)
    else:
        pats = [command['provides']]
        pkgs = obj.returnPackages(patterns=pats)

        if not pkgs:
            # handles wildcards
            pkgs = obj.searchProvides(command['provides'])

    if not pkgs:
        outpipe.write(command['provides'].split().pop(0)+' nil nil\n')
        outpipe.flush()
    else:
        # make sure we picked the package with the highest version
        pkgs = base.bestPackagesFromList(pkgs,single_name=True)
        pkg = pkgs.pop(0)
        outpipe.write("%(n)s %(e)s:%(v)s-%(r)s %(a)s\n" % { 'n': pkg.name, 'e': pkg.epoch, 'v': pkg.version, 'r': pkg.release, 'a': pkg.arch })
        outpipe.flush()

    # Reset any repos we were passed in enablerepo/disablerepo to the original state in enabled_repos
    if 'repos' in command:
      for repo in command['repos']:
        if 'enable' in repo:
          if base.repos.getRepo(repo['enable']) not in enabled_repos:
            base.repos.disableRepo(repo['enable'])
        if 'disable' in repo:
          if base.repos.getRepo(repo['disable']) in enabled_repos:
            base.repos.enableRepo(repo['disable'])