def _new(self): dlg = QtGui.QFileDialog(self) dlg.setFileMode(QtGui.QFileDialog.Directory) dlg.setOption(QtGui.QFileDialog.ShowDirsOnly) if dlg.exec_() != QtGui.QFileDialog.Accepted: return paths = dlg.selectedFiles() if not paths: return upath = unicode(paths[0]) if not upath: return path = core.encode(unicode(paths[0])) # Avoid needlessly calling `git init`. if git.is_git_dir(path): # We could prompt here and confirm that they really didn't # mean to open an existing repository, but I think # treating it like an "Open" is a sensible DWIM answer. self._gitdir = upath self.accept() return os.chdir(path) status, out, err = utils.run_command(['git', 'init']) if status != 0: title = 'Error Creating Repository' msg = 'git init returned exit status %d' % status details = 'output:\n%s\n\nerrors:\n%s' % (out, err) qtutils.critical(title, msg, details) else: self._gitdir = upath self.accept()
def new_repo(): """Prompt for a new directory and create a new Git repository :returns str: repository path or None if no repository was created. """ dlg = QtGui.QFileDialog() dlg.setFileMode(QtGui.QFileDialog.Directory) dlg.setOption(QtGui.QFileDialog.ShowDirsOnly) dlg.show() dlg.raise_() if dlg.exec_() != QtGui.QFileDialog.Accepted: return None paths = dlg.selectedFiles() if not paths: return None path = unicode(paths[0]) if not path: return None # Avoid needlessly calling `git init`. if git.is_git_dir(core.encode(path)): # We could prompt here and confirm that they really didn't # mean to open an existing repository, but I think # treating it like an "Open" is a sensible DWIM answer. return path status, out, err = utils.run_command(['git', 'init', path]) if status == 0: return path else: title = N_('Error Creating Repository') msg = (N_('"%(command)s" returned exit status %(status)d') % dict(command='git init %s' % path, status=status)) details = N_('Output:\n%s') % out if err: details += '\n\n' details += N_('Errors: %s') % err qtutils.critical(title, msg, details) return None
def do(self): for env in ('FILENAME', 'REVISION', 'ARGS'): try: del os.environ[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: _factory.prompt_user(signals.information, 'Please select a file', '"%s" requires a selected file' % cmd) return os.environ['FILENAME'] = commands.mkarg(filename) if opts.get('revprompt') or opts.get('argprompt'): while True: ok = _factory.prompt_user(signals.run_config_action, cmd, opts) if not ok: return rev = opts.get('revision') args = opts.get('args') if opts.get('revprompt') and not rev: msg = ('Invalid revision:\n\n' 'Revision expression is empty') title = 'Oops!' _factory.prompt_user(signals.information, title, msg) continue break elif opts.get('confirm'): title = os.path.expandvars(opts.get('title')) prompt = os.path.expandvars(opts.get('prompt')) if not _factory.prompt_user(signals.question, title, prompt): return if rev: os.environ['REVISION'] = rev if args: os.environ['ARGS'] = args title = os.path.expandvars(cmd) _notifier.broadcast(signals.log_cmd, 0, 'running: ' + title) cmd = ['sh', '-c', cmd] if opts.get('noconsole'): status, out, err = utils.run_command(cmd, flag_error=False) else: status, out, err = _factory.prompt_user(signals.run_command, title, cmd) _notifier.broadcast(signals.log_cmd, status, 'stdout: %s\nstatus: %s\nstderr: %s' % (out.rstrip(), status, err.rstrip())) if not opts.get('norescan'): self.model.update_status() return status
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.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 = 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.putenv('REVISION', rev) if args: compat.putenv('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 = utils.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
def do(self): for env in ("FILENAME", "REVISION", "ARGS"): try: del os.environ[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: _factory.prompt_user(signals.information, "Please select a file", '"%s" requires a selected file' % cmd) return os.environ["FILENAME"] = filename if opts.get("revprompt") or opts.get("argprompt"): while True: ok = _factory.prompt_user(signals.run_config_action, cmd, opts) if not ok: return 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." _factory.prompt_user(signals.critical, title, msg) continue break elif opts.get("confirm"): title = os.path.expandvars(opts.get("title")) prompt = os.path.expandvars(opts.get("prompt")) if not _factory.prompt_user(signals.question, title, prompt): return if rev: os.environ["REVISION"] = rev if args: os.environ["ARGS"] = args title = os.path.expandvars(cmd) _notifier.broadcast(signals.log_cmd, 0, "running: " + title) cmd = ["sh", "-c", cmd] if opts.get("noconsole"): status, out, err = utils.run_command(cmd, flag_error=False) else: status, out, err = _factory.prompt_user(signals.run_command, title, cmd) _notifier.broadcast( signals.log_cmd, status, "stdout: %s\nstatus: %s\nstderr: %s" % (out.rstrip(), status, err.rstrip()) ) if not opts.get("norescan"): self.model.update_status() return status
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
def do(self): for env in ('FILENAME', 'REVISION', 'ARGS'): try: del os.environ[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: _factory.prompt_user(signals.information, 'Please select a file', '"%s" requires a selected file' % cmd) return os.environ['FILENAME'] = filename if opts.get('revprompt') or opts.get('argprompt'): while True: ok = _factory.prompt_user(signals.run_config_action, cmd, opts) if not ok: return 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.' _factory.prompt_user(signals.critical, title, msg) continue break elif opts.get('confirm'): title = os.path.expandvars(opts.get('title')) prompt = os.path.expandvars(opts.get('prompt')) if not _factory.prompt_user(signals.question, title, prompt): return if rev: os.environ['REVISION'] = rev if args: os.environ['ARGS'] = args title = os.path.expandvars(cmd) _notifier.broadcast(signals.log_cmd, 0, 'running: ' + title) cmd = ['sh', '-c', cmd] if opts.get('noconsole'): status, out, err = utils.run_command(cmd, flag_error=False) else: status, out, err = _factory.prompt_user(signals.run_command, title, cmd) _notifier.broadcast(signals.log_cmd, status, 'stdout: %s\nstatus: %s\nstderr: %s' % (out.rstrip(), status, err.rstrip())) if not opts.get('norescan'): self.model.update_status() return status
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
def run_command(cls, title, cmd): cls.log('$ ' + subprocess.list2cmdline(cmd)) status, out, err = utils.run_command(cmd) cls.log_status(status, out, err)
def run_command(cls, title, cmd): print('$ ' + subprocess.list2cmdline(cmd)) status, out, err = utils.run_command(cmd) cls.log_status(status, out, err)