Commit 267823ce authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼 Committed by Julien Muchembled

Various fixups for Python 3

parent e80ca878
...@@ -252,7 +252,7 @@ class Babel: ...@@ -252,7 +252,7 @@ class Babel:
unidentified = set(n) unidentified = set(n)
self.neighbours = neighbours = {} self.neighbours = neighbours = {}
a = len(self.network) a = len(self.network)
logging.info("Routes: %r", routes) logging.debug("Routes: %r", routes)
for route in routes: for route in routes:
assert route.flags & 1, route # installed assert route.flags & 1, route # installed
if route.prefix.startswith(b'\0\0\0\0\0\0\0\0\0\0\xff\xff'): if route.prefix.startswith(b'\0\0\0\0\0\0\0\0\0\0\xff\xff'):
......
...@@ -8,15 +8,6 @@ HMAC_LEN = len(hashlib.sha1(b'').digest()) ...@@ -8,15 +8,6 @@ HMAC_LEN = len(hashlib.sha1(b'').digest())
class ReexecException(Exception): class ReexecException(Exception):
pass pass
try:
subprocess.CalledProcessError(0, '', '')
except TypeError: # BBB: Python < 2.7
def __init__(self, returncode, cmd, output=None):
self.returncode = returncode
self.cmd = cmd
self.output = output
subprocess.CalledProcessError.__init__ = __init__
logging_levels = logging.WARNING, logging.INFO, logging.DEBUG, 5 logging_levels = logging.WARNING, logging.INFO, logging.DEBUG, 5
class FileHandler(logging.FileHandler): class FileHandler(logging.FileHandler):
...@@ -167,17 +158,19 @@ class Popen(subprocess.Popen): ...@@ -167,17 +158,19 @@ class Popen(subprocess.Popen):
def send_signal(self, sig): def send_signal(self, sig):
logging.info('Sending signal %s to pid %s %r', logging.info('Sending signal %s to pid %s %r',
sig, self.pid, self._args) sig, self.pid, self._args)
super(Popen, self).send_signal(sig) # We don't need the change from https://bugs.python.org/issue38630
# and it would complicate stop()
assert self.returncode is None
os.kill(self.pid, sig)
def stop(self): def stop(self):
if self.pid and self.returncode is None: if self.pid and self.returncode is None:
self.terminate() self.terminate()
t = threading.Timer(5, self.kill) t = threading.Timer(5, self.kill)
t.start() t.start()
r = os.waitid(os.P_PID, self.pid, os.WNOWAIT) os.waitid(os.P_PID, self.pid, os.WEXITED | os.WNOWAIT)
t.cancel() t.cancel()
self.poll() self.poll()
return r
def setCloexec(fd): def setCloexec(fd):
......
...@@ -6,15 +6,9 @@ def _git_call(*args): ...@@ -6,15 +6,9 @@ def _git_call(*args):
return _S.call(("git", "-c", "safe.directory=" + _d) + args, cwd=_d) return _S.call(("git", "-c", "safe.directory=" + _d) + args, cwd=_d)
def _git_output(*args): def _git_output(*args):
p = _S.Popen( return _S.check_output(
("git", "-c", "safe.directory=" + _d) + args, ("git", "-c", "safe.directory=" + _d) + args,
cwd=_d, cwd=_d, text=True).strip()
stdout=_S.PIPE,
stderr=_S.PIPE)
out, err = p.communicate()
if p.returncode:
raise _S.CalledProcessError(p.returncode, "git", err)
return out.strip()
_git_call("update-index", "-q", "--refresh") _git_call("update-index", "-q", "--refresh")
dirty = _git_call("diff-index", "--quiet", "HEAD", "--") dirty = _git_call("diff-index", "--quiet", "HEAD", "--")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment