Commit b3491b19 authored by David Wilson's avatar David Wilson

master: Lazy-format more logging arguments, minor 3.x compat increments

parent 0e7cc55e
import Queue
import commands
import dis import dis
import errno import errno
import getpass import getpass
...@@ -22,6 +20,11 @@ import time ...@@ -22,6 +20,11 @@ import time
import types import types
import zlib import zlib
try:
import Queue
except ImportError:
import queue as Queue
if not hasattr(pkgutil, 'find_loader'): if not hasattr(pkgutil, 'find_loader'):
# find_loader() was new in >=2.5, but the modern pkgutil.py syntax has # find_loader() was new in >=2.5, but the modern pkgutil.py syntax has
# been kept intentionally 2.3 compatible so we can reuse it. # been kept intentionally 2.3 compatible so we can reuse it.
...@@ -51,13 +54,21 @@ def get_child_modules(path, fullname): ...@@ -51,13 +54,21 @@ def get_child_modules(path, fullname):
return ['%s.%s' % (fullname, name) for _, name, _ in it] return ['%s.%s' % (fullname, name) for _, name, _ in it]
def format_cmdline(args): class Argv(object):
return ' '.join( def __init__(self, argv):
commands.mkarg(arg).strip() self.argv = argv
if any(s in arg for s in (" '\"$")) else
arg def escape(self, x):
for arg in args s = '"'
) for c in x:
if c in '\\$"`':
s += '\\'
s += c
s += '"'
return s
def __str__(self):
return ' '.join(map(self.escape, self.argv))
def create_child(*args): def create_child(*args):
...@@ -73,7 +84,7 @@ def create_child(*args): ...@@ -73,7 +84,7 @@ def create_child(*args):
childfp.close() childfp.close()
LOG.debug('create_child() child %d fd %d, parent %d, cmd: %s', LOG.debug('create_child() child %d fd %d, parent %d, cmd: %s',
pid, parentfp.fileno(), os.getpid(), format_cmdline(args)) pid, parentfp.fileno(), os.getpid(), Argv(args))
return pid, os.dup(parentfp.fileno()) return pid, os.dup(parentfp.fileno())
...@@ -83,10 +94,11 @@ def flags(names): ...@@ -83,10 +94,11 @@ def flags(names):
return sum(getattr(termios, name) for name in names.split()) return sum(getattr(termios, name) for name in names.split())
def cfmakeraw((iflag, oflag, cflag, lflag, ispeed, ospeed, cc)): def cfmakeraw(flags):
"""Given a list returned by :py:func:`termios.tcgetattr`, return a list """Given a list returned by :py:func:`termios.tcgetattr`, return a list
that has been modified in the same manner as the `cfmakeraw()` C library that has been modified in the same manner as the `cfmakeraw()` C library
function.""" function."""
iflag, oflag, cflag, lflag, ispeed, ospeed, cc = flags
iflag &= ~flags('IGNBRK BRKINT PARMRK ISTRIP INLCR IGNCR ICRNL IXON') iflag &= ~flags('IGNBRK BRKINT PARMRK ISTRIP INLCR IGNCR ICRNL IXON')
oflag &= ~flags('OPOST IXOFF') oflag &= ~flags('OPOST IXOFF')
lflag &= ~flags('ECHO ECHOE ECHONL ICANON ISIG IEXTEN') lflag &= ~flags('ECHO ECHOE ECHONL ICANON ISIG IEXTEN')
...@@ -135,7 +147,7 @@ def tty_create_child(*args): ...@@ -135,7 +147,7 @@ def tty_create_child(*args):
os.close(slave_fd) os.close(slave_fd)
LOG.debug('tty_create_child() child %d fd %d, parent %d, cmd: %s', LOG.debug('tty_create_child() child %d fd %d, parent %d, cmd: %s',
pid, master_fd, os.getpid(), format_cmdline(args)) pid, master_fd, os.getpid(), Argv(args))
return pid, master_fd return pid, master_fd
......
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