def list_rpms_in_channel(pkg, channel, options=[]): """ :param pkg: A dict contains RPM basic information: * Must: name, version and release * Should/May: arch and epoch :param channel: Software channel label to list RPMs. :param options: List of option strings passed to :function:`rpmkti.swapi.call`, e.g. ['--verbose', '--server ...'] :return: List of pkg dicts in the software channel see also: http://red.ht/1laSAVn """ __validate_pkg(pkg, ['arch']) try: all_rpms = [_normalize(p) for p in SW.call('channel.software.listAllPackages', [channel], options)] assert all_rpms def f(pkg, all_rpms): for ref in all_rpms: if maybe_same_rpm(pkg, ref): LOG.debug("matched: " + str(ref)) yield get_rpm_details(ref, options) else: if all(ref[k] == pkg[k] for k in ("name", "version")): LOG.debug("mismatch: ref=" + str(ref)) return list(f(pkg, all_rpms)) except (RuntimeError, IndexError): return []
def find_rpm_by_search(pkg, options=[]): """ :param pkg: A dict contains RPM basic information: * Must: name, version and release * Should/May: arch and epoch :param options: List of option strings passed to :function:`rpmkti.swapi.call`, e.g. ['--verbose', '--server ...'] :return: List of another pkg dicts see also: http://red.ht/1dIs967 """ __validate_pkg(pkg) arg_fmt = "name:%(name)s AND version:%(version)s AND release:%(release)s" if pkg.get('epoch', 0) != 0: arg_fmt += " AND epoch:%(epoch)d" if pkg.get('arch', False): arg_fmt += " AND arch:%(arch)s" try: return [get_rpm_details(p, options) for p in SW.call('packages.search.advanced', [arg_fmt % pkg], options)] except (RuntimeError, IndexError): return []
def find_rpm_by_search(pkg, options=[]): """ :param pkg: A dict contains RPM basic information: * Must: name, version and release * Should/May: arch and epoch :param options: List of option strings passed to :function:`rpmkti.swapi.call`, e.g. ['--verbose', '--server ...'] :return: List of another pkg dicts see also: http://red.ht/1dIs967 """ __validate_pkg(pkg) arg_fmt = "name:%(name)s AND version:%(version)s AND release:%(release)s" if pkg.get('epoch', 0) != 0: arg_fmt += " AND epoch:%(epoch)d" if pkg.get('arch', False): arg_fmt += " AND arch:%(arch)s" try: return [ get_rpm_details(p, options) for p in SW.call('packages.search.advanced', [arg_fmt % pkg], options) ] except (RuntimeError, IndexError): return []
def list_rpms_in_channel(pkg, channel, options=[]): """ :param pkg: A dict contains RPM basic information: * Must: name, version and release * Should/May: arch and epoch :param channel: Software channel label to list RPMs. :param options: List of option strings passed to :function:`rpmkti.swapi.call`, e.g. ['--verbose', '--server ...'] :return: List of pkg dicts in the software channel see also: http://red.ht/1laSAVn """ __validate_pkg(pkg, ['arch']) try: all_rpms = [ _normalize(p) for p in SW.call('channel.software.listAllPackages', [channel], options) ] assert all_rpms def f(pkg, all_rpms): for ref in all_rpms: if maybe_same_rpm(pkg, ref): LOG.debug("matched: " + str(ref)) yield get_rpm_details(ref, options) else: if all(ref[k] == pkg[k] for k in ("name", "version")): LOG.debug("mismatch: ref=" + str(ref)) return list(f(pkg, all_rpms)) except (RuntimeError, IndexError): return []
def find_rpm_by_nvrea(pkg, options=[]): """ :param pkg: A dict contains RPM basic information: * Must: name, version and release * Should/May: arch and epoch :param options: List of option strings passed to :function:`rpmkti.swapi.call`, e.g. ['--verbose', '--server ...'] :return: List of resolved pkg dicts see also: http://red.ht/1jgCNCh """ __validate_pkg(pkg, ['arch']) epoch = ' ' if pkg.get('epoch', 0) == 0 else pkg['epoch'] api_args = [ pkg['name'], pkg['version'], pkg['release'], epoch, pkg['arch'] ] try: return [ get_rpm_details(p, options) for p in SW.call('packages.findByNvrea', api_args, options) ] except (RuntimeError, IndexError): return []
def download_rpms(pkg, outdir): """ TBD. :param pkg: A dict contains RPM basic information other than url :param outdir: Where to save RPM[s] """ url = RS.call("packages.getPackageUrl", [pkg["id"]], ["--no-cache"])[0] logging.info("RPM URL: " + ', '.join(url)) return urlgrabber.urlgrab(url, os.path.join(outdir, os.path.basename(url)))
def get_rpm_details(pkg, options=[]): """ :param pkg: A dict contains RPM basic information: * Must: id :param options: List of option strings passed to :function:`rpmkti.swapi.call`, e.g. ['--verbose', '--server ...'] :return: List of resolved pkg dict see also: http://red.ht/NWByOa """ __validate_pkg(pkg, ['id']) try: return SW.call('packages.getDetails', [pkg['id']], options)[0] except (RuntimeError, IndexError): LOG.warn("Failed to get details of the pkg#%(id)d" % pkg) return pkg
def find_rpm_by_nvrea(pkg, options=[]): """ :param pkg: A dict contains RPM basic information: * Must: name, version and release * Should/May: arch and epoch :param options: List of option strings passed to :function:`rpmkti.swapi.call`, e.g. ['--verbose', '--server ...'] :return: List of resolved pkg dicts see also: http://red.ht/1jgCNCh """ __validate_pkg(pkg, ['arch']) epoch = ' ' if pkg.get('epoch', 0) == 0 else pkg['epoch'] api_args = [pkg['name'], pkg['version'], pkg['release'], epoch, pkg['arch']] try: return [get_rpm_details(p, options) for p in SW.call('packages.findByNvrea', api_args, options)] except (RuntimeError, IndexError): return []