def run(self, commits, *args, **kwargs):
        """
        Reads the list of commits given, and constructions the instructions
        file to be used by rebase.
        Will spawn an editor if the constructor was told to be interactive.
        Additional arguments *args and **kwargs are to be passed to 'git
        rebase'.
        """

        todo_file = self._write_todo(commits, *args, **kwargs)
        if self._interactive:
            # spawn the editor
            user_editor = self.git_sequence_editor or self.git_editor
            status = subprocess.call("%s %s" % (user_editor, todo_file),
                                     shell=True)
            if status:
                return status, None, "Editor returned non-zero exit code"

        editor = "%s %s" % (self.editor, todo_file)
        self._set_editor(editor)

        try:
            if self._interactive == 'debug':
                # In general it's not recommended to run rebase in direct
                # interactive mode because it's not possible to capture the
                # stdout/stderr, but sometimes it's useful to allow it for
                # debugging to check the final result.
                #
                # It is not safe to redirect I/O channels as most editors will
                # be expecting that I/O is from/to proper terminal. YMMV
                cmd = ['git', 'rebase', '--interactive']
                cmd.extend(self.git.transform_kwargs(**kwargs))
                cmd.extend(args)
                return subprocess.call(cmd), None, None
            else:
                return self.git.rebase(interactive=True, with_exceptions=False,
                                       with_extended_output=True, *args,
                                       **kwargs)
        finally:
            os.remove(todo_file)
            # make sure to remove the environment tweaks added so as not to
            # impact any subsequent use of git commands using editors
            self._unset_editor()
dataset/ETHPy150Open openstack/git-upstream/git_upstream/lib/rebaseeditor.py/RebaseEditor.run/original