-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvimplugins.py
More file actions
130 lines (106 loc) · 4.11 KB
/
Copy pathvimplugins.py
File metadata and controls
130 lines (106 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from concurrent.futures import ThreadPoolExecutor
import os
import shutil
import sys
import tempfile
from urllib import request
import zipfile
DEFAULT = '~/.vim'
SUB = 'bundle'
plugins = [
('vim-surround',
'https://github.com/tpope/vim-surround/archive/f51a26d3710629d031806305b6c8727189cd1935.zip'),
('vim-tmux-navigator',
'https://github.com/christoomey/vim-tmux-navigator/archive/6c0b5d2faa49f2059331a4004b34a916c96abcb3.zip'),
('vim-syntastic',
'https://github.com/vim-syntastic/syntastic/archive/dd226673063b189683b98133d7a2243c1316e71e.zip'),
('taglist',
'https://github.com/yegappan/taglist/archive/v4.6.zip'),
('ctrlp',
'https://github.com/kien/ctrlp.vim/archive/564176f01d7f3f7f8ab452ff4e1f5314de7b0981.zip'),
('linediff',
'https://github.com/AndrewRadev/linediff.vim/archive/681a3bc2944059692c91c61fd5c6e01afba28e62.zip'),
('vim-repeat',
'https://github.com/tpope/vim-repeat/archive/master.zip'),
('vim-airline',
'https://github.com/vim-airline/vim-airline/archive/v0.11.zip'),
('vim-airline-themes',
'https://github.com/vim-airline/vim-airline-themes/archive/master.zip'),
# ('coc.nvim',
# 'https://github.com/neoclide/coc.nvim/archive/refs/tags/v0.0.80.zip'),
('vim-commentary',
'https://github.com/tpope/vim-commentary/archive/refs/tags/v1.3.zip'),
('vim-solidity',
'https://github.com/ChristianChiarulli/vim-solidity/archive/master.zip'),
('vim-indentwise',
'https://github.com/jeetsukumaran/vim-indentwise/archive/refs/heads/master.zip'),
('vim-solidity',
'https://github.com/TovarishFin/vim-solidity/archive/refs/heads/master.zip'),
# ('cairo.vim',
# 'https://github.com/miguelmota/cairo.vim/archive/d3cf09cec98fe35f4a07b3d1b90a3ecd55e231bc.zip'),
# ('cairo.vim',
# 'https://github.com/codemedian/cairo.vim/archive/345c8cd425ac5ea3b5956258830854488513cf25.zip'),
('SimpylFold',
'https://github.com/tmhedberg/SimpylFold/archive/refs/tags/v2.0.zip'),
('vim-flake8',
'https://github.com/nvie/vim-flake8/archive/refs/tags/1.7.zip'),
# ('nerdtree',
# 'https://github.com/preservim/nerdtree/archive/refs/tags/6.10.16.zip'),
]
def get_pathogen(dst):
url = 'https://tpo.pe/pathogen.vim'
path = os.path.join(dst, 'pathogen.vim')
resp = request.urlopen(url)
with open(path, 'w') as outfile:
outfile.write(resp.read().decode())
print(f'Downloaded pathogen to {dst}')
def download_extract_zip(name, url, dst, downloaddir='.',
rmzip=True, rmexisting=True):
resp = request.urlopen(url)
zipfile_path = os.path.join(downloaddir, f'{name}.zip')
with open(zipfile_path, 'wb') as outfile:
outfile.write(resp.read())
zf = zipfile.ZipFile(zipfile_path)
dirname = zf.namelist()[0]
zf.extractall(dst)
dstpath = os.path.join(dst, name)
if rmexisting:
shutil.rmtree(dstpath, ignore_errors=True)
try:
os.rename(os.path.join(dst, dirname), dstpath)
except Exception as e:
print(e)
raise
print(f'Downloaded {name}')
os.remove(zipfile_path)
def _star(f):
def inner(*args):
return f(*args[0])
return inner
def download_plugins(dst):
tmpdir = tempfile.mkdtemp()
try:
arg_iters = [(name, url, dst, tmpdir) for name, url in plugins]
with ThreadPoolExecutor(max_workers=4) as executor:
executor.map(_star(download_extract_zip), arg_iters)
finally:
shutil.rmtree(tmpdir)
def prepare_dst():
if len(sys.argv) == 1:
dst = DEFAULT
elif len(sys.argv) == 2:
dst = sys.argv[1]
else:
raise ValueError('Too many system arguments')
dst = os.path.expanduser(dst)
if not os.path.isdir(dst):
raise OSError(f'destination `{dst}` does not exist')
# pathogen file
os.makedirs(os.path.join(dst, 'autoload'), exist_ok=True)
# plugins
os.makedirs(os.path.join(dst, SUB), exist_ok=True)
return dst
if __name__ == '__main__':
dst = prepare_dst()
get_pathogen(os.path.join(dst, 'autoload'))
download_plugins(os.path.join(dst, SUB))