Пример #1
0
 def commit(self):
     bufNum = vim.current.buffer.number
     Shell.run('GIT_EDITOR=false git commit')
     vim.command('tabe {}'.format(self.cur_repo.commit_edit_msg))
     vim.command('setlocal bufhidden=wipe')
     vim.command(
         'autocmd bufunload <buffer> :py3 netrGit.post_commit({})'.format(
             bufNum))
Пример #2
0
 def view_pdf(self):
     if not Shell.isinPATH('pdftoppm'):
         self.view_mime()
     else:
         if self.path not in self.tempfile_cache:
             fname = tempfile.mkstemp()[1]
             Shell.touch(fname)
             self.tempfile_cache[self.path] = fname
         fname = self.tempfile_cache[self.path]
         Shell.run(f'pdftoppm -png -f 1 -singlefile "{self.path}" {fname}')
         self.path = self.tempfile_cache[self.path] + '.png'
         self.view_image()
Пример #3
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')
Пример #4
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}'
            ))
Пример #5
0
    def ls(self, dirname, cheap_remote_ls=False):
        if not cheap_remote_ls and len(dirname) > len(self.root_dir):
            local_files = set([
                name for name in Shell.run(f'ls -p "{dirname}"').split('\n')
                if len(name) > 0
            ])

            remote_files = set([
                name for name in Shell.run(
                    f'rclone {self._flags} lsf "{self.rpath(dirname)}"').split(
                        '\n') if len(name) > 0
            ])
            for name in remote_files.difference(local_files):
                if name[-1] == '/':
                    Shell.mkdir(os.path.join(dirname, name))
                else:
                    Shell.touch(os.path.join(dirname, name))

            for name in local_files.difference(remote_files):
                # TODO use Vim.AsyncRun instead
                Shell.run_async(f'rclone {self._flags} copyto --tpslimit=10 \
                                "{os.path.join(dirname, name)}" \
                                "{os.path.join(self.rpath(dirname), name)}"')
        return super(Rclone, self).ls(dirname)
Пример #6
0
 def sync(self, lpath, direction):
     src, dst = self.sync_src_dst(lpath, direction)
     Shell.run(f'rclone {self._flags} sync "{src}" "{dst}"')
Пример #7
0
 def rename(self, src, dst):
     Shell.run(
         f'rclone {self._flags} moveto "{self.rpath(src)}" "{self.rpath(dst)}"'
     )
     super(Rclone, self).rename(src, dst)
Пример #8
0
 def ensure_remote_downloaded(self, lpath):
     if os.stat(lpath).st_size == 0:
         src, dst = self.sync_src_dst(lpath, Rclone.SyncDirection.DOWN)
         Shell.run(
             f'rclone {self._flags} copyto --tpslimit=10 "{src}" "{dst}"')
Пример #9
0
 def run_cmd(self, cmd):
     return Shell.run('git -C {} {}'.format(self.path, cmd))