-
Notifications
You must be signed in to change notification settings - Fork 5
/
build_vimball.py
executable file
·107 lines (95 loc) · 3.26 KB
/
build_vimball.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
# vi:set ts=8 sts=4 sw=4 et tw=80:
"""Script to build the Vim run time files."""
# Python 2-3 compatibility.
from __future__ import print_function
import sys
import os
import string
import tempfile
import subprocess
import shutil
import importlib
from lib.clewn import __version__
DEBUGGERS = ('simple', 'gdb', 'pdb')
RUNTIME = [
'autoload/pyclewn/start.vim',
'autoload/pyclewn/buffers.vim',
'autoload/pyclewn/version.vim',
'doc/pyclewn.txt',
'plugin/pyclewn.vim',
'syntax/clewn_variables.vim',
'macros/.pyclewn_keys.gdb',
'macros/.pyclewn_keys.pdb',
'macros/.pyclewn_keys.simple',
]
VERSION_FUNC = """
function pyclewn#version#RuntimeVersion()
return "%s"
endfunction
"""
def keymap_files():
"""Update the key map files for each debugger."""
with open('runtime/macros/.pyclewn_keys.template') as tf:
print('Updating:')
template = tf.read()
for d in DEBUGGERS:
filename = 'runtime/macros/.pyclewn_keys.%s' % d
try:
module = importlib.import_module('.%s' % d, 'lib.clewn')
except ImportError:
print('Warning: cannot update %s' % filename, file=sys.stderr)
continue
with open(filename, 'w') as f:
f.write(string.Template(template).substitute(clazz=d))
mapkeys = getattr(module, 'MAPKEYS')
for k in sorted(mapkeys):
if len(mapkeys[k]) == 2:
comment = ' # ' + mapkeys[k][1]
f.write('# %s%s\n' % (('%s : %s' %
(k, mapkeys[k][0])).ljust(30), comment))
else:
f.write('# %s : %s\n' % (k, mapkeys[k][0]))
print(' %s' % filename)
def vimball():
"""Build the vimball."""
fd, tmpname = tempfile.mkstemp(prefix='vimball', suffix='.clewn')
args = ['vim', '-u', 'NORC', '-vN',
'-c', 'edit %s' % tmpname,
'-c', '%MkVimball! runtime/pyclewn runtime',
'-c', 'quit',
]
# Create version.vim.
version = __version__ + '.' + subprocess.check_output(
['hg', 'id', '-i'], universal_newlines=True)
with open('runtime/autoload/pyclewn/version.vim', 'w') as f:
f.write(VERSION_FUNC % version.rstrip('+\n'))
data_dir = 'lib/clewn/runtime'
if not os.path.exists(data_dir):
os.mkdir(data_dir)
# Remove the existing vimballs.
for dirpath, dirnames, filenames in os.walk(data_dir):
if dirpath == data_dir:
for fname in filenames:
if fname.startswith('pyclewn-') and fname.endswith('.vmb'):
print('Removing', fname)
os.unlink(os.path.join(dirpath, fname))
# Build the vimball.
try:
with os.fdopen(fd, 'w') as f:
f.write('\n'.join(RUNTIME))
f.close()
subprocess.call(args)
finally:
try:
os.unlink(tmpname)
except OSError:
pass
vimball = os.path.join(data_dir, 'pyclewn-%s.vmb' % __version__)
print('Creation of', vimball)
shutil.move('runtime/pyclewn.vmb', vimball)
def main():
keymap_files()
vimball()
if __name__ == '__main__':
main()