def available_version(name): ''' The available version of the package in the repository CLI Example:: salt '*' pkg.available_version <package name> ''' yb = yum.YumBase() # look for available packages only, if package is already installed with # latest version it will not show up here. If we want to use wildcards # here we can, but for now its exact match only. versions_list = [] for pkgtype in ['available', 'updates']: pl = yb.doPackageLists(pkgtype) exactmatch, matched, unmatched = yum.packages.parsePackages(pl, [name]) # build a list of available packages from either available or updates # this will result in a double match for a package that is already # installed. Maybe we should just return the value if we get a hit # on available, and only iterate though updates if we don't.. for pkg in exactmatch: if pkg.arch == getBaseArch() or pkg.arch == 'noarch': versions_list.append('-'.join([pkg.version, pkg.release])) if len(versions_list) == 0: # if versions_list is empty return empty string. It may make sense # to also check if a package is installed and on latest version # already and return a message saying 'up to date' or something along # those lines. return '' # remove the duplicate items from the list and return the first one return list(set(versions_list))[0]
def list_upgrades(refresh=True): ''' Check whether or not an upgrade is available for all packages CLI Example:: salt '*' pkg.list_upgrades ''' # Catch both boolean input from state and string input from CLI if refresh is True or str(refresh).lower() == 'true': refresh_db() pkgs = list_pkgs() yumbase = yum.YumBase() versions_list = {} for pkgtype in ['updates']: pkglist = yumbase.doPackageLists(pkgtype) for pkg in pkgs: exactmatch, matched, unmatched = yum.packages.parsePackages( pkglist, [pkg]) for pkg in exactmatch: if pkg.arch == getBaseArch() or pkg.arch == 'noarch': versions_list[pkg['name']] = '-'.join( [pkg['version'], pkg['release']]) return versions_list
def _p2sk(pkg, state=None): """ Take a pkg and return the key for it's state lookup. """ if state is None: state = pkg.state # Arch is needed so multilib. works, dito. getBaseArch() -- (so .i586 # => .i686 moves are seen) return (pkg.name, getBaseArch(pkg.arch), state)
def list_upgrades(refresh=True): ''' Check whether or not an upgrade is available for all packages CLI Example:: salt '*' pkg.list_upgrades ''' # Catch both boolean input from state and string input from CLI if refresh is True or str(refresh).lower() == 'true': refresh_db() pkgs = list_pkgs() yumbase = yum.YumBase() versions_list = {} for pkgtype in ['updates']: pkglist = yumbase.doPackageLists(pkgtype) for pkg in pkgs: exactmatch, matched, unmatched = yum.packages.parsePackages( pkglist, [pkg] ) for pkg in exactmatch: if pkg.arch == getBaseArch() or pkg.arch == 'noarch': versions_list[pkg['name']] = '-'.join( [pkg['version'], pkg['release']] ) return versions_list
def setup_yum(url=None, release=None, arch=None): my = yum.YumBase() basearch = getBaseArch() cachedir = tempfile.mkdtemp(dir='/tmp', prefix='critpath-') if arch is None: arch = basearch elif arch != basearch: # try to force yum to use the supplied arch rather than the host arch fakearch = {'i386':'i686', 'x86_64':'x86_64', 'ppc':'ppc64', 'armhfp':'armv7hl'} my.preconf.arch = fakearch[arch] my.conf.cachedir = cachedir my.conf.installroot = cachedir my.repos.disableRepo('*') my.add_enable_repo('critpath-repo-%s' % arch, baseurls=[url+releasepath[release]]) print "adding critpath-repo-%s at %s" % (arch, url+releasepath[release]) if updatepath[release]: my.add_enable_repo('critpath-repo-updates-%s' % arch, baseurls=[url+updatepath[release]]) return (my, cachedir)
def list_upgrades(*args): ''' Check whether or not an upgrade is available for all packages CLI Example:: salt '*' pkg.list_upgrades ''' pkgs=list_pkgs() yb=yum.YumBase() versions_list={} for pkgtype in ['updates']: pl=yb.doPackageLists(pkgtype) for pkg in pkgs: exactmatch, matched, unmatched = yum.packages.parsePackages(pl, [pkg]) for pkg in exactmatch: if pkg.arch == getBaseArch(): versions_list[pkg['name']] = '-'.join([pkg['version'],pkg['release']]) return versions_list
def list_upgrades(*args): ''' Check whether or not an upgrade is available for all packages CLI Example:: salt '*' pkg.list_upgrades ''' pkgs = list_pkgs() yb = yum.YumBase() versions_list = {} for pkgtype in ['updates']: pl = yb.doPackageLists(pkgtype) for pkg in pkgs: exactmatch, matched, unmatched = yum.packages.parsePackages( pl, [pkg]) for pkg in exactmatch: if pkg.arch == getBaseArch() or pkg.arch == 'noarch': versions_list[pkg['name']] = '-'.join( [pkg['version'], pkg['release']]) return versions_list
def available_version(*names): ''' Return the latest version of the named package available for upgrade or installation. If more than one package name is specified, a dict of name/version pairs is returned. If the latest version of a given package is already installed, an empty string will be returned for that package. CLI Example:: salt '*' pkg.available_version <package name> salt '*' pkg.available_version <package1> <package2> <package3> ... ''' if len(names) == 0: return '' ret = {} # Initialize the dict with empty strings for name in names: ret[name] = '' yumbase = yum.YumBase() # look for available packages only, if package is already installed with # latest version it will not show up here. If we want to use wildcards # here we can, but for now its exact match only. for pkgtype in ['available', 'updates']: pkglist = yumbase.doPackageLists(pkgtype) exactmatch, matched, unmatched = yum.packages.parsePackages( pkglist, names ) for pkg in exactmatch: if pkg.name in ret \ and (pkg.arch == getBaseArch() or pkg.arch == 'noarch'): ret[pkg.name] = '-'.join([pkg.version, pkg.release]) # Return a string if only one package name passed if len(names) == 1: return ret[names[0]] return ret
def available_version(*names): ''' Return the latest version of the named package available for upgrade or installation. If more than one package name is specified, a dict of name/version pairs is returned. If the latest version of a given package is already installed, an empty string will be returned for that package. CLI Example:: salt '*' pkg.available_version <package name> salt '*' pkg.available_version <package1> <package2> <package3> ... ''' if len(names) == 0: return '' ret = {} # Initialize the dict with empty strings for name in names: ret[name] = '' yumbase = yum.YumBase() # look for available packages only, if package is already installed with # latest version it will not show up here. If we want to use wildcards # here we can, but for now its exact match only. for pkgtype in ['available', 'updates']: pkglist = yumbase.doPackageLists(pkgtype) exactmatch, matched, unmatched = yum.packages.parsePackages( pkglist, names) for pkg in exactmatch: if pkg.name in ret \ and (pkg.arch == getBaseArch() or pkg.arch == 'noarch'): ret[pkg.name] = '-'.join([pkg.version, pkg.release]) # Return a string if only one package name passed if len(names) == 1: return ret[names[0]] return ret
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'])
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'])
def __init__(self, buildarch): self.buildarch = buildarch self.basearch = getBaseArch(buildarch) self.libdir = "lib64" if self.basearch in self.lib64_arches else "lib" self.bcj = self.bcj_arch.get(self.basearch)
parser = optparse.OptionParser(usage="%%prog [options] [%s]" % '|'.join(releases)) parser.add_option("--nvr", action='store_true', default=False, help="output full NVR instead of just package name") parser.add_option("-a", "--arches", default=','.join(base_arches), help="arches to evaluate (%default)") parser.add_option("-o", "--output", default="critpath.txt", help="name of file to write critpath list (%default)") parser.add_option("-u", "--url", default=fedora_baseurl, help="URL to repos") parser.add_option("--srpm", action='store_true', default=False, help="Output source RPMS instead of binary RPMS (for pkgdb)") (opt, args) = parser.parse_args() if (len(args) != 1) or (args[0] not in releases): parser.error("must choose a release from the list: %s" % releases) (maj, min, sub) = yum.__version_info__ if (maj < 3 or min < 2 or (maj == 3 and min == 2 and sub < 24)) and opt.arches != getBaseArch(): print "WARNING: yum < 3.2.24 may be unable to depsolve other arches." print "Get a newer yum or run this on an actual %s system." % opt.arches # Sanity checking done, set some variables release = args[0] check_arches = opt.arches.split(',') if opt.nvr and opt.srpm: print "ERROR: --nvr and --srpm are mutually exclusive" sys.exit(1) if opt.url != fedora_baseurl: releasepath[release] = releasepath[release].replace('development/','') print "Using URL %s" % (opt.url + releasepath[release]) # Do the critpath expansion for each arch critpath = set()