예제 #1
0
    def __init__(self, vim):
        self.vim = vim
        self.inited = False
        self.bufs = {}
        self.wd2bufnum = {}
        self.pinnedRoots = set()
        self.picked_nodes = defaultdict(set)
        self.cut_nodes, self.copied_nodes = defaultdict(set), defaultdict(set)
        self.bookmarkUI = None
        self.helpUI = None
        self.sortUI = None
        self.askUI = None
        self.onuiquit = None
        self.onuiquitNumArgs = 0
        self.fs = FS()
        self.rclone = None

        self.initVimVariables()
        self.initKeymaps()
        Shell.mkdir(default.variables['NETRRootDir'])
        self.rifle = Rifle(self.vim, VimVar('NETRRifleFile'))
        ignore_pat = list(VimVar('NETRIgnore'))
        self.vim.vars['NETRemoteCacheDir'] = os.path.expanduser(
            VimVar('NETRemoteCacheDir'))
        if '.*' not in ignore_pat:
            ignore_pat.append('.*')
            self.vim.vars['NETRIgnore'] = ignore_pat
예제 #2
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('ls -p {}'.format(dirname)).split('\n')
                if len(name) > 0
            ])
            remote_files = set([
                name for name in Shell.run('rclone lsf "{}"'.format(
                    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):
                log('rclone copyto "{}" "{}"'.format(
                    os.path.join(dirname, name),
                    os.path.join(self.rpath(dirname), name)))
                Shell.run('rclone copyto "{}" "{}"'.format(
                    os.path.join(dirname, name),
                    os.path.join(self.rpath(dirname), name)))
        return super(Rclone, self).ls(dirname)
예제 #3
0
 def init(self):
     self.inited = True
     self.initVimVariables()
     self.initKeymaps()
     self.rclone = None
     self.bookmarkUI = None
     self.helpUI = None
     self.isEditing = False
     self.onuiquit = None
     self.onuiquitNumArgs = 0
     Shell.mkdir(default.variables['NETRRootDir'])
     self.rifle = Rifle(self.vim, self.vim.vars['NETRRifleFile'])
예제 #4
0
def test_detect_fs_change():
    nvim.input(' ')
    Shell.touch('dir/b')
    Shell.mkdir('dir3')
    nvim.command('split new')
    nvim.command('quit')
    assert_content('dir', ind=0, hi='dir')
    assert_content('b', ind=4, level=1, hi='file')
    assert_content('dir3', ind=6, hi='dir')
    assert_num_content_line(7)

    Shell.rm('dir3')
    nvim.input('lh')
    assert_num_content_line(6)
예제 #5
0
    def prepare_test_dir(dirname):
        Shell.mkdir(dirname)
        os.chdir(dirname)
        Shell.mkdir('dir/subdir')
        Shell.mkdir('dir/subdir/subsubdir')
        Shell.mkdir('dir/subdir2')
        Shell.touch('dir/a')
        Shell.touch('.a')
        Shell.mkdir('dir2/')

        # The following should be removed when rclone fix "not copying empty directories" bug.
        Shell.touch('dir/subdir/subsubdir/placeholder')
        Shell.touch('dir/subdir2/placeholder')
        Shell.touch('dir/subdir2/placeholder')
예제 #6
0
    def __init__(self, lpath, path):
        Shell.mkdir(lpath)
        self.lpath = lpath

        self.child = {}
        self.cached = False
        self.path = path

        if path is None:
            remotes = Shell.run('rclone listremotes').split(':\n')
            log(remotes)
            for remote in remotes:
                if len(remote)==0:
                    continue
                self.child[remote] = RcloneDir(os.path.join(lpath, remote), remote+':/')
            self.cached = True
예제 #7
0
    def __init__(self, root_dir, remote_remap):
        if root_dir[-1] == '/':
            root_dir = root_dir[:-1]

        self.root_dir = root_dir
        self.rplen = len(root_dir) + 1
        for remote, root in remote_remap.items():
            if root[-1] != '/':
                remote_remap[remote] += '/'
        self.remote_remap = remote_remap
        Shell.mkdir(root_dir)
        remotes = set(Shell.run('rclone listremotes').split(':\n'))
        local_remotes = set(super(Rclone, self).ls(root_dir))
        for remote in remotes.difference(local_remotes):
            Shell.mkdir(os.path.join(root_dir, remote))
        for remote in local_remotes.difference(remotes):
            super(Rclone, self).rm(os.path.join(root_dir, remote), True)

        self.has_remote = len(remotes) > 0
        self.ls_time_stamp = {}
예제 #8
0
    def valid_or_install(cls, vim):
        import platform
        import zipfile

        if Shell.isinPATH('rclone'):
            return True
        else:
            rclone_dir = VimUserInput(
                'Rclone not in PATH. Install it at (modify/enter)',
                os.path.expanduser('~/rclone'))
            Shell.mkdir(rclone_dir)

            system = platform.system().lower()
            processor = 'amd64'
            if '386' in platform.processor():
                processor = '386'
            else:
                # Should support arm??
                pass

            url = 'https://downloads.rclone.org/rclone-current-{}-{}.zip'.format(
                system, processor)
            zip_fname = os.path.join(rclone_dir, 'rclone.zip')
            Shell.urldownload(url, zip_fname)
            zip_ref = zipfile.ZipFile(zip_fname, 'r')
            zip_ref.extractall(rclone_dir)
            for entry in zip_ref.NameToInfo:
                if entry.endswith('rclone'):
                    Shell.cp(os.path.join(rclone_dir, entry), rclone_dir)
                    Shell.chmod(os.path.join(rclone_dir, 'rclone'), 755)

            zip_ref.close()
            os.remove(zip_fname)

            shellrc = VimUserInput(
                'Update PATH in (leave blank to set manually later)',
                Shell.shellrc())
            if len(shellrc) > 0:
                with open(shellrc, 'a') as f:
                    f.write('PATH={}:$PATH\n'.format(rclone_dir))
            os.environ['PATH'] += ':' + rclone_dir
예제 #9
0
def do_test(fn, wipe_on_done=True):
    old_cwd = os.getcwd()
    test_root = os.path.expanduser('~/netranger_test_dir')
    Shell.run('rm -rf {}'.format(test_root))
    Shell.mkdir(test_root)

    os.chdir(test_root)
    Shell.mkdir(os.path.join(test_root, 'dir/subdir'))
    Shell.mkdir(os.path.join(test_root, 'dir/subdir/subsubdir'))
    Shell.mkdir(os.path.join(test_root, 'dir/subdir2'))
    Shell.run('touch {}/dir/a'.format(test_root))
    Shell.run('touch {}/.a'.format(test_root))
    Shell.mkdir(os.path.join(test_root, 'dir2/'))

    nvim.command('tabe {}'.format(test_root))
    fn()
    if wipe_on_done:
        nvim.command('bwipeout')

    os.chdir(old_cwd)
    print('== {} success =='.format(str(fn.__name__)))
예제 #10
0
파일: fs.py 프로젝트: mwcz/vim-netranger
 def mkdir(self, name):
     Shell.mkdir(name)