Beispiel #1
0
    def action_completed(self, task, status, output):
        # Grab the results of the action and finish up
        self.progress_thread.stop()
        self.progress_thread.wait()
        if task in self.tasks:
            self.tasks.remove(task)

        already_up_to_date = self.tr('Already up-to-date.')

        if not output:  # git fetch --tags --verbose doesn't print anything...
            output = already_up_to_date

        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        result = 'returned exit status %d' % status
        message = '"git %s" %s' % (self.action.lower(), result)
        if output:
            message += '\n\n' + output

        # Force the status to 1 so that we always display the log
        Interaction.log(message)

        if status == 0:
            self.accept()
            return

        if self.action == PUSH:
            message += '\n\nHave you rebased/pulled lately?'

        Interaction.critical(self.windowTitle(),
                             message=message,
                             details=output)
Beispiel #2
0
    def thread_done(self, results):
        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        detail_lines = []
        for (cmd, status, out, err) in results:
            if status != 0:
                Interaction.critical(
                    N_('Error Creating Branch'),
                    (N_('"%(command)s" returned exit status "%(status)d"') %
                     dict(command='git ' + cmd, status=status)))
                return
            line = '"git %s" returned exit status %d' % (cmd, status)
            detail_lines.append(line)
            if out:
                detail_lines.append(out)
            if err:
                detail_lines.append(err)
            detail_lines.append('')
        details = '\n'.join(detail_lines)
        qtutils.information(N_('Create Branch'),
                            N_('Branch created'),
                            details=details)
        self.accept()
Beispiel #3
0
    def thread_done(self, results):
        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        detail_lines = []
        for (cmd, status, out, err) in results:
            if status != 0:
                Interaction.critical(
                        N_('Error Creating Branch'),
                        (N_('"%(command)s" returned exit status "%(status)d"') %
                         dict(command='git '+cmd, status=status)))
                return
            line = '"git %s" returned exit status %d' % (cmd, status)
            detail_lines.append(line)
            if out:
                detail_lines.append(out)
            if err:
                detail_lines.append(err)
            detail_lines.append('')
        details = '\n'.join(detail_lines)
        qtutils.information(N_('Create Branch'),
                            N_('Branch created'),
                            details=details)
        self.accept()
Beispiel #4
0
    def do(self):
        if not self.filenames:
            return
        filename = self.filenames[0]
        if not core.exists(filename):
            return
        editor = prefs.editor()
        opts = []

        if self.line_number is None:
            opts = self.filenames
        else:
            # Single-file w/ line-numbers (likely from grep)
            editor_opts = {
                    '*vim*': ['+'+self.line_number, filename],
                    '*emacs*': ['+'+self.line_number, filename],
                    '*textpad*': ['%s(%s,0)' % (filename, self.line_number)],
                    '*notepad++*': ['-n'+self.line_number, filename],
            }

            opts = self.filenames
            for pattern, opt in editor_opts.items():
                if fnmatch(editor, pattern):
                    opts = opt
                    break

        try:
            core.fork(utils.shell_split(editor) + opts)
        except Exception as e:
            message = (N_('Cannot exec "%s": please configure your editor')
                       % editor)
            details = core.decode(e.strerror)
            Interaction.critical(N_('Error Editing File'), message, details)
Beispiel #5
0
    def do(self):
        if not self.filenames:
            return
        filename = self.filenames[0]
        if not core.exists(filename):
            return
        editor = prefs.editor()
        opts = []

        if self.line_number is None:
            opts = self.filenames
        else:
            # Single-file w/ line-numbers (likely from grep)
            editor_opts = {
                "*vim*": ["+" + self.line_number, filename],
                "*emacs*": ["+" + self.line_number, filename],
                "*textpad*": ["%s(%s,0)" % (filename, self.line_number)],
                "*notepad++*": ["-n" + self.line_number, filename],
            }

            opts = self.filenames
            for pattern, opt in editor_opts.items():
                if fnmatch(editor, pattern):
                    opts = opt
                    break

        try:
            core.fork(utils.shell_split(editor) + opts)
        except Exception as e:
            message = N_('Cannot exec "%s": please configure your editor') % editor
            details = core.decode(e.strerror)
            Interaction.critical(N_("Error Editing File"), message, details)
Beispiel #6
0
    def action_completed(self, task, status, output):
        # Grab the results of the action and finish up
        self.progress_thread.stop()
        self.progress_thread.wait()
        if task in self.tasks:
            self.tasks.remove(task)

        already_up_to_date = self.tr('Already up-to-date.')

        if not output: # git fetch --tags --verbose doesn't print anything...
            output = already_up_to_date

        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        result = 'returned exit status %d' % status
        message = '"git %s" %s' % (self.action.lower(), result)
        if output:
            message += '\n\n' + output

        # Force the status to 1 so that we always display the log
        Interaction.log(message)

        if status == 0:
            self.accept()
            return

        if self.action == PUSH:
            message += '\n\nHave you rebased/pulled lately?'

        Interaction.critical(self.windowTitle(),
                             message=message, details=output)
Beispiel #7
0
    def do(self):
        if not self.filenames:
            return
        filename = self.filenames[0]
        if not core.exists(filename):
            return
        editor = prefs.editor()
        opts = []

        if self.line_number is None:
            opts = self.filenames
        else:
            # Single-file w/ line-numbers (likely from grep)
            editor_opts = {
                    '*vim*': ['+'+self.line_number, filename],
                    '*emacs*': ['+'+self.line_number, filename],
                    '*textpad*': ['%s(%s,0)' % (filename, self.line_number)],
                    '*notepad++*': ['-n'+self.line_number, filename],
            }

            opts = self.filenames
            for pattern, opt in editor_opts.items():
                if fnmatch(editor, pattern):
                    opts = opt
                    break

        try:
            core.fork(utils.shell_split(editor) + opts)
        except Exception as e:
            message = (N_('Cannot exec "%s": please configure your editor') %
                       editor)
            Interaction.critical(N_('Error Editing File'),
                                 message, str(e))
Beispiel #8
0
    def action_completed(self, task, status, out, err):
        # Grab the results of the action and finish up
        self.action_button.setEnabled(True)
        self.close_button.setEnabled(True)

        already_up_to_date = N_('Already up-to-date.')

        if not out: # git fetch --tags --verbose doesn't print anything...
            out = already_up_to_date

        command = 'git %s' % self.action.lower()
        message = (N_('"%(command)s" returned exit status %(status)d') %
                   dict(command=command, status=status))
        details = ''
        if out:
            details = out
        if err:
            details += '\n\n' + err

        log_message = message
        if details:
            log_message += '\n\n' + details
        Interaction.log(log_message)

        if status == 0:
            self.accept()
            return

        if self.action == PUSH:
            message += '\n\n'
            message += N_('Have you rebased/pulled lately?')

        Interaction.critical(self.windowTitle(),
                             message=message, details=details)
Beispiel #9
0
def report_clone_repo_errors(task):
    """Report errors from the clone task if they exist"""
    if task.cmd is None or task.cmd.ok:
        return
    Interaction.critical(task.cmd.error_message,
                         message=task.cmd.error_message,
                         details=task.cmd.error_details)
Beispiel #10
0
    def action_completed(self, task, status, out, err):
        # Grab the results of the action and finish up
        self.action_button.setEnabled(True)
        self.close_button.setEnabled(True)

        already_up_to_date = N_('Already up-to-date.')

        if not out:  # git fetch --tags --verbose doesn't print anything...
            out = already_up_to_date

        command = 'git %s' % self.action.lower()
        message = (N_('"%(command)s" returned exit status %(status)d') %
                   dict(command=command, status=status))
        details = ''
        if out:
            details = out
        if err:
            details += '\n\n' + err

        log_message = message
        if details:
            log_message += '\n\n' + details
        Interaction.log(log_message)

        if status == 0:
            self.accept()
            return

        if self.action == PUSH:
            message += '\n\n'
            message += N_('Have you rebased/pulled lately?')

        Interaction.critical(self.windowTitle(),
                             message=message,
                             details=details)
Beispiel #11
0
    def action_completed(self, task, status, output):
        # Grab the results of the action and finish up
        self.progress_thread.stop()
        self.progress_thread.wait()
        if task in self.tasks:
            self.tasks.remove(task)

        already_up_to_date = N_('Already up-to-date.')

        if not output: # git fetch --tags --verbose doesn't print anything...
            output = already_up_to_date

        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        command = 'git %s' % self.action.lower()
        message = (N_('"%(command)s" returned exit status %(status)d') %
                   dict(command=command, status=status))
        if output:
            message += '\n\n' + output

        Interaction.log(message)

        if status == 0:
            self.accept()
            return

        if self.action == PUSH:
            message += '\n\n'
            message += N_('Have you rebased/pulled lately?')

        Interaction.critical(self.windowTitle(),
                             message=message, details=output)
Beispiel #12
0
def launch_history_browser(argv):
    try:
        core.fork(argv)
    except Exception as e:
        _, details = utils.format_exception(e)
        title = N_("Error Launching History Browser")
        msg = N_('Cannot exec "%s": please configure a history browser') % " ".join(argv)
        Interaction.critical(title, message=msg, details=details)
Beispiel #13
0
def do_cmd(cmd):
    try:
        cmd.do()
    except StandardError, e:
        exc_type, exc_value, exc_tb = sys.exc_info()
        details = traceback.format_exception(exc_type, exc_value, exc_tb)
        details = '\n'.join(details)
        msg = _exception_message(e)
        Interaction.critical('Oops', message=msg, details=details)
Beispiel #14
0
def do(cls, *args, **opts):
    """Run a command in-place"""
    try:
        cls(*args, **opts).do()
    except StandardError, e:
        exc_type, exc_value, exc_tb = sys.exc_info()
        details = traceback.format_exception(exc_type, exc_value, exc_tb)
        details = '\n'.join(details)
        Interaction.critical('Oops', message=e.msg, details=details)
Beispiel #15
0
def do_cmd(cmd):
    if hasattr(cmd, "DISABLED") and cmd.DISABLED:
        return None
    try:
        return cmd.do()
    except Exception as e:
        msg, details = utils.format_exception(e)
        Interaction.critical(N_("Error"), message=msg, details=details)
        return None
Beispiel #16
0
def do(cls, *args, **opts):
    """Run a command in-place"""
    try:
        cls(*args, **opts).do()
    except StandardError, e:
        exc_type, exc_value, exc_tb = sys.exc_info()
        details = traceback.format_exception(exc_type, exc_value, exc_tb)
        details = '\n'.join(details)
        Interaction.critical('Oops', message=e.msg, details=details)
Beispiel #17
0
def launch_history_browser(argv):
    try:
        core.fork(argv)
    except Exception as e:
        _, details = utils.format_exception(e)
        title = N_('Error Launching History Browser')
        msg = (N_('Cannot exec "%s": please configure a history browser') %
               ' '.join(argv))
        Interaction.critical(title, message=msg, details=details)
Beispiel #18
0
def do_cmd(cmd):
    if hasattr(cmd, 'DISABLED') and cmd.DISABLED:
        return None
    try:
        return cmd.do()
    except StandardError, e:
        msg, details = utils.format_exception(e)
        Interaction.critical(N_('Error'), message=msg, details=details)
        return None
Beispiel #19
0
def do_cmd(cmd):
    try:
        cmd.do()
    except StandardError, e:
        exc_type, exc_value, exc_tb = sys.exc_info()
        details = traceback.format_exception(exc_type, exc_value, exc_tb)
        details = '\n'.join(details)
        msg = _exception_message(e)
        Interaction.critical('Oops', message=msg, details=details)
Beispiel #20
0
def do_cmd(cmd):
    if hasattr(cmd, 'DISABLED') and cmd.DISABLED:
        return None
    try:
        return cmd.do()
    except Exception as e:
        msg, details = utils.format_exception(e)
        Interaction.critical(N_('Error'), message=msg, details=details)
        return None
Beispiel #21
0
def do_cmd(cmd):
    if hasattr(cmd, 'DISABLED') and cmd.DISABLED:
        return None
    try:
        return cmd.do()
    except StandardError, e:
        exc_type, exc_value, exc_tb = sys.exc_info()
        details = traceback.format_exception(exc_type, exc_value, exc_tb)
        details = '\n'.join(details)
        msg = _exception_message(e)
        Interaction.critical(N_('Error'), message=msg, details=details)
        return None
Beispiel #22
0
def do_cmd(cmd):
    if hasattr(cmd, 'DISABLED') and cmd.DISABLED:
        return None
    try:
        return cmd.do()
    except StandardError, e:
        exc_type, exc_value, exc_tb = sys.exc_info()
        details = traceback.format_exception(exc_type, exc_value, exc_tb)
        details = '\n'.join(details)
        msg = _exception_message(e)
        Interaction.critical(N_('Error'), message=msg, details=details)
        return None
Beispiel #23
0
    def thread_done(self, results):
        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        for (cmd, status, out, err) in results:
            if status != 0:
                Interaction.critical(
                        N_('Error Creating Branch'),
                        (N_('"%(command)s" returned exit status "%(status)d"') %
                         dict(command='git '+cmd, status=status)))
                return

        self.accept()
Beispiel #24
0
    def do(self):
        status, out, err = self.model.git.push(self.remote, self.branch, delete=True)
        Interaction.log_status(status, out, err)
        self.model.update_status()

        if status == 0:
            Interaction.information(
                N_("Remote Branch Deleted"),
                N_('"%(branch)s" has been deleted from "%(remote)s".') % dict(branch=self.branch, remote=self.remote),
            )
        else:
            command = "git push"
            message = N_('"%(command)s" returned exit status %(status)d') % dict(command=command, status=status)

            Interaction.critical(N_("Error Deleting Remote Branch"), message, out + err)
Beispiel #25
0
    def do(self):
        argv = utils.shell_split(prefs.history_browser())
        if self.revision:
            argv.append(self.revision)
        if self.paths:
            argv.append('--')
            argv.extend(self.paths)

        try:
            core.fork(argv)
        except Exception as e:
            _, details = utils.format_exception(e)
            title = N_('Error Launching History Browser')
            msg = (N_('Cannot exec "%s": please configure a history browser') %
                   ' '.join(argv))
            Interaction.critical(title, message=msg, details=details)
Beispiel #26
0
    def do(self):
        argv = utils.shell_split(prefs.history_browser())
        if self.revision:
            argv.append(self.revision)
        if self.paths:
            argv.append('--')
            argv.extend(self.paths)

        try:
            core.fork(argv)
        except Exception as e:
            _, details = utils.format_exception(e)
            title = N_('Error Launching History Browser')
            msg = (N_('Cannot exec "%s": please configure a history browser') %
                   ' '.join(argv))
            Interaction.critical(title, message=msg, details=details)
Beispiel #27
0
    def do(self):
        status, out, err = self.model.git.push(self.remote, self.branch,
                                               delete=True)
        Interaction.log_status(status, out, err)
        self.model.update_status()

        if status == 0:
            Interaction.information(
                N_('Remote Branch Deleted'),
                N_('"%(branch)s" has been deleted from "%(remote)s".')
                    % dict(branch=self.branch, remote=self.remote))
        else:
            command = 'git push'
            message = (N_('"%(command)s" returned exit status %(status)d') %
                        dict(command=command, status=status))

            Interaction.critical(N_('Error Deleting Remote Branch'),
                                 message, out + err)
Beispiel #28
0
    def thread_done(self, results):
        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        detail_lines = []
        for (cmd, status, out) in results:
            if status != 0:
                Interaction.critical(
                    'Create Branch Error',
                    '"git %s" returned exit status "%d"' % (cmd, status))
                return
            line = '"git %s" returned exit status %d' % (cmd, status)
            detail_lines.append(line)
            detail_lines.append(out)
            detail_lines.append('')
        details = '\n'.join(detail_lines)
        qtutils.information('Create Branch', 'Branch created', details=details)
        self.accept()
Beispiel #29
0
    def thread_done(self, results):
        self.setEnabled(True)
        self.progress.close()
        QtGui.QApplication.restoreOverrideCursor()

        detail_lines = []
        for (cmd, status, out) in results:
            if status != 0:
                Interaction.critical(
                        'Create Branch Error',
                        '"git %s" returned exit status "%d"' % (cmd, status))
                return
            line = '"git %s" returned exit status %d' % (cmd, status)
            detail_lines.append(line)
            detail_lines.append(out)
            detail_lines.append('')
        details = '\n'.join(detail_lines)
        qtutils.information('Create Branch', 'Branch created',
                            details=details)
        self.accept()
Beispiel #30
0
    def do(self):
        status, output = self.model.git.push(self.remote, self.branch,
                                             delete=True,
                                             with_status=True,
                                             with_stderr=True)
        self.model.update_status()

        Interaction.log_status(status, output)

        if status == 0:
            Interaction.information(
                N_('Remote Branch Deleted'),
                N_('"%(branch)s" has been deleted from "%(remote)s".')
                    % dict(branch=self.branch, remote=self.remote))
        else:
            command = 'git push'
            message = (N_('"%(command)s" returned exit status %(status)d') %
                        dict(command=command, status=status))

            Interaction.critical(N_('Error Deleting Remote Branch'),
                                 message, output)
Beispiel #31
0
    def action_completed(self, task, status, out, err):
        # Grab the results of the action and finish up
        self.action_button.setEnabled(True)
        self.close_button.setEnabled(True)
        QtGui.QApplication.restoreOverrideCursor()

        self.progress_thread.stop()
        self.progress_thread.wait()
        self.progress.close()
        if task in self.tasks:
            self.tasks.remove(task)

        already_up_to_date = N_("Already up-to-date.")

        if not out:  # git fetch --tags --verbose doesn't print anything...
            out = already_up_to_date

        command = "git %s" % self.action.lower()
        message = N_('"%(command)s" returned exit status %(status)d') % dict(command=command, status=status)
        details = ""
        if out:
            details = out
        if err:
            details += "\n\n" + err

        log_message = message
        if details:
            log_message += "\n\n" + details
        Interaction.log(log_message)

        if status == 0:
            self.accept()
            return

        if self.action == PUSH:
            message += "\n\n"
            message += N_("Have you rebased/pulled lately?")

        Interaction.critical(self.windowTitle(), message=message, details=details)
Beispiel #32
0
    def do(self):
        for env in ('FILENAME', 'REVISION', 'ARGS'):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        opts = _config.get_guitool_opts(self.action_name)
        cmd = opts.get('cmd')
        if 'title' not in opts:
            opts['title'] = cmd

        if 'prompt' not in opts or opts.get('prompt') is True:
            prompt = N_('Run "%s"?') % cmd
            opts['prompt'] = prompt

        if opts.get('needsfile'):
            filename = selection.filename()
            if not filename:
                Interaction.information(
                        N_('Please select a file'),
                        N_('"%s" requires a selected file.') % cmd)
                return False
            compat.setenv('FILENAME', filename)

        if opts.get('revprompt') or opts.get('argprompt'):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get('revision')
                args = opts.get('args')
                if opts.get('revprompt') and not rev:
                    title = N_('Invalid Revision')
                    msg = N_('The revision expression cannot be empty.')
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get('confirm'):
            title = os.path.expandvars(opts.get('title'))
            prompt = os.path.expandvars(opts.get('prompt'))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.setenv('REVISION', rev)
        if args:
            compat.setenv('ARGS', args)
        title = os.path.expandvars(cmd)
        Interaction.log(N_('Running command: %s') % title)
        cmd = ['sh', '-c', cmd]

        if opts.get('noconsole'):
            status, out, err = core.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status,
                               out and (N_('Output: %s') % out) or '',
                               err and (N_('Errors: %s') % err) or '')

        if not opts.get('norescan'):
            self.model.update_status()
        return status
Beispiel #33
0
    def do(self):
        for env in ("FILENAME", "REVISION", "ARGS"):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        cfg = gitcfg.current()
        opts = cfg.get_guitool_opts(self.action_name)
        cmd = opts.get("cmd")
        if "title" not in opts:
            opts["title"] = cmd

        if "prompt" not in opts or opts.get("prompt") is True:
            prompt = N_('Run "%s"?') % cmd
            opts["prompt"] = prompt

        if opts.get("needsfile"):
            filename = selection.filename()
            if not filename:
                Interaction.information(N_("Please select a file"), N_('"%s" requires a selected file.') % cmd)
                return False
            compat.setenv("FILENAME", filename)

        if opts.get("revprompt") or opts.get("argprompt"):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get("revision")
                args = opts.get("args")
                if opts.get("revprompt") and not rev:
                    title = N_("Invalid Revision")
                    msg = N_("The revision expression cannot be empty.")
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get("confirm"):
            title = os.path.expandvars(opts.get("title"))
            prompt = os.path.expandvars(opts.get("prompt"))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.setenv("REVISION", rev)
        if args:
            compat.setenv("ARGS", args)
        title = os.path.expandvars(cmd)
        Interaction.log(N_("Running command: %s") % title)
        cmd = ["sh", "-c", cmd]

        if opts.get("background"):
            core.fork(cmd)
            status, out, err = (0, "", "")
        elif opts.get("noconsole"):
            status, out, err = core.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status, out and (N_("Output: %s") % out) or "", err and (N_("Errors: %s") % err) or "")

        if not opts.get("background") and not opts.get("norescan"):
            self.model.update_status()
        return status
Beispiel #34
0
 def fail(self, status, out, err):
     title = msg = self.error_message()
     details = self.error_details() or out + err
     Interaction.critical(title, message=msg, details=details)
Beispiel #35
0
    def do(self):
        for env in ("FILENAME", "REVISION", "ARGS"):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        opts = _config.get_guitool_opts(self.name)
        cmd = opts.get("cmd")
        if "title" not in opts:
            opts["title"] = cmd

        if "prompt" not in opts or opts.get("prompt") is True:
            prompt = i18n.gettext("Are you sure you want to run %s?") % cmd
            opts["prompt"] = prompt

        if opts.get("needsfile"):
            filename = selection.filename()
            if not filename:
                Interaction.information("Please select a file", '"%s" requires a selected file' % cmd)
                return False
            compat.putenv("FILENAME", filename)

        if opts.get("revprompt") or opts.get("argprompt"):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get("revision")
                args = opts.get("args")
                if opts.get("revprompt") and not rev:
                    title = "Invalid Revision"
                    msg = "The revision expression cannot be empty."
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get("confirm"):
            title = os.path.expandvars(opts.get("title"))
            prompt = os.path.expandvars(opts.get("prompt"))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.putenv("REVISION", rev)
        if args:
            compat.putenv("ARGS", args)
        title = os.path.expandvars(cmd)
        Interaction.log("running: " + title)
        cmd = ["sh", "-c", cmd]

        if opts.get("noconsole"):
            status, out, err = utils.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status, out and "stdout: %s" % out, err and "stderr: %s" % err)

        if not opts.get("norescan"):
            self.model.update_status()
        return status
Beispiel #36
0
    def do(self):
        for env in ('FILENAME', 'REVISION', 'ARGS'):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        cfg = gitcfg.current()
        opts = cfg.get_guitool_opts(self.action_name)
        cmd = opts.get('cmd')
        if 'title' not in opts:
            opts['title'] = cmd

        if 'prompt' not in opts or opts.get('prompt') is True:
            prompt = N_('Run "%s"?') % cmd
            opts['prompt'] = prompt

        if opts.get('needsfile'):
            filename = selection.filename()
            if not filename:
                Interaction.information(
                        N_('Please select a file'),
                        N_('"%s" requires a selected file.') % cmd)
                return False
            compat.setenv('FILENAME', filename)

        if opts.get('revprompt') or opts.get('argprompt'):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get('revision')
                args = opts.get('args')
                if opts.get('revprompt') and not rev:
                    title = N_('Invalid Revision')
                    msg = N_('The revision expression cannot be empty.')
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get('confirm'):
            title = os.path.expandvars(opts.get('title'))
            prompt = os.path.expandvars(opts.get('prompt'))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.setenv('REVISION', rev)
        if args:
            compat.setenv('ARGS', args)
        title = os.path.expandvars(cmd)
        Interaction.log(N_('Running command: %s') % title)
        cmd = ['sh', '-c', cmd]

        if opts.get('background'):
            core.fork(cmd)
            status, out, err = (0, '', '')
        elif opts.get('noconsole'):
            status, out, err = core.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status,
                               out and (N_('Output: %s') % out) or '',
                               err and (N_('Errors: %s') % err) or '')

        if not opts.get('background') and not opts.get('norescan'):
            self.model.update_status()
        return status
Beispiel #37
0
    def do(self):
        for env in ('FILENAME', 'REVISION', 'ARGS'):
            try:
                compat.unsetenv(env)
            except KeyError:
                pass
        rev = None
        args = None
        opts = _config.get_guitool_opts(self.name)
        cmd = opts.get('cmd')
        if 'title' not in opts:
            opts['title'] = cmd

        if 'prompt' not in opts or opts.get('prompt') is True:
            prompt = i18n.gettext('Are you sure you want to run %s?') % cmd
            opts['prompt'] = prompt

        if opts.get('needsfile'):
            filename = selection.filename()
            if not filename:
                Interaction.information('Please select a file',
                                        '"%s" requires a selected file' % cmd)
                return False
            compat.putenv('FILENAME', filename)

        if opts.get('revprompt') or opts.get('argprompt'):
            while True:
                ok = Interaction.confirm_config_action(cmd, opts)
                if not ok:
                    return False
                rev = opts.get('revision')
                args = opts.get('args')
                if opts.get('revprompt') and not rev:
                    title = 'Invalid Revision'
                    msg = 'The revision expression cannot be empty.'
                    Interaction.critical(title, msg)
                    continue
                break

        elif opts.get('confirm'):
            title = os.path.expandvars(opts.get('title'))
            prompt = os.path.expandvars(opts.get('prompt'))
            if Interaction.question(title, prompt):
                return
        if rev:
            compat.putenv('REVISION', rev)
        if args:
            compat.putenv('ARGS', args)
        title = os.path.expandvars(cmd)
        Interaction.log('running: ' + title)
        cmd = ['sh', '-c', cmd]

        if opts.get('noconsole'):
            status, out, err = utils.run_command(cmd)
        else:
            status, out, err = Interaction.run_command(title, cmd)

        Interaction.log_status(status, out and 'stdout: %s' % out, err
                               and 'stderr: %s' % err)

        if not opts.get('norescan'):
            self.model.update_status()
        return status
Beispiel #38
0
 def fail(self, status, out, err):
     title = msg = self.error_message()
     details = self.error_details() or out + err
     Interaction.critical(title, message=msg, details=details)