Skip to content

Commit

Permalink
Replace broken function-decorator context.quiet with working context.…
Browse files Browse the repository at this point in the history
…quietfunc

Fixes: ae6a074
  • Loading branch information
zachriggle committed Jan 17, 2017
1 parent fb16e15 commit 9ace73a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
38 changes: 19 additions & 19 deletions pwnlib/adb/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def adb(argv, *a, **kw):

return tubes.process.process(context.adb + argv, *a, **kw).recvall()

@context.quiet
@context.quietfunc
def devices(serial=None):
"""Returns a list of ``Device`` objects corresponding to the connected devices."""
with Client() as c:
Expand Down Expand Up @@ -552,7 +552,7 @@ def push(local_path, remote_path):
return c.write(remote_path,
misc.read(local_path),
callback=_create_adb_push_pull_callback(w))
@context.quiet
@context.quietfunc
@with_device
def read(path, target=None, callback=None):
"""Download a file from the device, and extract its contents.
Expand Down Expand Up @@ -584,7 +584,7 @@ def read(path, target=None, callback=None):

return data

@context.quiet
@context.quietfunc
@with_device
def write(path, data=''):
"""Create a file on the device with the provided contents.
Expand All @@ -602,7 +602,7 @@ def write(path, data=''):
misc.write(temp.name, data)
push(temp.name, path)

@context.quiet
@context.quietfunc
@with_device
def mkdir(path):
"""Create a directory on the target device.
Expand Down Expand Up @@ -645,7 +645,7 @@ def mkdir(path):
if result:
log.error(result)

@context.quiet
@context.quietfunc
@with_device
def makedirs(path):
"""Create a directory and all parent directories on the target device.
Expand All @@ -664,7 +664,7 @@ def makedirs(path):

mkdir(path)

@context.quiet
@context.quietfunc
@with_device
def exists(path):
"""Return :const:`True` if ``path`` exists on the target device.
Expand All @@ -681,7 +681,7 @@ def exists(path):
with Client() as c:
return bool(c.stat(path))

@context.quiet
@context.quietfunc
@with_device
def isdir(path):
"""Return :const:`True` if ``path`` is a on the target device.
Expand All @@ -699,7 +699,7 @@ def isdir(path):
st = c.stat(path)
return bool(st and stat.S_ISDIR(st['mode']))

@context.quiet
@context.quietfunc
@with_device
def unlink(path, recursive=False):
"""Unlinks a file or directory on the target device.
Expand Down Expand Up @@ -816,7 +816,7 @@ def forward(port):
start_forwarding = adb(['forward', tcp_port, tcp_port])
atexit.register(lambda: adb(['forward', '--remove', tcp_port]))

@context.quiet
@context.quietfunc
@with_device
def logcat(stream=False):
"""Reads the system log file.
Expand Down Expand Up @@ -952,7 +952,7 @@ def address(self):
return self.symbols['_text']

@property
@context.quiet
@context.quietfunc
def symbols(self):
"""Returns a dictionary of kernel symbols"""
result = {}
Expand All @@ -964,7 +964,7 @@ def symbols(self):
return result

@property
@context.quiet
@context.quietfunc
def kallsyms(self):
"""Returns the raw output of kallsyms"""
if not self._kallsyms:
Expand All @@ -975,20 +975,20 @@ def kallsyms(self):
return self._kallsyms

@property
@context.quiet
@context.quietfunc
def version(self):
"""Returns the kernel version of the device."""
root()
return read('/proc/version').strip()

@property
@context.quiet
@context.quietfunc
def cmdline(self):
root()
return read('/proc/cmdline').strip()

@property
@context.quiet
@context.quietfunc
def lastmsg(self):
root()
if 'last_kmsg' in listdir('/proc'):
Expand Down Expand Up @@ -1240,15 +1240,15 @@ def readlink(path):

class Partitions(object):
@property
@context.quiet
@context.quietfunc
def by_name_dir(self):
return next(find('/dev/block/platform','by-name'))

@context.quiet
@context.quietfunc
def __dir__(self):
return list(self)

@context.quiet
@context.quietfunc
@with_device
def __iter__(self):
root()
Expand All @@ -1257,7 +1257,7 @@ def __iter__(self):
for name in listdir(self.by_name_dir):
yield name

@context.quiet
@context.quietfunc
@with_device
def __getattr__(self, attr):
for name in self:
Expand Down Expand Up @@ -1327,7 +1327,7 @@ def uninstall(package, *arguments):
with context.quiet:
return process(['pm','uninstall',package] + list(arguments)).recvall()

@context.quiet
@context.quietfunc
def packages():
"""Returns a list of packages installed on the system"""
packages = process(['pm', 'list', 'packages']).recvall()
Expand Down
11 changes: 6 additions & 5 deletions pwnlib/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,13 @@ def silent(self, function=None):
def quiet(self, function=None):
"""Disables all non-error logging within the enclosed scope,
*unless* the debugging level is set to 'debug' or lower."""
if not function:
level = 'error'
if context.log_level <= logging.DEBUG:
level = None
return self.local(function, log_level=level)
level = 'error'
if context.log_level <= logging.DEBUG:
level = None
return self.local(function, log_level=level)

def quietfunc(self, function):
"""Similar to :attr:`quiet`, but wraps a whole function."""
@functools.wraps(function)
def wrapper(*a, **kw):
level = 'error'
Expand Down

0 comments on commit 9ace73a

Please sign in to comment.