Exemplo n.º 1
0
 def test_release_tagger_use_version(self):
     os.chdir(os.path.join(self.repo_dir, 'pkg2'))
     start_ver = get_latest_tagged_version(TEST_PKG_2)
     tito('tag --debug --accept-auto-changelog --use-version 1.3.37')
     new_ver = get_latest_tagged_version(TEST_PKG_2)
     self.assertFalse(release_bumped(start_ver, new_ver))
     self.assertEquals(new_ver, "1.3.37-1")
Exemplo n.º 2
0
    def test_release_tagger_legacy_props_file(self):
        # Test that build.py.props filename is still picked up:
        os.chdir(os.path.join(MULTI_GIT, TEST_PKG_2_DIR))
        start_ver = get_latest_tagged_version(TEST_PKG_2)

        run_command("git mv tito.props build.py.props")
        run_command('git commit -a -m "Rename to build.py.props"')

        run_tito('tag --debug --accept-auto-changelog')
        new_ver = get_latest_tagged_version(TEST_PKG_2)
        self.assertTrue(release_bumped(start_ver, new_ver))
Exemplo n.º 3
0
    def test_release_tagger_legacy_props_file(self):
        # Test that build.py.props filename is still picked up:
        os.chdir(os.path.join(self.repo_dir, 'pkg2'))
        start_ver = get_latest_tagged_version(TEST_PKG_2)
        run_command("git mv tito.props build.py.props")
        index = self.repo.index
        index.add(['pkg2/build.py.props'])
        index.commit("Rename to build.py.props.")

        tito('tag --debug --accept-auto-changelog')
        new_ver = get_latest_tagged_version(TEST_PKG_2)
        self.assertTrue(release_bumped(start_ver, new_ver))
Exemplo n.º 4
0
    def _bump_version(self, release=False, zstream=False):
        """
        Bump up the package version in the spec file.

        Set release to True to bump the package release instead.

        Checks for the keep version option and if found, won't actually
        bump the version or release.
        """
        old_version = get_latest_tagged_version(self.project_name)
        if old_version is None:
            old_version = "untagged"
        if not self.keep_version:
            version_regex = re.compile("^(version:\s*)(.+)$", re.IGNORECASE)
            release_regex = re.compile("^(release:\s*)(.+)$", re.IGNORECASE)

            in_f = open(self.spec_file, 'r')
            out_f = open(self.spec_file + ".new", 'w')

            for line in in_f.readlines():
                version_match = re.match(version_regex, line)
                release_match = re.match(release_regex, line)

                if version_match and not zstream and not release:
                    current_version = version_match.group(2)
                    if hasattr(self, '_use_version'):
                        updated_content = self._use_version
                    else:
                        updated_content = increase_version(current_version)

                    line = "".join([version_match.group(1), updated_content, "\n"])

                elif release_match:
                    current_release = release_match.group(2)
                    if hasattr(self, '_use_release'):
                        updated_content = self._use_release
                    elif release:
                        updated_content = increase_version(current_release)
                    elif zstream:
                        updated_content = increase_zstream(current_release)
                    else:
                        updated_content = reset_release(current_release)

                    line = "".join([release_match.group(1), updated_content, "\n"])

                out_f.write(line)

            in_f.close()
            out_f.close()
            shutil.move(self.spec_file + ".new", self.spec_file)

        new_version = get_spec_version_and_release(self.full_project_dir,
                self.spec_file_name)
        if new_version.strip() == "":
            msg = "Error getting bumped package version, try: \n"
            msg = msg + "  'rpm -q --specfile %s'" % self.spec_file
            error_out(msg)
        info_out("Tagging new version of %s: %s -> %s" % (self.project_name,
            old_version, new_version))
        return new_version
Exemplo n.º 5
0
    def _bump_version(self, release=False, zstream=False):
        """
        Bump up the package version in the spec file.

        Set release to True to bump the package release instead.

        Checks for the keep version option and if found, won't actually
        bump the version or release.
        """
        old_version = get_latest_tagged_version(self.project_name)
        if old_version == None:
            old_version = "untagged"
        # TODO: Do this here instead of calling out to an external Perl script:
        if not self.keep_version:
            bump_type = "bump-version"
            if release:
                bump_type = "bump-release"
            elif zstream:
                bump_type = "bump-zstream"

            script_path = get_script_path("bump-version.pl")
            cmd = "%s %s --specfile %s" % \
                    (script_path, bump_type, self.spec_file)
            run_command(cmd)

        new_version = self._get_spec_version_and_release()
        if new_version.strip() == "":
            msg = "Error getting bumped package version, try: \n"
            msg = msg + "  'rpm -q --specfile %s'" % self.spec_file
            error_out(msg)
        print("Tagging new version of %s: %s -> %s" % (self.project_name,
            old_version, new_version))
        return new_version
Exemplo n.º 6
0
    def test_template_version_tagger(self):
        """
        Make sure the template is applied and results in the correct file
        being included in the tag.
        """
        pkg_dir = join(self.repo_dir, 'pkg3')
        filename = join(pkg_dir, "tito.props")
        self.write_file(filename, TEMPLATE_TAGGER_TITO_PROPS)
        run_command('mkdir -p %s' % join(self.repo_dir, '.tito/templates'))
        self.write_file(join(self.repo_dir,
            '.tito/templates/version.rb'), VERSION_TEMPLATE_FILE)

        os.chdir(self.repo_dir)
        run_command('git add pkg3/tito.props')
        run_command("git commit -m 'add tito.props for pkg3'")

        # Create another pkg3 tag and make sure we got a generated
        # template file.
        os.chdir(os.path.join(self.repo_dir, 'pkg3'))
        tito('tag --debug --accept-auto-changelog')
        new_ver = get_latest_tagged_version(TEST_PKG_3)
        self.assertEquals("0.0.2-1", new_ver)

        dest_file = os.path.join(self.repo_dir, 'pkg3', "version.txt")
        self.assertTrue(os.path.exists(dest_file))

        f = open(dest_file, 'r')
        contents = f.read()
        f.close()

        self.assertTrue("VERSION = \"0.0.2-1\"" in contents)
Exemplo n.º 7
0
Arquivo: cli.py Projeto: jsabo/tito
    def main(self):
        BaseCliModule.main(self)

        build_dir = os.path.normpath(os.path.abspath(self.options.output_dir))
        package_name = get_project_name(tag=self.options.tag)

        build_tag = None
        build_version = None
        # Determine which package version we should build:
        if self.options.tag:
            build_tag = self.options.tag
            build_version = build_tag[len(package_name + "-"):]
        else:
            build_version = get_latest_tagged_version(package_name)
            if build_version == None:
                error_out(["Unable to lookup latest package info.",
                        "Perhaps you need to tag first?"])
            build_tag = "%s-%s" % (package_name, build_version)

        if not self.options.test:
            check_tag_exists(build_tag, offline=self.options.offline)

        self.pkg_config = self._read_project_config(package_name, build_dir,
                self.options.tag, self.options.no_cleanup)

        builder = self._create_builder(package_name, build_tag,
                build_version, self.options, self.pkg_config,
                build_dir)
        builder.run(self.options)
Exemplo n.º 8
0
    def _get_build_version(self):
        """
        Figure out the git tag and version-release we're building.
        """
        # Determine which package version we should build:
        build_version = None
        if self.build_tag:
            build_version = self.build_tag[len(self.project_name + "-"):]
        else:
            build_version = get_latest_tagged_version(self.project_name)
            if build_version is None:
                if not self.test:
                    error_out(["Unable to lookup latest package info.",
                            "Perhaps you need to tag first?"])
                warn_out("unable to lookup latest package "
                    "tag, building untagged test project")
                build_version = get_spec_version_and_release(self.start_dir,
                    find_spec_like_file(self.start_dir))
            self.build_tag = "%s-%s" % (self.project_name, build_version)

        self.spec_version = build_version.split('-')[-2]
        self.spec_release = build_version.split('-')[-1]
        if not self.test:
            check_tag_exists(self.build_tag, offline=self.offline)
        return build_version
Exemplo n.º 9
0
    def _get_build_version(self):
        """
      Figure out the git tag and version-release we're building.
      """
        # Determine which package version we should build:
        build_version = None
        if self.build_tag:
            build_version = self.build_tag[len(self.project_name + "-"):]
        else:
            build_version = get_latest_tagged_version(self.project_name)
            if build_version is None:
                if not self.test:
                    error_out([
                        "Unable to lookup latest package info.",
                        "Perhaps you need to tag first?"
                    ])
                sys.stderr.write("WARNING: unable to lookup latest package "
                                 "tag, building untagged test project\n")
                build_version = get_spec_version_and_release(
                    self.start_dir, find_spec_file(in_dir=self.start_dir))
            self.build_tag = "v%s" % (build_version)

        if not self.test:
            check_tag_exists(self.build_tag, offline=self.offline)
        return build_version
Exemplo n.º 10
0
 def run(self, options):
     """
     Tag using the (platform) project as master for the version.
     @param options: tagging options.
     @type options: options
     """
     tag = get_latest_tagged_version(MASTER_PACKAGE)
     options.use_version = tag.split('-', 1)[0]
     PulpTagger.run(self, options)
Exemplo n.º 11
0
def next(project='pulp'):
    """
    Get the next (incremented) version or release.
    @param project: A pulp project name.
    @type project: str
    @return: The version-release
    @rtype: str
    """
    last_version = get_latest_tagged_version(project)
    return increment(last_version)
Exemplo n.º 12
0
def next(project='pulp'):
    """
    Get the next (incremented) version or release.
    @param project: A pulp project name.
    @type project: str
    @return: The version-release
    @rtype: str
    """
    last_version = get_latest_tagged_version(project)
    return increment(last_version)
Exemplo n.º 13
0
    def _get_build_version(self):
        """
        Figure out the git tag and version-release we're building.
        """
        # Determine which package version we should build:
        build_version = None
        if self.build_tag:
            build_version = self.build_tag[len(self.project_name + "-"):]
        else:
            build_version = get_latest_tagged_version(self.project_name)
            if build_version is None:
                error_out(["Unable to lookup latest package info.",
                        "Perhaps you need to tag first?"])
            self.build_tag = "%s-%s" % (self.project_name, build_version)

        if not self.test:
            check_tag_exists(self.build_tag, offline=self.offline)
        return build_version
Exemplo n.º 14
0
    def _get_build_version(self):
        """
        Figure out the git tag and version-release we're building.
        """
        # Determine which package version we should build:
        build_version = None
        if self.build_tag:
            build_version = self.build_tag[len(self.project_name + "-"):]
        else:
            build_version = get_latest_tagged_version(self.project_name)
            if build_version is None:
                error_out([
                    "Unable to lookup latest package info.",
                    "Perhaps you need to tag first?"
                ])
            self.build_tag = "%s-%s" % (self.project_name, build_version)

        if not self.test:
            check_tag_exists(self.build_tag, offline=self.offline)
        return build_version
Exemplo n.º 15
0
    def _get_build_version(self):
        """
        Figure out the git tag and version-release we're building.
        """
        # Determine which package version we should build:
        build_version = None
        if self.build_tag:
            build_version = self.build_tag[len(self.project_name + "-") :]
        else:
            build_version = get_latest_tagged_version(self.project_name)
            if build_version is None:
                if not self.test:
                    error_out(["Unable to lookup latest package info.", "Perhaps you need to tag first?"])
                sys.stderr.write("WARNING: unable to lookup latest package " "tag, building untagged test project\n")
                build_version = get_spec_version_and_release(self.start_dir, find_spec_file(in_dir=self.start_dir))
            self.build_tag = "v{0}".format(build_version)

        if not self.test:
            check_tag_exists(self.build_tag, offline=self.offline)
        return build_version
Exemplo n.º 16
0
    def _undo(self):
        """
        Undo the most recent tag.

        Tag commit must be the most recent commit, and the tag must not
        exist in the remote git repo, otherwise we report and error out.
        """
        tag = self._get_tag_for_version(get_latest_tagged_version(self.project_name))
        info_out("Undoing tag: %s" % tag)
        if not tag_exists_locally(tag):
            raise TitoException(
                "Cannot undo tag that does not exist locally.")
        if not self.offline and tag_exists_remotely(tag):
            raise TitoException("Cannot undo tag that has been pushed.")

        # Tag must be the most recent commit.
        if not head_points_to_tag(tag):
            raise TitoException("Cannot undo if tag is not the most recent commit.")

        # Everything looks good:
        print
        undo_tag(tag)
Exemplo n.º 17
0
    def _undo(self):
        """
        Undo the most recent tag.

        Tag commit must be the most recent commit, and the tag must not
        exist in the remote git repo, otherwise we report and error out.
        """
        tag = "v{0}".format(get_latest_tagged_version(self.project_name))
        print("Undoing tag: {0}".format(tag))
        if not tag_exists_locally(tag):
            raise TitoException(
                "Cannot undo tag that does not exist locally.")
        if not self.offline and tag_exists_remotely(tag):
            raise TitoException("Cannot undo tag that has been pushed.")

        # Tag must be the most recent commit.
        if not head_points_to_tag(tag):
            raise TitoException("Cannot undo if tag is not the most recent commit.")

        # Everything looks good:
        print
        undo_tag(tag)
Exemplo n.º 18
0
    def _bump_version(self, release=False, zstream=False, force=False):
        """
        Bump up the package version in the spec file.

        Set release to True to bump the package release instead.

        Checks for the keep version option and if found, won't actually
        bump the version or release.
        """
        old_version = get_latest_tagged_version(self.project_name)
        if old_version == None:
            old_version = "untagged"
        if not self.keep_version:
            version_regex = re.compile("^(version:\s*)(.+)$", re.IGNORECASE)
            release_regex = re.compile("^(release:\s*)(.+)$", re.IGNORECASE)

            in_f = open(self.spec_file, 'r')
            out_f = open(self.spec_file + ".new", 'w')

            for line in in_f.readlines():
                if release:
                    match = re.match(release_regex, line)
                    if match:
                        line = "".join((match.group(1),
                                        increase_version(match.group(2)),
                                        "\n"
                        ))
                elif zstream:
                    match = re.match(release_regex, line)
                    if match:
                        line = "".join((match.group(1),
                                        increase_zstream(match.group(2)),
                                        "\n"
                        ))
                elif force:
                    match = re.match(version_regex, line)
                    if match:
                        line = "".join((match.group(1),
                                        self._use_version,
                                        "\n"
                        ))

                    match = re.match(release_regex, line)
                    if match:
                        line = "".join((match.group(1),
                                        reset_release(match.group(2)),
                                        "\n"
                        ))
                else:
                    match = re.match(version_regex, line)
                    if match:
                        line = "".join((match.group(1),
                                        increase_version(match.group(2)),
                                        "\n"
                        ))

                    match = re.match(release_regex, line)
                    if match:
                        line = "".join((match.group(1),
                                        reset_release(match.group(2)),
                                        "\n"
                        ))

                out_f.write(line)

            in_f.close()
            out_f.close()
            shutil.move(self.spec_file + ".new", self.spec_file)

        new_version = self._get_spec_version_and_release()
        if new_version.strip() == "":
            msg = "Error getting bumped package version, try: \n"
            msg = msg + "  'rpm -q --specfile %s'" % self.spec_file
            error_out(msg)
        print("Tagging new version of %s: %s -> %s" % (self.project_name,
            old_version, new_version))
        return new_version
Exemplo n.º 19
0
    def _make_changelog(self):
        """
        Create a new changelog entry in the spec, with line items from git
        """
        if self._no_auto_changelog:
            debug("Skipping changelog generation.")
            return

        in_f = open(self.spec_file, 'r')
        out_f = open(self.spec_file + ".new", 'w')

        found_changelog = False
        for line in in_f.readlines():
            out_f.write(line)

            if not found_changelog and line.startswith("%changelog"):
                found_changelog = True

                old_version = get_latest_tagged_version(self.project_name)

                # don't die if this is a new package with no history
                if old_version != None:
                    last_tag = "%s-%s" % (self.project_name, old_version)
                    output = self._generate_default_changelog(last_tag)
                else:
                    output = self._new_changelog_msg

                fd, name = tempfile.mkstemp()
                os.write(fd, "# Create your changelog entry below:\n")
                if self.git_email is None or (('HIDE_EMAIL' in self.user_config) and \
                        (self.user_config['HIDE_EMAIL'] not in ['0', ''])):
                    header = "* %s %s\n" % (self.today, self.git_user)
                else:
                    header = "* %s %s <%s>\n" % (self.today, self.git_user,
                       self.git_email)

                os.write(fd, header)

                for cmd_out in output.split("\n"):
                    os.write(fd, "- ")
                    os.write(fd, "\n  ".join(textwrap.wrap(cmd_out, 77)))
                    os.write(fd, "\n")

                os.write(fd, "\n")

                if not self._accept_auto_changelog:
                    # Give the user a chance to edit the generated changelog:
                    editor = 'vi'
                    if "EDITOR" in os.environ:
                        editor = os.environ["EDITOR"]
                    subprocess.call(editor.split() + [name])

                os.lseek(fd, 0, 0)
                file = os.fdopen(fd)

                for line in file.readlines():
                    if not line.startswith("#"):
                        out_f.write(line)

                output = file.read()

                file.close()
                os.unlink(name)

        in_f.close()
        out_f.close()

        shutil.move(self.spec_file + ".new", self.spec_file)
Exemplo n.º 20
0
 def test_release_tagger(self):
     os.chdir(os.path.join(self.repo_dir, 'pkg2'))
     start_ver = get_latest_tagged_version(TEST_PKG_2)
     tito('tag --debug --accept-auto-changelog')
     new_ver = get_latest_tagged_version(TEST_PKG_2)
     self.assertTrue(release_bumped(start_ver, new_ver))
Exemplo n.º 21
0
 def test_release_tagger_use_release(self):
     os.chdir(os.path.join(self.repo_dir, 'pkg2'))
     tito('tag --debug --accept-auto-changelog --use-release 42')
     new_ver = get_latest_tagged_version(TEST_PKG_2)
     self.assertEquals(new_ver.split('-')[-1], "42")
Exemplo n.º 22
0
    def _make_changelog(self):
        """
        Create a new changelog entry in the changes, with line items from git
        """
        if self._no_auto_changelog:
            debug("Skipping changelog generation.")
            return

        # Attempt to open the file if it exists, but create it if it doesn't
        try:
            in_f = open(self.changes_file, 'r')
        except FileNotFoundError:
            new_in_f = open(self.changes_file, 'w')
            new_in_f.close()
            in_f = open(self.changes_file, 'r')

        out_f = open(self.changes_file + ".new", 'w')

        old_version = get_latest_tagged_version(self.project_name)

        # don't die if this is a new package with no history
        if old_version is not None:
            last_tag = "%s-%s" % (self.project_name, old_version)
            output = self._generate_default_changelog(last_tag)
        else:
            output = self._new_changelog_msg

        fd, name = tempfile.mkstemp()
        write(fd, "# Create your changelog entry below:\n")
        header = "-------------------------------------------------------------------\n"
        if self.git_email is None or (
            ('HIDE_EMAIL' in self.user_config) and
            (self.user_config['HIDE_EMAIL'] not in ['0', ''])):
            header = header + "%s - %s\n\n" % (self.today, self.git_user)
        else:
            header = header + "%s - %s <%s>\n\n" % (self.today, self.git_user,
                                                    self.git_email)

        write(fd, header)

        for cmd_out in output.split("\n"):
            write(fd, "- ")
            write(fd, "\n  ".join(textwrap.wrap(cmd_out, 77)))
            write(fd, "\n")

        write(fd, "\n")

        if not self._accept_auto_changelog:
            write(fd, "###################################################\n")
            write(fd, "# These are the already existing changelog entries:\n")
            write(fd, "###################################################\n")
            for line in in_f.readlines():
                write(fd, "#" + line)
            in_f.seek(0, 0)

            # Give the user a chance to edit the generated changelog:
            editor = 'vi'
            if "EDITOR" in os.environ:
                editor = os.environ["EDITOR"]
            subprocess.call([editor, name])

        os.lseek(fd, 0, 0)
        file = os.fdopen(fd)

        for line in file.readlines():
            if not line.startswith("#"):
                out_f.write(line)

        output = file.read()

        file.close()
        os.unlink(name)

        for line in in_f.readlines():
            out_f.write(line)

        in_f.close()
        out_f.close()

        shutil.move(self.changes_file + ".new", self.changes_file)
Exemplo n.º 23
0
Arquivo: tagger.py Projeto: jsabo/tito
    def _make_changelog(self):
        """
        Create a new changelog entry in the spec, with line items from git
        """
        if self._no_auto_changelog:
            debug("Skipping changelog generation.")

        in_f = open(self.spec_file, 'r')
        out_f = open(self.spec_file + ".new", 'w')

        found_changelog = False
        for line in in_f.readlines():
            out_f.write(line)

            if not found_changelog and line.startswith("%changelog"):
                found_changelog = True

                old_version = get_latest_tagged_version(self.project_name)

                # don't die if this is a new package with no history
                if old_version != None:
                    last_tag = "%s-%s" % (self.project_name, old_version)
                    patch_command = \
                            "git log --pretty=format:%%s\ \(%%ae\)" \
                            " --relative %s..%s -- %s" % \
                            (last_tag, "HEAD", ".")
                    output = run_command(patch_command)
                else:
                    output = self._new_changelog_msg

                fd, name = tempfile.mkstemp()
                os.write(fd, "# Create your changelog entry below:\n")
                header = "* %s %s <%s>\n" % (self.today, self.git_user,
                        self.git_email)

                os.write(fd, header)

                for cmd_out in output.split("\n"):
                    os.write(fd, "- ")
                    os.write(fd, "\n  ".join(textwrap.wrap(cmd_out, 77)))
                    os.write(fd, "\n")

                os.write(fd, "\n")

                if not self._accept_auto_changelog:
                    # Give the user a chance to edit the generated changelog:
                    editor = 'vi'
                    if "EDITOR" in os.environ:
                        editor = os.environ["EDITOR"]
                    subprocess.call([editor, name])

                os.lseek(fd, 0, 0)
                file = os.fdopen(fd)

                for line in file.readlines():
                    if not line.startswith("#"):
                        out_f.write(line)

                output = file.read()

                file.close()
                os.unlink(name)

        in_f.close()
        out_f.close()

        shutil.move(self.spec_file + ".new", self.spec_file)
Exemplo n.º 24
0
 def test_release_tagger(self):
     os.chdir(os.path.join(self.repo_dir, 'pkg2'))
     start_ver = get_latest_tagged_version(TEST_PKG_2)
     tito('tag --debug --accept-auto-changelog')
     new_ver = get_latest_tagged_version(TEST_PKG_2)
     self.assertTrue(release_bumped(start_ver, new_ver))
Exemplo n.º 25
0
 def test_release_tagger(self):
     os.chdir(os.path.join(MULTI_GIT, TEST_PKG_2_DIR))
     start_ver = get_latest_tagged_version(TEST_PKG_2)
     run_tito('tag --debug --accept-auto-changelog')
     new_ver = get_latest_tagged_version(TEST_PKG_2)
     self.assertTrue(release_bumped(start_ver, new_ver))
Exemplo n.º 26
0
    def _make_changelog(self):
        """
        Create a new changelog entry in the changes, with line items from git
        """
        if self._no_auto_changelog:
            debug("Skipping changelog generation.")
            return

        # Attempt to open the file if it exists, but create it if it doesn't
        try:
            in_f = open(self.changes_file, 'r')
        except FileNotFoundError:
            new_in_f = open(self.changes_file, 'w')
            new_in_f.close()
            in_f = open(self.changes_file, 'r')

        out_f = open(self.changes_file + ".new", 'w')

        old_version = get_latest_tagged_version(self.project_name)

        # don't die if this is a new package with no history
        if old_version is not None:
            last_tag = "%s-%s" % (self.project_name, old_version)
            output = self._generate_default_changelog(last_tag)
        else:
            output = self._new_changelog_msg

        fd, name = tempfile.mkstemp()
        write(fd, "# Create your changelog entry below:\n")
        header = "-------------------------------------------------------------------\n"
        if self.git_email is None or (('HIDE_EMAIL' in self.user_config) and
                (self.user_config['HIDE_EMAIL'] not in ['0', ''])):
            header = header + "%s - %s\n\n" % (self.today, self.git_user)
        else:
            header = header + "%s - %s <%s>\n\n" % (self.today, self.git_user,
                                                        self.git_email)

        write(fd, header)

        for cmd_out in output.split("\n"):
            write(fd, "- ")
            write(fd, "\n  ".join(textwrap.wrap(cmd_out, 77)))
            write(fd, "\n")

        write(fd, "\n")

        if not self._accept_auto_changelog:
            write(fd, "###################################################\n")
            write(fd, "# These are the already existing changelog entries:\n")
            write(fd, "###################################################\n")
            for line in in_f.readlines():
                write(fd, "#" + line)
            in_f.seek(0, 0)

            # Give the user a chance to edit the generated changelog:
            editor = 'vi'
            if "EDITOR" in os.environ:
                editor = os.environ["EDITOR"]
            subprocess.call([editor, name])

        os.lseek(fd, 0, 0)
        file = os.fdopen(fd)

        for line in file.readlines():
            if not line.startswith("#"):
                out_f.write(line)

        output = file.read()

        file.close()
        os.unlink(name)

        for line in in_f.readlines():
            out_f.write(line)

        in_f.close()
        out_f.close()

        shutil.move(self.changes_file + ".new", self.changes_file)
Exemplo n.º 27
0
    def _make_changelog(self):
        """
        Create a new changelog entry in the spec, with line items from git
        """
        if self._no_auto_changelog:
            debug("Skipping changelog generation.")
            return

        in_f = open(self.spec_file, 'r')
        out_f = open(self.spec_file + ".new", 'w')

        found_changelog = False
        for line in in_f.readlines():
            out_f.write(line)

            if not found_changelog and line.startswith("%changelog"):
                found_changelog = True

                old_version = get_latest_tagged_version(self.project_name)

                fd, name = tempfile.mkstemp()
                write(fd, "# Create your changelog entry below:\n")
                if self.git_email is None or (('HIDE_EMAIL' in self.user_config) and
                        (self.user_config['HIDE_EMAIL'] not in ['0', ''])):
                    header = "* %s %s\n" % (self.today, self.git_user)
                else:
                    header = "* %s %s <%s>\n" % (self.today, self.git_user,
                       self.git_email)

                write(fd, header)

                # don't die if this is a new package with no history
                if self._changelog is not None:
                    for entry in self._changelog:
                        if not entry.startswith('-'):
                            entry = '- ' + entry
                        write(fd, entry)
                        write(fd, "\n")
                else:
                    if old_version is not None:
                        last_tag = self._get_new_tag(old_version)
                        output = self._generate_default_changelog(last_tag)
                    else:
                        output = self._new_changelog_msg

                    for cmd_out in output.split("\n"):
                        write(fd, "- ")
                        write(fd, "\n  ".join(textwrap.wrap(cmd_out, 77)))
                        write(fd, "\n")

                write(fd, "\n")

                if not self._accept_auto_changelog:
                    # Give the user a chance to edit the generated changelog:
                    editor = 'vi'
                    if "EDITOR" in os.environ:
                        editor = os.environ["EDITOR"]
                    subprocess.call(editor.split() + [name])

                os.lseek(fd, 0, 0)
                f = os.fdopen(fd)

                for line in f.readlines():
                    if not line.startswith("#"):
                        out_f.write(line)

                output = f.read()

                f.close()
                os.unlink(name)

        if not found_changelog:
            warn_out("no %changelog section find in spec file. Changelog entry was not appended.")

        in_f.close()
        out_f.close()

        shutil.move(self.spec_file + ".new", self.spec_file)
Exemplo n.º 28
0
    def _bump_version(self, release=False, zstream=False):
        """
        Bump up the package version in the spec file.

        Set release to True to bump the package release instead.

        Checks for the keep version option and if found, won't actually
        bump the version or release.
        """
        old_version = get_latest_tagged_version(self.project_name)
        if old_version is None:
            old_version = "untagged"
        if not self.keep_version:
            version_regex = re.compile("^(version:\s*)(.+)$", re.IGNORECASE)
            release_regex = re.compile("^(release:\s*)(.+)$", re.IGNORECASE)

            in_f = open(self.spec_file, 'r')
            out_f = open(self.spec_file + ".new", 'w')

            for line in in_f.readlines():
                version_match = re.match(version_regex, line)
                release_match = re.match(release_regex, line)

                if version_match and not zstream and not release:
                    current_version = version_match.group(2)
                    if hasattr(self, '_use_version'):
                        updated_content = self._use_version
                    else:
                        updated_content = increase_version(current_version)

                    line = "".join(
                        [version_match.group(1), updated_content, "\n"])

                elif release_match:
                    current_release = release_match.group(2)
                    if hasattr(self, '_use_release'):
                        updated_content = self._use_release
                    elif release:
                        updated_content = increase_version(current_release)
                    elif zstream:
                        updated_content = increase_zstream(current_release)
                    else:
                        updated_content = reset_release(current_release)

                    line = "".join(
                        [release_match.group(1), updated_content, "\n"])

                out_f.write(line)

            in_f.close()
            out_f.close()
            shutil.move(self.spec_file + ".new", self.spec_file)

        new_version = get_spec_version_and_release(self.full_project_dir,
                                                   self.spec_file_name)
        if new_version.strip() == "":
            msg = "Error getting bumped package version, try: \n"
            msg = msg + "  'rpm -q --specfile %s'" % self.spec_file
            error_out(msg)
        info_out("Tagging new version of %s: %s -> %s" %
                 (self.project_name, old_version, new_version))
        return new_version