Commit d9c6da75 authored by Luke Macken's avatar Luke Macken

pep8 all the things

parent 2f5c59ac
...@@ -33,6 +33,7 @@ import warnings ...@@ -33,6 +33,7 @@ import warnings
from utils import run from utils import run
class CodeInjector(object): class CodeInjector(object):
"""Injects code into a running Python process""" """Injects code into a running Python process"""
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
from utils import run from utils import run
class ObjectInspector(object): class ObjectInspector(object):
"""Inspects objects in a running Python program""" """Inspects objects in a running Python program"""
......
...@@ -27,6 +27,7 @@ import pyrasite ...@@ -27,6 +27,7 @@ import pyrasite
from os.path import dirname, abspath, join from os.path import dirname, abspath, join
class PyrasiteIPC(object): class PyrasiteIPC(object):
"""Pyrasite Inter-Python Communication. """Pyrasite Inter-Python Communication.
...@@ -130,7 +131,9 @@ class PyrasiteIPC(object): ...@@ -130,7 +131,9 @@ class PyrasiteIPC(object):
self.address = address self.address = address
def cmd(self, cmd): def cmd(self, cmd):
"""Send a python command to exec in the process and return the output""" """
Send a python command to exec in the process and return the output
"""
self.send(cmd + '\n') self.send(cmd + '\n')
return self.recv() return self.recv()
......
...@@ -15,18 +15,21 @@ ...@@ -15,18 +15,21 @@
# #
# Copyright (C) 2011 Red Hat, Inc. # Copyright (C) 2011 Red Hat, Inc.
import os, sys import os
import sys
import argparse import argparse
from inject import CodeInjector from inject import CodeInjector
from utils import setup_logger from utils import setup_logger
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='pyrasite - inject code into a running python process', description='pyrasite - inject code into a running python process',
epilog="For updates, visit https://github.com/lmacken/pyrasite" epilog="For updates, visit https://github.com/lmacken/pyrasite"
) )
parser.add_argument('pid', help="The ID of the process to inject code into") parser.add_argument('pid',
help="The ID of the process to inject code into")
parser.add_argument('filename', parser.add_argument('filename',
help="The second argument must be a filename") help="The second argument must be a filename")
parser.add_argument('--gdb-prefix', dest='gdb_prefix', parser.add_argument('--gdb-prefix', dest='gdb_prefix',
...@@ -58,7 +61,8 @@ def main(): ...@@ -58,7 +61,8 @@ def main():
log.error("Error: The second argument must be a filename") log.error("Error: The second argument must be a filename")
sys.exit(4) sys.exit(4)
injector = CodeInjector(pid, verbose=args.verbose, gdb_prefix=args.gdb_prefix) injector = CodeInjector(pid, verbose=args.verbose,
gdb_prefix=args.gdb_prefix)
injector.inject(filename) injector.inject(filename)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -26,6 +26,7 @@ import threading ...@@ -26,6 +26,7 @@ import threading
from StringIO import StringIO from StringIO import StringIO
from pyrasite.ipc import PyrasiteIPC from pyrasite.ipc import PyrasiteIPC
class ReverseConnection(threading.Thread, PyrasiteIPC): class ReverseConnection(threading.Thread, PyrasiteIPC):
"""A payload that connects to a given host:port and receives commands""" """A payload that connects to a given host:port and receives commands"""
......
This diff is collapsed.
...@@ -33,6 +33,7 @@ from meliae import loader ...@@ -33,6 +33,7 @@ from meliae import loader
from pyrasite.inspect import ObjectInspector from pyrasite.inspect import ObjectInspector
class PyrasiteMemoryViewer(object): class PyrasiteMemoryViewer(object):
palette = [ palette = [
('body', 'black', 'light gray', 'standout'), ('body', 'black', 'light gray', 'standout'),
...@@ -75,8 +76,9 @@ class PyrasiteMemoryViewer(object): ...@@ -75,8 +76,9 @@ class PyrasiteMemoryViewer(object):
if i in (0, 1): if i in (0, 1):
rb = self.create_disabled_radio_button(line) rb = self.create_disabled_radio_button(line)
else: else:
obj = self.summary.summaries[i-2] obj = self.summary.summaries[i - 2]
rb = self.create_radio_button(group, line, obj, self.display_object) rb = self.create_radio_button(group, line, obj,
self.display_object)
buttons.append(rb) buttons.append(rb)
return buttons return buttons
...@@ -107,7 +109,7 @@ class PyrasiteMemoryViewer(object): ...@@ -107,7 +109,7 @@ class PyrasiteMemoryViewer(object):
w = urwid.Frame(header=bt, body=w) w = urwid.Frame(header=bt, body=w)
# Exit message # Exit message
exit = urwid.BigText(('exit'," Quit? "), urwid.Thin6x6Font()) exit = urwid.BigText(('exit', " Quit? "), urwid.Thin6x6Font())
exit = urwid.Overlay(exit, w, 'center', None, 'middle', None) exit = urwid.Overlay(exit, w, 'center', None, 'middle', None)
return w, exit return w, exit
......
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
from __future__ import division from __future__ import division
def humanize_bytes(bytes, precision=1): def humanize_bytes(bytes, precision=1):
"""Return a humanized string representation of a number of bytes.""" """Return a humanized string representation of a number of bytes."""
abbrevs = ( abbrevs = (
(1<<50L, 'PB'), (1 << 50L, 'PB'),
(1<<40L, 'TB'), (1 << 40L, 'TB'),
(1<<30L, 'GB'), (1 << 30L, 'GB'),
(1<<20L, 'MB'), (1 << 20L, 'MB'),
(1<<10L, 'kB'), (1 << 10L, 'kB'),
(1, 'bytes') (1, 'bytes')
) )
if bytes == 1: if bytes == 1:
...@@ -40,6 +41,7 @@ def humanize_bytes(bytes, precision=1): ...@@ -40,6 +41,7 @@ def humanize_bytes(bytes, precision=1):
import logging import logging
import subprocess import subprocess
def run(*args, **kwargs): def run(*args, **kwargs):
"""Run a subprocess. """Run a subprocess.
...@@ -54,8 +56,10 @@ def run(*args, **kwargs): ...@@ -54,8 +56,10 @@ def run(*args, **kwargs):
:param args: arguments to be passed to :class:`subprocess.Popen`. :param args: arguments to be passed to :class:`subprocess.Popen`.
:param kwargs: keyword arguments to be passed to :class:`subprocess.Popen`. :param kwargs: keyword arguments to be passed to :class:`subprocess.Popen`.
:param communicate: if True, call :meth:`subprocess.Popen.communicate` after creating the subprocess. :param communicate: if True, call :meth:`subprocess.Popen.communicate`
:param executable: if present, the path to a program to execute instead of this script. after creating the subprocess.
:param executable: if present, the path to a program to execute instead of
this script.
""" """
_kwargs = { _kwargs = {
"stdin": subprocess.PIPE, "stdin": subprocess.PIPE,
...@@ -82,7 +86,8 @@ def setup_logger(verbose=False): ...@@ -82,7 +86,8 @@ def setup_logger(verbose=False):
NullHandler = logging.NullHandler NullHandler = logging.NullHandler
except AttributeError: except AttributeError:
class NullHandler(logging.Handler): class NullHandler(logging.Handler):
def emit(self, record): pass def emit(self, record):
pass
# Add a do-nothing NullHandler to the module logger to prevent "No handlers # Add a do-nothing NullHandler to the module logger to prevent "No handlers
# could be found" errors. The calling code can still add other, more useful # could be found" errors. The calling code can still add other, more useful
......
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