Python 2.6 compatibility

Tested on
- Vim 7.2.330
- Python 2.6.5
- Ubuntu 10.04
- https://gist.github.com/junegunn/863dcbd78eadece788cd
This commit is contained in:
Junegunn Choi 2015-03-08 02:00:06 +09:00
parent 30a2c5cc14
commit 3c6ac68947

View File

@ -764,7 +764,7 @@ function! s:update_impl(pull, force, args) abort
silent python import platform; print(platform.python_version()) silent python import platform; print(platform.python_version())
redir END redir END
let s:py2 = s:version_requirement( let s:py2 = s:version_requirement(
\ map(split(split(pyv)[0], '\.'), 'str2nr(v:val)'), [2, 7]) \ map(split(split(pyv)[0], '\.'), 'str2nr(v:val)'), [2, 6])
endif endif
if (s:py2 || s:ruby) && !s:nvim && s:update.threads > 1 if (s:py2 || s:ruby) && !s:nvim && s:update.threads > 1
try try
@ -1052,7 +1052,7 @@ class GLog(object):
fname = cls.LOGDIR + os.path.sep + name fname = cls.LOGDIR + os.path.sep + name
with open(fname, 'ab') as flog: with open(fname, 'ab') as flog:
ltime = datetime.datetime.now().strftime("%H:%M:%S.%f") ltime = datetime.datetime.now().strftime("%H:%M:%S.%f")
msg = '[{},{}] {}{}'.format(name, ltime, msg, '\n') msg = '[{0},{1}] {2}{3}'.format(name, ltime, msg, '\n')
flog.write(msg) flog.write(msg)
class Buffer(object): class Buffer(object):
@ -1067,7 +1067,7 @@ class Buffer(object):
def _where(self, name): def _where(self, name):
""" Find first line with name in current buffer. Return line num. """ """ Find first line with name in current buffer. Return line num. """
found, lnum = False, 0 found, lnum = False, 0
matcher = re.compile('^[-+x*] {}:'.format(name)) matcher = re.compile('^[-+x*] {0}:'.format(name))
for line in vim.current.buffer: for line in vim.current.buffer:
if matcher.search(line) is not None: if matcher.search(line) is not None:
found = True found = True
@ -1080,10 +1080,10 @@ class Buffer(object):
def header(self): def header(self):
curbuf = vim.current.buffer curbuf = vim.current.buffer
curbuf[0] = self.event + ' plugins ({}/{})'.format(len(self.bar), self.num_plugs) curbuf[0] = self.event + ' plugins ({0}/{1})'.format(len(self.bar), self.num_plugs)
num_spaces = self.num_plugs - len(self.bar) num_spaces = self.num_plugs - len(self.bar)
curbuf[1] = '[{}{}]'.format(self.bar, num_spaces * ' ') curbuf[1] = '[{0}{1}]'.format(self.bar, num_spaces * ' ')
vim.command('normal! 2G') vim.command('normal! 2G')
if not self.is_win: if not self.is_win:
@ -1095,14 +1095,14 @@ class Buffer(object):
def _write(self, action, name, lines): def _write(self, action, name, lines):
first, rest = lines[0], lines[1:] first, rest = lines[0], lines[1:]
msg = ['{} {}{}{}'.format(action, name, ': ' if first else '', first)] msg = ['{0} {1}{2}{3}'.format(action, name, ': ' if first else '', first)]
padded_rest = [' ' + line for line in rest] padded_rest = [' ' + line for line in rest]
msg.extend(padded_rest) msg.extend(padded_rest)
try: try:
if action == Action.ERROR: if action == Action.ERROR:
self.bar += 'x' self.bar += 'x'
vim.command("call add(s:update.errors, '{}')".format(name)) vim.command("call add(s:update.errors, '{0}')".format(name))
elif action == Action.DONE: elif action == Action.DONE:
self.bar += '=' self.bar += '='
@ -1110,7 +1110,7 @@ class Buffer(object):
lnum = self._where(name) lnum = self._where(name)
if lnum != -1: # Found matching line num if lnum != -1: # Found matching line num
del curbuf[lnum] del curbuf[lnum]
if lnum > self.maxy and action in {Action.INSTALL, Action.UPDATE}: if lnum > self.maxy and action in set([Action.INSTALL, Action.UPDATE]):
lnum = 3 lnum = 3
else: else:
lnum = 3 lnum = 3
@ -1145,7 +1145,7 @@ class Command(object):
for count in range(3, 0, -1): for count in range(3, 0, -1):
if G_STOP.is_set(): if G_STOP.is_set():
raise KeyboardInterrupt raise KeyboardInterrupt
msg = 'Timeout. Will retry in {} second{} ...'.format( msg = 'Timeout. Will retry in {0} second{1} ...'.format(
count, 's' if count != 1 else '') count, 's' if count != 1 else '')
self.callback([msg]) self.callback([msg])
time.sleep(1) time.sleep(1)
@ -1217,7 +1217,7 @@ class Plugin(object):
else: else:
self.install() self.install()
with self.lock: with self.lock:
vim.command("let s:update.new['{}'] = 1".format(self.name)) vim.command("let s:update.new['{0}'] = 1".format(self.name))
except (CmdTimedOut, CmdFailed, InvalidURI) as exc: except (CmdTimedOut, CmdFailed, InvalidURI) as exc:
self.write(Action.ERROR, self.name, exc.message) self.write(Action.ERROR, self.name, exc.message)
except KeyboardInterrupt: except KeyboardInterrupt:
@ -1225,7 +1225,7 @@ class Plugin(object):
self.write(Action.ERROR, self.name, ['Interrupted!']) self.write(Action.ERROR, self.name, ['Interrupted!'])
except: except:
# Any exception except those above print stack trace # Any exception except those above print stack trace
msg = 'Trace:\n{}'.format(traceback.format_exc().rstrip()) msg = 'Trace:\n{0}'.format(traceback.format_exc().rstrip())
self.write(Action.ERROR, self.name, msg.split('\n')) self.write(Action.ERROR, self.name, msg.split('\n'))
raise raise
@ -1242,7 +1242,7 @@ class Plugin(object):
self.write(Action.INSTALL, self.name, ['Installing ...']) self.write(Action.INSTALL, self.name, ['Installing ...'])
callback = functools.partial(self.buf.write, Action.INSTALL, self.name) callback = functools.partial(self.buf.write, Action.INSTALL, self.name)
cmd = 'git clone {} --recursive {} -b {} {} 2>&1'.format( cmd = 'git clone {0} --recursive {1} -b {2} {3} 2>&1'.format(
G_PROGRESS, self.args['uri'], self.checkout, esc(target)) G_PROGRESS, self.args['uri'], self.checkout, esc(target))
com = Command(cmd, None, G_TIMEOUT, G_RETRIES, callback, clean(target)) com = Command(cmd, None, G_TIMEOUT, G_RETRIES, callback, clean(target))
result = com.attempt_cmd() result = com.attempt_cmd()
@ -1254,17 +1254,17 @@ class Plugin(object):
expect_uri = re.sub(match, '', self.args['uri']) expect_uri = re.sub(match, '', self.args['uri'])
if actual_uri != expect_uri: if actual_uri != expect_uri:
msg = ['', msg = ['',
'Invalid URI: {}'.format(actual_uri), 'Invalid URI: {0}'.format(actual_uri),
'Expected {}'.format(expect_uri), 'Expected {0}'.format(expect_uri),
'PlugClean required.'] 'PlugClean required.']
raise InvalidURI(msg) raise InvalidURI(msg)
if G_PULL: if G_PULL:
self.write(Action.UPDATE, self.name, ['Updating ...']) self.write(Action.UPDATE, self.name, ['Updating ...'])
callback = functools.partial(self.buf.write, Action.UPDATE, self.name) callback = functools.partial(self.buf.write, Action.UPDATE, self.name)
cmds = ['git fetch {}'.format(G_PROGRESS), cmds = ['git fetch {0}'.format(G_PROGRESS),
'git checkout -q {}'.format(self.checkout), 'git checkout -q {0}'.format(self.checkout),
'git merge --ff-only {}'.format(self.merge), 'git merge --ff-only {0}'.format(self.merge),
'git submodule update --init --recursive'] 'git submodule update --init --recursive']
cmd = ' 2>&1 && '.join(cmds) cmd = ' 2>&1 && '.join(cmds)
GLog.write(cmd) GLog.write(cmd)
@ -1282,7 +1282,7 @@ class Plugin(object):
return result[-1] return result[-1]
def write(self, action, name, msg): def write(self, action, name, msg):
GLog.write('{} {}: {}'.format(action, name, '\n'.join(msg))) GLog.write('{0} {1}: {2}'.format(action, name, '\n'.join(msg)))
self.buf.write(action, name, msg) self.buf.write(action, name, msg)
class PlugThread(thr.Thread): class PlugThread(thr.Thread):
@ -1298,7 +1298,7 @@ class PlugThread(thr.Thread):
try: try:
while not G_STOP.is_set(): while not G_STOP.is_set():
name, args = work_q.get_nowait() name, args = work_q.get_nowait()
GLog.write('{}: Dir {}'.format(name, args['dir'])) GLog.write('{0}: Dir {1}'.format(name, args['dir']))
plug = Plugin(name, args, buf, lock) plug = Plugin(name, args, buf, lock)
plug.manage() plug.manage()
work_q.task_done() work_q.task_done()
@ -1348,9 +1348,9 @@ def main():
plugs = vim.eval('s:update.todo') plugs = vim.eval('s:update.todo')
mac_gui = vim.eval('s:mac_gui') == '1' mac_gui = vim.eval('s:mac_gui') == '1'
is_win = vim.eval('s:is_win') == '1' is_win = vim.eval('s:is_win') == '1'
GLog.write('Plugs: {}'.format(plugs)) GLog.write('Plugs: {0}'.format(plugs))
GLog.write('PULL: {}, WIN: {}, MAC: {}'.format(G_PULL, is_win, mac_gui)) GLog.write('PULL: {0}, WIN: {1}, MAC: {2}'.format(G_PULL, is_win, mac_gui))
GLog.write('Num Threads: {}'.format(nthreads)) GLog.write('Num Threads: {0}'.format(nthreads))
lock = thr.Lock() lock = thr.Lock()
buf = Buffer(lock, len(plugs)) buf = Buffer(lock, len(plugs))