-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim-plugin-release
executable file
·225 lines (177 loc) · 6.33 KB
/
vim-plugin-release
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/python -u
# -u for unbuffered I/O
import sys
import os
import re
from time import strftime, localtime
import mechanize
import gnomekeyring as gkey
from subprocess import Popen, PIPE, check_call, CalledProcessError
import shlex
from tempfile import mkstemp
import md5
br = mechanize.Browser()
def system(cmd, msg = None):
p = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)
(stdout, stderr) = p.communicate()
if p.returncode != 0:
if msg is None:
print 'Error executing', cmd, '!'
else:
print msg
print stderr
exit()
return stdout.splitlines()
def get_script_files():
def is_not_ignored(file):
output = system('git check-attr export-ignore ' + file)[0]
return output.split()[-1] != 'set'
files = system('git ls-files --cached')
return [file for file in files if is_not_ignored(file)]
def update_files(scrver):
print 'Updating version number in files to', scrver + '...',
pat = re.compile(r'^(?P<text>(" )?Version:\s+)[0-9.]+$')
files = get_script_files()
for fname in files:
with open(fname) as f:
out_fname = fname + '.tmp'
out = open(out_fname, 'w')
for line in f:
out.write(re.sub(pat, lambda m: m.group('text') + scrver, line))
out.close()
os.rename(out_fname, fname)
print 'done.'
def update_gh_site(scrver, scrcommfile, reldate):
print 'Updating website...',
system('git checkout gh-pages')
out_fname = '_posts/' + reldate + '-' + scrver + '.markdown'
with open(out_fname, 'w') as outf:
outf.write('---\n')
outf.write('title: ' + scrver + '\n')
outf.write('---\n\n')
with open(scrcommfile) as inf:
for line in inf:
outf.write(line)
system('git add ' + out_fname)
system('git commit -m "Version ' + scrver + '"')
system('git checkout master')
print 'done.'
def login():
print 'Logging in...',
pwdata = gkey.find_network_password_sync(server = 'www.vim.org',
user = 'majutsushi')[0]
br.open('http://www.vim.org/login.php')
br.select_form(name = 'login')
br.form['userName'] = pwdata['user']
br.form['password'] = pwdata['password']
br.submit()
print 'done.'
def upload_script(scrid, scrfile, vimver, scrver, scrcomment):
print 'Uploading script file ' + scrfile + '...',
br.open('http://www.vim.org/scripts/script.php?script_id=' + scrid)
br.follow_link(text = 'upload new version')
br.select_form(name = 'script')
br.form.add_file(open(scrfile), content_type = 'text/plain',
filename = scrfile, name = 'script_file')
br.form['vim_version'] = [str(vimver)]
br.form['script_version'] = scrver
br.form['version_comment'] = scrcomment
br.submit(label = 'upload')
print 'done.'
def make_vimball(scrname):
print 'Creating Vimball...',
export = get_script_files()
filecmds = ''
for file in export:
filecmds += ' -c ":put =\'' + file + '\'" '
cmd = 'vim ' + filecmds + \
' -c ":g/^$/d" ' + \
' -c ":let g:vimball_home = \'.\'" ' + \
' -c ":%MkVimball! ' + scrname + '"' + \
' -c ":q!"'
system(cmd)
print 'done.'
return os.path.abspath(scrname + '.vmb')
def call_vim(filename, args = None):
def abort():
print 'Aborted.'
os.unlink(scrcommfile)
exit()
cmd = 'vim ' + filename
if args is not None:
cmd += ' ' + args
timestamp = os.stat(filename).st_mtime
with open(filename) as f:
checksum = md5.md5(f.read()).hexdigest()
try:
check_call(shlex.split(cmd))
except CalledProcessError:
abort()
if timestamp == os.stat(filename).st_mtime:
abort()
else:
with open(filename) as f:
newchecksum = md5.md5(f.read()).hexdigest()
if newchecksum == checksum:
abort()
if __name__ == '__main__':
system('git diff --no-ext-diff --quiet --exit-code --ignore-submodules',
'Error: workdir is dirty!')
if not os.path.exists('.info'):
print 'No .info file found, exiting.'
exit()
with open('.info') as infofile:
info = infofile.readlines()
scrname = info[0].strip()
scrid = info[1].strip()
print 'Scriptname:', scrname
print 'Script ID:', scrid
oscrvers = system('git describe --tags --abbrev=0')[0]
oscrmatch = re.match('^v(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<bugfix>\d+))?$', oscrvers)
omajor = oscrmatch.group('major')
ominor = oscrmatch.group('minor')
obugfix = oscrmatch.group('bugfix')
if obugfix is not None:
print 'Old version:', omajor + '.' + ominor + '.' + obugfix
else:
print 'Old version:', omajor + '.' + ominor
scrver = raw_input('New version [' + omajor + '.' + str(int(ominor) + 1) + ']: ')
if len(scrver) == 0:
scrver = omajor + '.' + str(int(ominor) + 1)
vimver = raw_input('Vim version [7.0]: ')
if len(vimver) == 0:
vimver = 7.0
reldate = strftime('%Y-%m-%d', localtime())
[handle, scrcommfile] = mkstemp()
os.close(handle)
call_vim(scrcommfile)
docfile = 'doc/' + scrname + '.txt'
headerpat = r'^\d\+\.\d\+\(\.\d\+\)\? (\d\{4}-\d\{2}-\d\{2})$'
docargs = ' -c "call search(\'' + headerpat + '\')"'
docargs += ' -c "normal! 2k"'
docargs += ' -c "silent put =\'\'"'
docargs += ' -c "read ' + scrcommfile + '"'
docargs += ' -c "normal! >ipgqip{"'
docargs += ' -c "silent put =\'' + scrver + ' (' + reldate + ')\'"'
# docargs += ' -c "wq"'
call_vim(docfile, docargs)
update_files(scrver)
print 'Committing version', scrver + '...',
system('git commit -a -m "Version ' + scrver + '"')
print 'done.'
print 'Tagging version', scrver + '...',
system('git tag v' + scrver)
print 'done.'
update_gh_site(scrver, scrcommfile, reldate)
print 'Pushing changes...',
system('git push origin master')
system('git push origin gh-pages')
system('git push --tags')
print 'done.'
with open(scrcommfile) as f:
scrcomment = f.read()
vimball = make_vimball(scrname)
login()
upload_script(scrid, vimball, vimver, scrver, scrcomment)
os.unlink(vimball)
os.unlink(scrcommfile)