Run 2to3 utility

This commit is contained in:
Moritz Lell 2019-10-27 14:19:50 +01:00
commit 491040ea72
12 changed files with 26 additions and 26 deletions

View file

@ -11,7 +11,7 @@ def _nice(t):
def _try_stat(filename): def _try_stat(filename):
try: try:
return os.lstat(filename) return os.lstat(filename)
except OSError, e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
return None return None
else: else:
@ -90,7 +90,7 @@ def start_stdin_log_reader(status, details, pretty, color,
argv.append('--color' if color >= 2 else '--no-color') argv.append('--color' if color >= 2 else '--no-color')
argv.append('-') argv.append('-')
os.execvp(argv[0], argv) os.execvp(argv[0], argv)
except Exception, e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
sys.stderr.write('redo-log: exec: %s\n' % e) sys.stderr.write('redo-log: exec: %s\n' % e)
finally: finally:
os._exit(99) os._exit(99)
@ -138,7 +138,7 @@ class _BuildJob(object):
if is_target: if is_target:
meta('unchanged', state.target_relpath(self.t)) meta('unchanged', state.target_relpath(self.t))
return self._finalize(0) return self._finalize(0)
except helpers.ImmediateReturn, e: except helpers.ImmediateReturn as e:
return self._finalize(e.rv) return self._finalize(e.rv)
if env.v.NO_OOB or dirty == True: # pylint: disable=singleton-comparison if env.v.NO_OOB or dirty == True: # pylint: disable=singleton-comparison
@ -398,7 +398,7 @@ class _BuildJob(object):
helpers.unlink(self.tmpname) helpers.unlink(self.tmpname)
try: try:
newf = open(self.tmpname, 'w') newf = open(self.tmpname, 'w')
except IOError, e: except IOError as e:
dnt = os.path.dirname(os.path.abspath(t)) dnt = os.path.dirname(os.path.abspath(t))
if not os.path.exists(dnt): if not os.path.exists(dnt):
# This could happen, so report a simple error message # This could happen, so report a simple error message
@ -424,7 +424,7 @@ class _BuildJob(object):
try: try:
# Atomically replace the target file # Atomically replace the target file
os.rename(self.tmpname, t) os.rename(self.tmpname, t)
except OSError, e: except OSError as e:
# This could happen for, eg. a permissions error on # This could happen for, eg. a permissions error on
# the target directory. # the target directory.
err('%s: rename %s: %s\n' % (t, self.tmpname, e)) err('%s: rename %s: %s\n' % (t, self.tmpname, e))

View file

@ -52,7 +52,7 @@ def main():
finally: finally:
try: try:
jobserver.force_return_tokens() jobserver.force_return_tokens()
except Exception, e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
traceback.print_exc(100, sys.stderr) traceback.print_exc(100, sys.stderr)
err('unexpected error: %r\n' % e) err('unexpected error: %r\n' % e)
rv = 1 rv = 1

View file

@ -102,7 +102,7 @@ def catlog(t):
if not f: if not f:
try: try:
f = open(logname) f = open(logname)
except IOError, e: except IOError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
# ignore files without logs # ignore files without logs
pass pass
@ -231,7 +231,7 @@ def catlog(t):
status = None status = None
if line_head: if line_head:
# partial line never got terminated # partial line never got terminated
print line_head print(line_head)
if t != '-': if t != '-':
assert depth[-1] == t assert depth[-1] == t
depth.pop(-1) depth.pop(-1)
@ -274,7 +274,7 @@ def main():
catlog(t) catlog(t)
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit(200) sys.exit(200)
except IOError, e: except IOError as e:
if e.errno == errno.EPIPE: if e.errno == errno.EPIPE:
pass pass
else: else:

View file

@ -36,7 +36,7 @@ def main():
is_checked=is_checked, is_checked=is_checked,
set_checked=set_checked, set_checked=set_checked,
log_override=log_override): log_override=log_override):
print state.relpath(os.path.join(env.v.BASE, f.name), cwd) print(state.relpath(os.path.join(env.v.BASE, f.name), cwd))
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -48,7 +48,7 @@ def main():
if opt.version: if opt.version:
from . import version from . import version
print version.TAG print(version.TAG)
sys.exit(0) sys.exit(0)
if opt.debug: if opt.debug:
os.environ['REDO_DEBUG'] = str(opt.debug or 0) os.environ['REDO_DEBUG'] = str(opt.debug or 0)
@ -114,7 +114,7 @@ def main():
finally: finally:
try: try:
jobserver.force_return_tokens() jobserver.force_return_tokens()
except Exception, e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
traceback.print_exc(100, sys.stderr) traceback.print_exc(100, sys.stderr)
err('unexpected error: %r\n' % e) err('unexpected error: %r\n' % e)
retcode = 1 retcode = 1

View file

@ -16,7 +16,7 @@ def main():
cwd = os.getcwd() cwd = os.getcwd()
for f in state.files(): for f in state.files():
if f.is_source(): if f.is_source():
print state.relpath(os.path.join(env.v.BASE, f.name), cwd) print(state.relpath(os.path.join(env.v.BASE, f.name), cwd))
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -16,7 +16,7 @@ def main():
cwd = os.getcwd() cwd = os.getcwd()
for f in state.files(): for f in state.files():
if f.is_target(): if f.is_target():
print state.relpath(os.path.join(env.v.BASE, f.name), cwd) print(state.relpath(os.path.join(env.v.BASE, f.name), cwd))
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -26,7 +26,7 @@ def main():
relpath = os.path.relpath(dopath, '.') relpath = os.path.relpath(dopath, '.')
exists = os.path.exists(dopath) exists = os.path.exists(dopath)
assert '\n' not in relpath assert '\n' not in relpath
print relpath print(relpath)
if exists: if exists:
sys.exit(0) sys.exit(0)
sys.exit(1) # no appropriate dofile found sys.exit(1) # no appropriate dofile found

View file

@ -16,7 +16,7 @@ def unlink(f):
""" """
try: try:
os.unlink(f) os.unlink(f)
except OSError, e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
pass # it doesn't exist, that's what you asked for pass # it doesn't exist, that's what you asked for

View file

@ -98,7 +98,7 @@ def _create_tokens(n):
global _mytokens, _cheats global _mytokens, _cheats
assert n >= 0 assert n >= 0
assert _cheats >= 0 assert _cheats >= 0
for _ in xrange(n): for _ in range(n):
if _cheats > 0: if _cheats > 0:
_cheats -= 1 _cheats -= 1
else: else:
@ -118,7 +118,7 @@ def _release(n):
assert _mytokens >= n assert _mytokens >= n
_debug('%d,%d -> release(%d)\n' % (_mytokens, _cheats, n)) _debug('%d,%d -> release(%d)\n' % (_mytokens, _cheats, n))
n_to_share = 0 n_to_share = 0
for _ in xrange(n): for _ in range(n):
_mytokens -= 1 _mytokens -= 1
if _cheats > 0: if _cheats > 0:
_cheats -= 1 _cheats -= 1
@ -176,7 +176,7 @@ def _try_read(fd, n):
signal.setitimer(signal.ITIMER_REAL, 0.01, 0.01) # emergency fallback signal.setitimer(signal.ITIMER_REAL, 0.01, 0.01) # emergency fallback
try: try:
b = os.read(fd, 1) b = os.read(fd, 1)
except OSError, e: except OSError as e:
if e.errno in (errno.EAGAIN, errno.EINTR): if e.errno in (errno.EAGAIN, errno.EINTR):
# interrupted or it was nonblocking # interrupted or it was nonblocking
return None # try again return None # try again
@ -297,7 +297,7 @@ def _wait(want_token, max_delay):
Returns: Returns:
None None
""" """
rfds = _waitfds.keys() rfds = list(_waitfds.keys())
if want_token: if want_token:
rfds.append(_tokenfds[0]) rfds.append(_tokenfds[0])
assert rfds assert rfds

View file

@ -239,12 +239,12 @@ class Options:
""" """
try: try:
(flags,extra) = self.optfunc(args, self._shortopts, self._longopts) (flags,extra) = self.optfunc(args, self._shortopts, self._longopts)
except getopt.GetoptError, e: except getopt.GetoptError as e:
self.fatal(e) self.fatal(e)
opt = OptDict() opt = OptDict()
for k,v in self._defaults.iteritems(): for k,v in self._defaults.items():
k = self._aliases[k] k = self._aliases[k]
opt[k] = v opt[k] = v
@ -268,6 +268,6 @@ class Options:
else: else:
v = _intify(v) v = _intify(v)
opt[k] = v opt[k] = v
for (f1,f2) in self._aliases.iteritems(): for (f1,f2) in self._aliases.items():
opt[f1] = opt._opts.get(f2) opt[f1] = opt._opts.get(f2)
return (opt,flags,extra) return (opt,flags,extra)

View file

@ -46,14 +46,14 @@ def db():
dbfile = '%s/db.sqlite3' % dbdir dbfile = '%s/db.sqlite3' % dbdir
try: try:
os.mkdir(dbdir) os.mkdir(dbdir)
except OSError, e: except OSError as e:
if e.errno == errno.EEXIST: if e.errno == errno.EEXIST:
pass # if it exists, that's okay pass # if it exists, that's okay
else: else:
raise raise
_lockfile = os.open(os.path.join(env.v.BASE, '.redo/locks'), _lockfile = os.open(os.path.join(env.v.BASE, '.redo/locks'),
os.O_RDWR | os.O_CREAT, 0666) os.O_RDWR | os.O_CREAT, 0o666)
close_on_exec(_lockfile, True) close_on_exec(_lockfile, True)
if env.is_toplevel and detect_broken_locks(): if env.is_toplevel and detect_broken_locks():
env.mark_locks_broken() env.mark_locks_broken()
@ -508,7 +508,7 @@ class Lock(object):
assert not self.owned assert not self.owned
try: try:
fcntl.lockf(_lockfile, fcntl.LOCK_EX|fcntl.LOCK_NB, 1, self.fid) fcntl.lockf(_lockfile, fcntl.LOCK_EX|fcntl.LOCK_NB, 1, self.fid)
except IOError, e: except IOError as e:
if e.errno in (errno.EAGAIN, errno.EACCES): if e.errno in (errno.EAGAIN, errno.EACCES):
pass # someone else has it locked pass # someone else has it locked
else: else: