Commit d9c6da75 authored by Luke Macken's avatar Luke Macken

pep8 all the things

parent 2f5c59ac
......@@ -33,6 +33,7 @@ import warnings
from utils import run
class CodeInjector(object):
"""Injects code into a running Python process"""
......
......@@ -17,6 +17,7 @@
from utils import run
class ObjectInspector(object):
"""Inspects objects in a running Python program"""
......
......@@ -27,6 +27,7 @@ import pyrasite
from os.path import dirname, abspath, join
class PyrasiteIPC(object):
"""Pyrasite Inter-Python Communication.
......@@ -130,7 +131,9 @@ class PyrasiteIPC(object):
self.address = address
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')
return self.recv()
......
......@@ -15,18 +15,21 @@
#
# Copyright (C) 2011 Red Hat, Inc.
import os, sys
import os
import sys
import argparse
from inject import CodeInjector
from utils import setup_logger
def main():
parser = argparse.ArgumentParser(
description='pyrasite - inject code into a running python process',
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',
help="The second argument must be a filename")
parser.add_argument('--gdb-prefix', dest='gdb_prefix',
......@@ -58,7 +61,8 @@ def main():
log.error("Error: The second argument must be a filename")
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)
if __name__ == '__main__':
......
......@@ -26,6 +26,7 @@ import threading
from StringIO import StringIO
from pyrasite.ipc import PyrasiteIPC
class ReverseConnection(threading.Thread, PyrasiteIPC):
"""A payload that connects to a given host:port and receives commands"""
......
This diff is collapsed.
......@@ -33,6 +33,7 @@ from meliae import loader
from pyrasite.inspect import ObjectInspector
class PyrasiteMemoryViewer(object):
palette = [
('body', 'black', 'light gray', 'standout'),
......@@ -75,8 +76,9 @@ class PyrasiteMemoryViewer(object):
if i in (0, 1):
rb = self.create_disabled_radio_button(line)
else:
obj = self.summary.summaries[i-2]
rb = self.create_radio_button(group, line, obj, self.display_object)
obj = self.summary.summaries[i - 2]
rb = self.create_radio_button(group, line, obj,
self.display_object)
buttons.append(rb)
return buttons
......@@ -107,7 +109,7 @@ class PyrasiteMemoryViewer(object):
w = urwid.Frame(header=bt, body=w)
# 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)
return w, exit
......
......@@ -2,14 +2,15 @@
from __future__ import division
def humanize_bytes(bytes, precision=1):
"""Return a humanized string representation of a number of bytes."""
abbrevs = (
(1<<50L, 'PB'),
(1<<40L, 'TB'),
(1<<30L, 'GB'),
(1<<20L, 'MB'),
(1<<10L, 'kB'),
(1 << 50L, 'PB'),
(1 << 40L, 'TB'),
(1 << 30L, 'GB'),
(1 << 20L, 'MB'),
(1 << 10L, 'kB'),
(1, 'bytes')
)
if bytes == 1:
......@@ -40,6 +41,7 @@ def humanize_bytes(bytes, precision=1):
import logging
import subprocess
def run(*args, **kwargs):
"""Run a subprocess.
......@@ -54,8 +56,10 @@ def run(*args, **kwargs):
:param args: 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 executable: if present, the path to a program to execute instead of this script.
:param communicate: if True, call :meth:`subprocess.Popen.communicate`
after creating the subprocess.
:param executable: if present, the path to a program to execute instead of
this script.
"""
_kwargs = {
"stdin": subprocess.PIPE,
......@@ -82,7 +86,8 @@ def setup_logger(verbose=False):
NullHandler = logging.NullHandler
except AttributeError:
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
# 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