Exemplo n.º 1
0
    def exec_server_cmd(self, cmd, on_exit, arguments, sudo=False):
        def on_stderr(job_id, err_msg):
            ind = err_msg.rfind('FSServerException: ')
            if ind > 0:
                err_msg = err_msg[ind + 19:]
            Vim.ErrorMsg(err_msg)

        fname = tempfile.mkstemp()[1]
        with open(fname, 'ab') as f:
            pickle.dump(arguments, f)

        if sudo:
            Vim.AsyncRun('sudo {} {} {}'.format(self.ServerCmd, cmd, fname),
                         on_exit=on_exit,
                         term=True)
        else:
            Vim.AsyncRun('{} {} {}'.format(self.ServerCmd, cmd, fname),
                         on_stderr=on_stderr,
                         on_exit=on_exit)
Exemplo n.º 2
0
    def run_async(cls, cmd, on_stdout=None, on_exit=None):
        def print_error(job_id, err_msg):
            # Truncate unnecessary message if from fs_server.py
            ind = err_msg.rfind('FSServerException: ')
            if ind > 0:
                err_msg = err_msg[ind + 19:]
            Vim.ErrorMsg(err_msg)

        Vim.AsyncRun(cmd,
                     on_stdout=on_stdout,
                     on_exit=on_exit,
                     on_stderr=print_error)
Exemplo n.º 3
0
    def run_cmd(self, cmd):
        if not self.rcd_started:
            Vim.AsyncRun(
                f'rclone {self._flags} rcd --rc-no-auth --rc-addr=localhost:{self.rclone_rcd_port}'
            )
            self.rcd_started = True
            # Ensure the server running before executing the next command.
            time.sleep(.1)

        return json.loads(
            Shell.run(
                f'rclone {self._flags} rc --rc-addr=localhost:{self.rclone_rcd_port} {cmd}'
            ))
Exemplo n.º 4
0
 def view_image(self):
     try:
         import ueberzug
     except ModuleNotFoundError:
         Vim.ErrorMsg('Please install ueberzug for image preview')
         self.view_mime()
         return
     path = self.path
     if self.path.endswith('gif') and Shell.isinPATH('convert'):
         if self.path not in self.tempfile_cache:
             dir = tempfile.TemporaryDirectory().name
             Shell.mkdir(dir)
             self.tempfile_cache[self.path] = dir
         dir = self.tempfile_cache[self.path]
         path = dir
         Shell.run(f'convert -deconstruct  "{self.path}" {dir}/a.png')
     Vim.AsyncRun(f'{util.GenNetRangerScriptCmd("image_preview")}\
                     "{path}" {self.total_width} {self.preview_width}',
                  term=True,
                  termopencmd='')
     Vim.command('setlocal nocursorline')