Exemple #1
0
    def _confirm_commit_msg(self, diff_output):
        """
        Generates a commit message in a temporary file, gives the user a
        chance to edit it, and returns the filename to the caller.
        """

        fd, name = tempfile.mkstemp()
        debug("Storing commit message in temp file: %s" % name)
        write(
            fd, "Update %s to %s\n" %
            (self.project_name, self.builder.build_version))
        # Write out Resolves line for all bugzillas we see in commit diff:
        # TODO: move to DistGitBuilder only?
        try:
            (required_bz_flags, placeholder_bz) = self._get_bz_flags()
            extractor = BugzillaExtractor(diff_output,
                                          required_flags=required_bz_flags,
                                          placeholder_bz=placeholder_bz)
            for line in extractor.extract():
                write(fd, line + "\n")
        except MissingBugzillaCredsException:
            error_out([
                "Releaser specifies required flags but you have not configured",
                "a ~/.bugzillarc with your bugzilla credentials.", "Example:",
                "", "[bugzilla.redhat.com]", "user = [email protected]",
                "password = mypassword"
            ])

        print("")
        print("##### Commit message: #####")
        print("")

        os.lseek(fd, 0, 0)
        f = os.fdopen(fd)
        for line in f.readlines():
            print(line)
        f.close()

        print("")
        print("###############################")
        print("")
        if self._ask_yes_no(
                "Would you like to edit this commit message? [y/n] ", False):
            debug("Opening editor for user to edit commit message in: %s" %
                  name)
            editor = 'vi'
            if "EDITOR" in os.environ:
                editor = os.environ["EDITOR"]
            subprocess.call(editor.split() + [name])

        return name
Exemple #2
0
    def _confirm_commit_msg(self, diff_output):
        """
        Generates a commit message in a temporary file, gives the user a
        chance to edit it, and returns the filename to the caller.
        """

        fd, name = tempfile.mkstemp()
        debug("Storing commit message in temp file: %s" % name)
        write(fd, "Update %s to %s\n" % (self.project_name,
            self.builder.build_version))
        # Write out Resolves line for all bugzillas we see in commit diff:
        # TODO: move to DistGitBuilder only?
        try:
            (required_bz_flags, placeholder_bz) = self._get_bz_flags()
            extractor = BugzillaExtractor(diff_output,
                required_flags=required_bz_flags,
                placeholder_bz=placeholder_bz)
            for line in extractor.extract():
                write(fd, line + "\n")
        except MissingBugzillaCredsException:
            error_out([
                "Releaser specifies required flags but you have not configured",
                "a ~/.bugzillarc with your bugzilla credentials.",
                "Example:",
                "",
                "[bugzilla.redhat.com]",
                "user = [email protected]",
                "password = mypassword"])

        print("")
        print("##### Commit message: #####")
        print("")

        os.lseek(fd, 0, 0)
        f = os.fdopen(fd)
        for line in f.readlines():
            print(line)
        f.close()

        print("")
        print("###############################")
        print("")
        if self._ask_yes_no("Would you like to edit this commit message? [y/n] ", False):
            debug("Opening editor for user to edit commit message in: %s" % name)
            editor = 'vi'
            if "EDITOR" in os.environ:
                editor = os.environ["EDITOR"]
            subprocess.call(editor.split() + [name])

        return name
Exemple #3
0
    def _confirm_commit_msg(self, diff_output):
        """
        Generates a commit message in a temporary file, gives the user a
        chance to edit it, and returns the filename to the caller.
        """

        fd, name = tempfile.mkstemp()
        debug("Storing commit message in temp file: %s" % name)
        write(
            fd, "Update %s to %s\n" %
            (self.obs_package_name, self.builder.build_version))
        # Write out Resolves line for all bugzillas we see in commit diff:
        extractor = BugzillaExtractor(diff_output)
        for line in extractor.extract():
            write(fd, line + "\n")

        print("")
        print("##### Commit message: #####")
        print("")

        os.lseek(fd, 0, 0)
        commit_file = os.fdopen(fd)
        for line in commit_file.readlines():
            print(line)
        commit_file.close()

        print("")
        print("###############################")
        print("")
        if self._ask_yes_no(
                "Would you like to edit this commit message? [y/n] ", False):
            debug("Opening editor for user to edit commit message in: %s" %
                  name)
            editor = 'vi'
            if "EDITOR" in os.environ:
                editor = os.environ["EDITOR"]
            subprocess.call(editor.split() + [name])

        return name
Exemple #4
0
    def _confirm_commit_msg(self, diff_output):
        """
        Generates a commit message in a temporary file, gives the user a
        chance to edit it, and returns the filename to the caller.
        """

        fd, name = tempfile.mkstemp()
        debug("Storing commit message in temp file: %s" % name)
        write(fd, "Update %s to %s\n" % (self.obs_package_name,
            self.builder.build_version))
        # Write out Resolves line for all bugzillas we see in commit diff:
        extractor = BugzillaExtractor(diff_output)
        for line in extractor.extract():
            write(fd, line + "\n")

        print("")
        print("##### Commit message: #####")
        print("")

        os.lseek(fd, 0, 0)
        commit_file = os.fdopen(fd)
        for line in commit_file.readlines():
            print(line)
        commit_file.close()

        print("")
        print("###############################")
        print("")
        if self._ask_yes_no("Would you like to edit this commit message? [y/n] ", False):
            debug("Opening editor for user to edit commit message in: %s" % name)
            editor = 'vi'
            if "EDITOR" in os.environ:
                editor = os.environ["EDITOR"]
            subprocess.call(editor.split() + [name])

        return name
Exemple #5
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)
Exemple #6
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 is not None:
                    last_tag = "v%s" % (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")
                if self.git_email is None or \
                        (('HIDE_EMAIL' in self.user_config) and
                        (self.user_config['HIDE_EMAIL'] not in ['0', ''])):
                    header = "* {0} {1}\n".format(self.today, self.git_user)
                else:
                    header = "* {0} {1} <{2}>\n".format(
                        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:
                    # 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)

        if not found_changelog:
            print("WARNING: 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)
Exemple #7
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)
Exemple #8
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)