pax_global_header00006660000000000000000000000064122466202610014513gustar00rootroot0000000000000052 comment=5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5 exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/000077500000000000000000000000001224662026100210265ustar00rootroot00000000000000exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/.gitignore000066400000000000000000000005461224662026100230230ustar00rootroot00000000000000*.py[cod] # C extensions *.so # Packages *.egg *.egg-info build eggs parts bin var sdist develop-eggs .installed.cfg lib lib64 *.tar.gz *.deb *.rpm debian/python* debian/files # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox nosetests.xml # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject *.sublime* exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/LICENSE000066400000000000000000000167201224662026100220410ustar00rootroot00000000000000GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/Makefile000066400000000000000000000030141224662026100224640ustar00rootroot00000000000000PYTHON=`which python` DESTDIR=/ BUILDIR=$(CURDIR)/debian/python-exconsole RPMTOPDIR=$(CURDIR)/build PROJECT=python-exconsole DEBPROJECT=python-exconsole VERSION=`python -c "from exconsole import __version__; print __version__"` PREFIX=/usr all: install: $(PYTHON) setup.py install --root $(DESTDIR) $(COMPILE) --prefix $(PREFIX) rpm: tgz rm -rf dist/*.rpm cat dist/$(PROJECT).spec.in | sed s/__VERSION__/$(VERSION)/g > $(PROJECT).spec mkdir -p build/SOURCES || true cp dist/$(PROJECT)*.tar.gz build/SOURCES rpmbuild --define '_topdir $(RPMTOPDIR)' -bb $(PROJECT).spec mv build/RPMS/noarch/$(PROJECT)*.rpm dist rm $(PROJECT).spec deb: tgz rm -rf dist/*.deb cat debian/changelog.in | sed s/__VERSION__/$(VERSION)/g | sed "s/__DATE__/$(DATE)/g" > debian/changelog cp dist/$(PROJECT)*.tar.gz .. rename -f 's/$(PROJECT)-(.*)\.tar\.gz/$(DEBPROJECT)_$$1\.orig\.tar\.gz/' ../* dpkg-buildpackage -b -rfakeroot -us -uc mv ../$(DEBPROJECT)*.deb dist/ rm ../$(DEBPROJECT)*.orig.tar.gz rm ../$(DEBPROJECT)*.changes rm debian/changelog upload-deb: deb scp dist/*.deb root@ajenti.org:/srv/repo/ng/debian ssh root@ajenti.org /srv/repo/rebuild-debian.sh upload-rpm: rpm scp dist/*.rpm root@ajenti.org:/srv/repo/ng/centos/6 ssh root@ajenti.org /srv/repo/rebuild-centos.sh upload-tgz: tgz $(PYTHON) setup.py sdist upload tgz: rm dist/*.tar.gz || true $(PYTHON) setup.py sdist clean: $(PYTHON) setup.py clean rm -rf build/ debian/$(PROJECT)* debian/*stamp* debian/files MANIFEST *.egg-info find . -name '*.pyc' -delete exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/README.rst000066400000000000000000000023241224662026100225160ustar00rootroot00000000000000exconsole ========= Emergency/postmortem Python console Installation from PyPI:: pip install python-exconsole DEB and RPM packages are available in Ajenti repositories: http://docs.ajenti.org/man/install/general.html Quick start:: import exconsole exconsole.register() do_dangerous_stuff() Console can be invoked by sending **SIGQUIT** or just pressing ``Ctrl-\`` Example of work:: Activating emergency console ---------------------------- Caused by: ZeroDivisionError integer division or modulo by zero Stack frames: [ 0] example.py:17 [ 1] example.py:15 Tester().test() [ 2] example.py:9 self.inner() [ 3] example.py:6 self.divide(2, 0) > [ 4] example.py:3 return a / b On frame 4 Source: def divide(self, a, b): >> return a / b Press Ctrl-D to leave console Type "_help()"" for built-in commands >>> print a,b 2 0 >>> _f(3) On frame 3 Source: def inner(self): >> self.divide(2, 0) >>> print self <__main__.Tester instance at 0x7f67c9a0e440> exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/000077500000000000000000000000001224662026100222505ustar00rootroot00000000000000exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/changelog.in000066400000000000000000000002171224662026100245270ustar00rootroot00000000000000python-exconsole (__VERSION__) UNRELEASED; urgency=low * Initial release. -- Eugeny Pankov Thu, 7 Feb 2013 00:12:00 +0300 exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/compat000066400000000000000000000000021224662026100234460ustar00rootroot000000000000008 exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/control000066400000000000000000000007021224662026100236520ustar00rootroot00000000000000Source: python-exconsole Section: python Priority: optional Maintainer: Eugene Pankov Build-Depends: debhelper (>=8.0.0), python-support (>= 0.6), cdbs (>= 0.4.49) XS-Python-Version: >=2.6 Standards-Version: 3.9.1 Package: python-exconsole Architecture: all Homepage: http://github.com/Eugeny/exconsole XB-Python-Version: ${python:Versions} Depends: ${misc:Depends}, ${python:Depends} Description: Emergency/postmortem Python console exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/copyright000066400000000000000000000002031224662026100241760ustar00rootroot00000000000000Copyright (c) 2012-2013 The Ajenti Team * Eugeny Pankov & contributors LICENSED UNDER LGPLv3 See LICENSE. exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/postinst000066400000000000000000000000261224662026100240540ustar00rootroot00000000000000#!/bin/sh #DEBHELPER# exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/prerm000066400000000000000000000000271224662026100233170ustar00rootroot00000000000000#!/bin/sh #DEBHELPER# exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/pyversions000066400000000000000000000000051224662026100244070ustar00rootroot000000000000002.6- exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/rules000077500000000000000000000003651224662026100233340ustar00rootroot00000000000000#!/usr/bin/make -f # -*- makefile -*- DEB_PYTHON_SYSTEM := pysupport include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/python-distutils.mk clean:: rm -rf build build-stamp configure-stamp build/ MANIFEST dh_clean exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/debian/watch000066400000000000000000000000121224662026100232720ustar00rootroot00000000000000version=3 exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/dist/000077500000000000000000000000001224662026100217715ustar00rootroot00000000000000exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/dist/python-exconsole.spec.in000066400000000000000000000014761224662026100266000ustar00rootroot00000000000000%define name python-exconsole %define version __VERSION__ %define unmangled_version __VERSION__ %define release 1 Summary: Emergency/postmortem Python console Name: %{name} Version: %{version} Release: %{release} Source0: %{name}-%{version}.tar.gz License: LGPLv3 Group: Development/Libraries BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot Prefix: %{_prefix} BuildArch: noarch Vendor: Eugene Pankov Url: http://ajenti.org/ %description Emergency/postmortem Python console %prep %setup -n %{name}-%{unmangled_version} -n %{name}-%{unmangled_version} %build python setup.py build %install python setup.py install --single-version-externally-managed -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES --prefix=/usr %clean rm -rf $RPM_BUILD_ROOT %files -f INSTALLED_FILES %defattr(-,root,root) exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/example.py000066400000000000000000000004731224662026100230370ustar00rootroot00000000000000class Tester: def divide(self, a, b): return a / b def inner(self): self.divide(2, 0) def test(self): self.inner() import exconsole def testcmd(*args, **kwargs): print 'Test!' exconsole.register(commands=[('_t', 'Test', testcmd)]) def fun(): Tester().test() fun() exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/exconsole/000077500000000000000000000000001224662026100230255ustar00rootroot00000000000000exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/exconsole/__init__.py000066400000000000000000000001051224662026100251320ustar00rootroot00000000000000from exconsole.console import register, launch __version__ = '0.1.5'exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/exconsole/console.py000066400000000000000000000102171224662026100250420ustar00rootroot00000000000000from __future__ import print_function import inspect import pdb import sys import signal def register(reg_signal=signal.SIGQUIT, reg_unhandled=True, commands=[]): """ Registers exconsole hooks :param reg_signal: if not None, register signal handler (default: ``signal.SIGQUIT``) :param reg_unhandled: if ``True``, register unhandled exception hook (``sys.excepthook``) :param commands: list of custom commands/objects: (, , ) """ if reg_signal: signal.signal(reg_signal, handle_quit) if reg_unhandled: sys.excepthook = handle_exception launch.commands = commands def handle_exception(type, value, tb): launch(exception=value, extraceback=tb) def handle_quit(signal, frame): launch(signalnum=signal, frame=frame) def launch(exception=None, extraceback=None, signalnum=None, frame=None): """ Launches an emergency console :param exception: unhandled exception value :param extraceback: unhandled exception traceback :param signalnum: interrupting signal number :param frame: interrupting signal frame """ print('\n') print('Activating emergency console') print('----------------------------') print('Caused by:') if signalnum: signals = dict((k, v) for v, k in signal.__dict__.iteritems() if v.startswith('SIG')) print('Signal', signals.get(signalnum, 'unknown')) elif exception: print(exception.__class__.__name__) print(exception) else: print('manual invocation') stack = [] locals = {} active_frame = 0 if frame: current_frame = frame while current_frame: stack.insert(0, current_frame) current_frame = current_frame.f_back if extraceback: current_tb = extraceback while current_tb: stack.append(current_tb.tb_frame) current_tb = current_tb.tb_next import readline import code def _cmd_stack(): index = 0 print('\nStack frames:') for frame in stack: s = '> ' if (active_frame == index) else ' ' s += '[%s] ' % str(index).rjust(3) lines, current_line = inspect.getsourcelines(frame) s += '%s:%i' % (inspect.getfile(frame), frame.f_lineno) s += '\n' + ' ' * 10 if frame.f_lineno - current_line < len(lines): s += lines[frame.f_lineno - current_line].strip('\n') print(s) index += 1 def _cmd_help(): print(( "Exconsole interactive emergency console\n" "Builtin commands:\n" " - _help() this help\n" " - _s() display stack\n" " - _f(index) change current stack frame\n" " - _pdb() launch PDB debugger\n" " - _exc exception object\n" " - Ctrl-D leave console\n" )) print('\n'.join(' - %s\t%s' % x[:2] for x in launch.commands)) def _cmd_pdb(): pdb.pm() def _cmd_frame(index): if not isinstance(index, int): print('index must be int') return if index < 0 or index >= len(stack): print('index out of bounds') return frame = stack[index] locals.clear() locals.update(frame.f_locals) locals.update({ '_help': _cmd_help, '_s': _cmd_stack, '_f': _cmd_frame, '_pdb': _cmd_pdb, '_exc': exception, }) for command in launch.commands: locals[command[0]] = command[2] print('On frame %i' % index) print('Source:') lines, current_line = inspect.getsourcelines(frame) print(''.join( ' ' + ('>>' if lines.index(line) == frame.f_lineno - current_line else ' ') + ' ' + line for line in lines )) active_frame = len(stack) - 1 _cmd_stack() _cmd_frame(len(stack) - 1) shell = code.InteractiveConsole(locals) print('Press Ctrl-D to leave console') print('Type "_help()" for built-in commands') shell.interact(banner='') exconsole-5ffd4c79aa098d155f1dd83bcaa634ffa9591bc5/setup.py000066400000000000000000000006521224662026100225430ustar00rootroot00000000000000#!/usr/bin/env python from distutils.core import setup from setuptools import find_packages import exconsole setup( name='python-exconsole', version=exconsole.__version__, install_requires=[ ], description='Emergency/postmortem Python console', author='Eugene Pankov', author_email='e@ajenti.org', url='https://github.com/Eugeny/exconsole', packages=find_packages(exclude=['*test*']), )