コード例 #1
0
def get_spec_name_in_srpm(srpm):
    """Return the name of the spec file present in an SRPM.  Assumes
    there is exactly one spec file in the SRPM -- if there is more than
    one spec file, returns the name of the first one ``cpio'' prints.
    """
    out, ret = utils.sbacktick("rpm2cpio %s | cpio -t '*.spec' 2> /dev/null" %
                               utils.shell_quote(srpm),
                               shell=True)
    if ret != 0:
        raise Error("Unable to get list of spec files from %s" % srpm)
    try:
        spec_name = [_f for _f in [x.strip() for x in out.split("\n")]
                     if _f][0]
    except IndexError:
        spec_name = None

    if not spec_name:
        raise Error("No spec file inside %s" % srpm)

    return spec_name
コード例 #2
0
def extract_from_rpm(rpm, file_or_pattern=None):
    """Extract a specific file or glob from an rpm."""
    command = "rpm2cpio " + utils.shell_quote(rpm) + " | cpio -ivd"
    if file_or_pattern:
        command += " " + utils.shell_quote(file_or_pattern)
    return utils.checked_call(command, shell=True)