forked from koron/online-update
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim-online-update.py
85 lines (73 loc) · 2.43 KB
/
vim-online-update.py
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
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
# Vimのアップデートを確認するプログラム.
import logging
import os
import sys
import gettext
from online_updater import Updater
from online_updater.progress import UpdaterProgress
import online_updater.pe32
pe32 = online_updater.pe32
_ = gettext.gettext
def __detectArch(rootdir):
arch = pe32.ARCH_UNKNOWN
exe = os.path.join(rootdir, 'vim.exe')
if os.path.exists(exe):
arch = pe32.detectArch(exe)
else:
machtype = os.environ.get('PROCESSOR_ARCHITECTURE').upper()
if machtype == 'X86':
arch = pe32.ARCH_WIN32
elif machtype == 'AMD64':
arch = pe32.ARCH_WIN64
if arch != pe32.ARCH_WIN32 and arch != pe32.ARCH_WIN64:
logging.error('failed to detect CPU arch')
return arch
def __determineUrl(arch):
if arch == pe32.ARCH_WIN32:
logging.info('detected WIN32 version')
return 'http://files.kaoriya.net/vim/vim74-kaoriya-win32.zip'
elif arch == pe32.ARCH_WIN64:
logging.info('detected WIN64 version')
return 'http://files.kaoriya.net/vim/vim74-kaoriya-win64.zip'
else:
return None
class Progress(UpdaterProgress):
def begin_download(self):
print(_('Found update.'))
UpdaterProgress.begin_download(self)
def update(target_dir):
# Determine parameters.
rootdir = target_dir.strip('"\'')
url = __determineUrl(__detectArch(rootdir))
if not url:
print(_('Config error'))
return
# Execute the update.
workdir = os.path.join(rootdir, 'online_updater', 'var')
updater = Updater(name='vim74', url=url, target_dir=rootdir,
work_dir=workdir, progress=Progress())
result = updater.update()
# Show result message.
if result == Updater.COMPLETE:
print(_('Updated successfully.'))
delete(rootdir, 'vimrc')
delete(rootdir, 'gvimrc')
elif result == Updater.INCOMPLETE:
print(_('Incomplete update, retry later.'))
elif result == Updater.STAY:
print(_('No updates found.'))
def delete(target_dir, file_name):
rootdir = target_dir.strip('"\'')
fullPath = os.path.join(rootdir, file_name)
if os.path.exists(fullPath):
os.remove(fullPath)
if __name__ == '__main__':
#logging.basicConfig(level=logging.INFO)
if len(sys.argv) < 2:
# TODO: show usage.
pass
else:
retval = update(sys.argv[1])
exit(retval)