def __init__(self, path, spawn=None, thread=None, **kwargs): """ :param path: path to the file to be edited :type path: str :param spawn: force running edtor in a new terminal :type spawn: bool :param thread: run asynchronously, don't block alot :type thread: bool """ self.spawn = spawn if spawn is None: self.spawn = settings.get('editor_spawn') self.thread = thread if thread is None: self.thread = settings.get('editor_in_thread') editor_cmdstring = None if os.path.isfile('/usr/bin/editor'): editor_cmdstring = '/usr/bin/editor' editor_cmdstring = os.environ.get('EDITOR', editor_cmdstring) editor_cmdstring = settings.get('editor_cmd') or editor_cmdstring logging.debug('using editor_cmd: %s' % editor_cmdstring) self.cmdlist = None if '%s' in editor_cmdstring: cmdstring = editor_cmdstring.replace('%s', helper.shell_quote(path)) self.cmdlist = split_commandstring(cmdstring) else: self.cmdlist = split_commandstring(editor_cmdstring) + [path] logging.debug({'spawn: ': self.spawn, 'in_thread': self.thread}) ExternalCommand.__init__(self, self.cmdlist, spawn=self.spawn, thread=self.thread, **kwargs)
def thread_code(*args): if self.path: if "{}" in self.commandstring: cmd = self.commandstring.replace("{}", helper.shell_quote(self.path)) else: cmd = "%s %s" % (self.commandstring, helper.shell_quote(self.path)) else: cmd = self.commandstring if self.spawn: cmd = "%s %s" % (settings.config.get("general", "terminal_cmd"), cmd) cmd = cmd.encode("utf-8", errors="ignore") ui.logger.info("calling external command: %s" % cmd) try: if 0 == subprocess.call(shlex.split(cmd)): os.write(write_fd, "success") except OSError, e: os.write(write_fd, str(e))
def thread_code(*args): if self.path: if '{}' in self.commandstring: cmd = self.commandstring.replace('{}', helper.shell_quote(self.path)) else: cmd = '%s %s' % (self.commandstring, helper.shell_quote(self.path)) else: cmd = self.commandstring if self.spawn: cmd = '%s %s' % (settings.get('terminal_cmd'), cmd) cmd = cmd.encode('utf-8', errors='ignore') logging.info('calling external command: %s' % cmd) try: if 0 == subprocess.call(shlex.split(cmd)): return 'success' except OSError, e: return str(e)
def test_single_quotes_are_escaped_using_double_quotes(self): quoted = helper.shell_quote("hello'there") self.assertEqual(quoted, """'hello'"'"'there'""")
def test_all_strings_are_sourrounded_by_single_quotes(self): quoted = helper.shell_quote("hello") self.assertEqual(quoted, "'hello'")