Example #1
0
def extract_spec(srpm, osg_dir):
    """Extract the spec file from the SRPM, put it into an osg/ dir,
    and add both the osg/ dir and the spec file to SVN, if necessary.
    An existing spec file will be moved out of the way, with a .old
    extension, if necessary.
    """
    if not os.path.exists(osg_dir):
        os.mkdir(osg_dir)
        svn_safe_add(osg_dir)

    utils.pushd(osg_dir)
    try:
        srpm = os.path.abspath(srpm)

        spec_name = get_spec_name_in_srpm(srpm)

        if os.path.exists(spec_name):
            spec_name_old = spec_name + ".old"
            logging.info("OSG spec file found matching %s, saving to %s",
                         spec_name, spec_name_old)
            shutil.move(spec_name, spec_name_old)

        logging.info("Extracting new upstream spec file as %s", spec_name)
        extract_from_rpm(srpm, spec_name)
        svn_safe_add(spec_name)
    finally:
        utils.popd()
Example #2
0
def extract_spec(srpm, osg_dir):
    """Extract the spec file from the SRPM, put it into an osg/ dir,
    and add both the osg/ dir and the spec file to SVN, if necessary.
    An existing spec file will be moved out of the way, with a .old
    extension, if necessary.
    """
    if not os.path.exists(osg_dir):
        os.mkdir(osg_dir)
        svn_safe_add(osg_dir)

    utils.pushd(osg_dir)
    try:
        srpm = os.path.abspath(srpm)

        spec_name = get_spec_name_in_srpm(srpm)

        if os.path.exists(spec_name):
            spec_name_old = spec_name + ".old"
            logging.info("OSG spec file found matching %s, saving to %s",
                         spec_name, spec_name_old)
            shutil.move(spec_name, spec_name_old)

        logging.info("Extracting new upstream spec file as %s", spec_name)
        extract_from_rpm(srpm, spec_name)
        svn_safe_add(spec_name)
    finally:
        utils.popd()
Example #3
0
def extract_orig_spec(osg_dir):
    """Save a copy of the original upstream spec file from before the
    import into the osg_dir
    """
    utils.pushd(osg_dir)
    try:
        utils.checked_call(['osg-build', 'prebuild', '..'])
        spec_paths = list(glob.glob("../_upstream_srpm_contents/*.spec"))
        for spec_path in spec_paths:
            spec_name_orig = os.path.basename(spec_path) + '.orig'
            logging.info("Saving original upstream spec file as %s",
                         spec_name_orig)
            shutil.copy(spec_path, spec_name_orig)
    finally:
        utils.popd()
Example #4
0
def extract_orig_spec(osg_dir):
    """Save a copy of the original upstream spec file from before the
    import into the osg_dir
    """
    utils.pushd(osg_dir)
    try:
        utils.checked_call(['osg-build', 'prebuild', '..'])
        spec_paths = list(glob.glob("../_upstream_srpm_contents/*.spec"))
        for spec_path in spec_paths:
            spec_name_orig = os.path.basename(spec_path) + '.orig'
            logging.info("Saving original upstream spec file as %s",
                         spec_name_orig)
            shutil.copy(spec_path, spec_name_orig)
    finally:
        utils.popd()
Example #5
0
def diff_spec(srpm, osg_dir, want_diff3=False):
    """Do a 2- or 3-way diff between spec files found in the osg/
     directory, and the new upstream SRPM. If a 3-way diff is requested,
     also look at the spec file from the previous upstream SRPM. The
     osg/ directory must exist.

    The files that will be created or changed are:
    - $spec.old  : spec file from the osg/ dir before import
    - $spec.new  : spec file from the new upstream SRPM
    - $spec.orig : spec file from the old upstream SRPM (3-way only)
    - $spec      : combined spec file with differences separated by markers

    """
    if not os.path.isdir(osg_dir) or not glob.glob(os.path.join(osg_dir, '*')):
        logging.error("No osg/ dir found or no spec files in osg/ dir -- nothing to diff.")
        logging.error("To extract the spec file, run with -e instead.")
        sys.exit(1)

    utils.pushd(osg_dir)
    try:
        srpm = os.path.abspath(srpm)

        spec_name = get_spec_name_in_srpm(srpm)
        spec_name_old = spec_name + ".old"
        spec_name_new = spec_name + ".new"

        if not os.path.exists(spec_name):
            logging.info("No old spec file matching %s - the spec file might have been renamed.",
                         spec_name)
            logging.info("Extracting new upstream spec file as %s", spec_name)
            extract_from_rpm(srpm, spec_name)
            return

        logging.info("OSG spec file found matching %s, saving to %s",
                     spec_name, spec_name_old)
        shutil.move(spec_name, spec_name_old)

        logging.info("Extracting new upstream spec file as %s", spec_name_new)
        extract_from_rpm(srpm, spec_name)
        shutil.move(spec_name, spec_name_new)

        if want_diff3:
            spec_name_orig = spec_name + ".orig"
            if os.path.exists(spec_name_orig):
                # Use `diff3 -m` to takes the changes that turn spec_name_orig into
                # spec_name_new, and applies these changes to spec_name_new.
                # Put the results into spec_name.

                diff3(spec_name_old, spec_name_orig, spec_name_new, spec_name)
            else:
                # This can happen if the package before import was an upstream
                # tarball with osg-provided spec file, as opposed to an
                # upstream SRPM with an osg-modified spec file.

                logging.info("No original upstream spec file matching %s - doing a two-way diff instead.", spec_name)
                diff2(spec_name_old, spec_name_new, spec_name)
        else:
            diff2(spec_name_old, spec_name_new, spec_name)

    finally:
        utils.popd()
Example #6
0
def diff_spec(srpm, osg_dir, want_diff3=False):
    """Do a 2- or 3-way diff between spec files found in the osg/
     directory, and the new upstream SRPM. If a 3-way diff is requested,
     also look at the spec file from the previous upstream SRPM. The
     osg/ directory must exist.

    The files that will be created or changed are:
    - $spec.old  : spec file from the osg/ dir before import
    - $spec.new  : spec file from the new upstream SRPM
    - $spec.orig : spec file from the old upstream SRPM (3-way only)
    - $spec      : combined spec file with differences separated by markers

    """
    if not os.path.isdir(osg_dir) or not glob.glob(os.path.join(osg_dir, '*')):
        logging.error(
            "No osg/ dir found or no spec files in osg/ dir -- nothing to diff."
        )
        logging.error("To extract the spec file, run with -e instead.")
        sys.exit(1)

    utils.pushd(osg_dir)
    try:
        srpm = os.path.abspath(srpm)

        spec_name = get_spec_name_in_srpm(srpm)
        spec_name_old = spec_name + ".old"
        spec_name_new = spec_name + ".new"

        if not os.path.exists(spec_name):
            logging.info(
                "No old spec file matching %s - the spec file might have been renamed.",
                spec_name)
            logging.info("Extracting new upstream spec file as %s", spec_name)
            extract_from_rpm(srpm, spec_name)
            return

        logging.info("OSG spec file found matching %s, saving to %s",
                     spec_name, spec_name_old)
        shutil.move(spec_name, spec_name_old)

        logging.info("Extracting new upstream spec file as %s", spec_name_new)
        extract_from_rpm(srpm, spec_name)
        shutil.move(spec_name, spec_name_new)

        if want_diff3:
            spec_name_orig = spec_name + ".orig"
            if os.path.exists(spec_name_orig):
                # Use `diff3 -m` to takes the changes that turn spec_name_orig into
                # spec_name_new, and applies these changes to spec_name_new.
                # Put the results into spec_name.

                diff3(spec_name_old, spec_name_orig, spec_name_new, spec_name)
            else:
                # This can happen if the package before import was an upstream
                # tarball with osg-provided spec file, as opposed to an
                # upstream SRPM with an osg-modified spec file.

                logging.info(
                    "No original upstream spec file matching %s - doing a two-way diff instead.",
                    spec_name)
                diff2(spec_name_old, spec_name_new, spec_name)
        else:
            diff2(spec_name_old, spec_name_new, spec_name)

    finally:
        utils.popd()