-
Notifications
You must be signed in to change notification settings - Fork 291
/
Copy pathupdate_plugins
executable file
·71 lines (53 loc) · 2.14 KB
/
update_plugins
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
#!/usr/bin/env python
import zipfile
import shutil
import tempfile
import requests
from os import path
#--- Globals ----------------------------------------------
PLUGINS = """
bclose.vim https://github.com/rbgrouleff/bclose.vim
ack.vim https://github.com/mileszs/ack.vim
bufexplorer https://github.com/corntrace/bufexplorer
nerdtree https://github.com/scrooloose/nerdtree
csapprox https://github.com/godlygeek/csapprox
vim-fugitive https://github.com/tpope/vim-fugitive
gitv https://github.com/gregsexton/gitv
nerdcommenter https://github.com/scrooloose/nerdcommenter
vim-gitgutter https://github.com/airblade/vim-gitgutter
syntastic https://github.com/scrooloose/syntastic
neocomplete.vim https://github.com/Shougo/neocomplete.vim
neosnippet.vim https://github.com/Shougo/neosnippet.vim
vim-go https://github.com/fatih/vim-go
auto-pairs https://github.com/jiangmiao/auto-pairs
tagbar https://github.com/majutsushi/tagbar
""".strip()
GITHUB_ZIP = '%s/archive/master.zip'
SOURCE_DIR = path.join(path.dirname(__file__), '../bundle/pristine')
def download_extract_replace(plugin_name, zip_path, temp_dir, source_dir):
temp_zip_path = path.join(temp_dir, plugin_name)
# Download and extract file in temp dir
req = requests.get(zip_path)
open(temp_zip_path, 'wb').write(req.content)
zip_f = zipfile.ZipFile(temp_zip_path)
zip_f.extractall(temp_dir)
plugin_temp_path = path.join(temp_dir,
path.join(temp_dir, '%s-master' % plugin_name))
# Remove the current plugin and replace it with the extracted
plugin_dest_path = path.join(source_dir, plugin_name)
try:
shutil.rmtree(plugin_dest_path)
except OSError:
pass
shutil.move(plugin_temp_path, plugin_dest_path)
print('Updated {0}'.format(plugin_name))
if __name__ == '__main__':
temp_directory = tempfile.mkdtemp()
try:
for line in PLUGINS.splitlines():
name, github_url = line.split(' ')
zip_path = GITHUB_ZIP % github_url
download_extract_replace(name, zip_path,
temp_directory, SOURCE_DIR)
finally:
shutil.rmtree(temp_directory)