User:Mstone/Tricks: Difference between revisions

From OLPC
Jump to navigation Jump to search
mNo edit summary
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
This page contains pointers to a collection of idioms which I rely on to accomplish tasks quickly and with predictable results.
== Verbose Python Tracebacks ==


; verbose python tracebacks
[http://teach.laptop.org/~mstone/nice_traces.py nice_traces.py]
: <tt>import [http://docs.python.org/library/cgitb.html cgitb]; cgitb.enable(format="plain")</tt>
from nice_traces import trace
# sys.excepthook now is set to trace by the import
# also, trace(sys.exc_info()) can be used for more controlled handling


; verbosity controls on logging
== Handy report() function ==
: See [http://dev.laptop.org/git?p=projects/mocktools;a=blob;f=trac_helper.py;hb=HEAD trac_helper.py]


; pythonic relations
See [http://dev.laptop.org/git?p=projects/mocktools;a=blob;f=trac_helper.py;hb=HEAD trac_helper.py]
: See my [http://dev.laptop.org/git/users/mstone/relation relation] module and [http://alloy.mit.edu Alloy] (which was my inspiration, though I've made nothing more than a poor knockoff).


== Relational error logging ==
; relational error logging
: See [http://dev.laptop.org/git?p=projects/mocktools;a=blob;f=trac_helper.py;hb=HEAD trac_helper.py] and [http://dev.laptop.org/git?p=projects/buildtools;a=blob;f=collect-pkgs.py;hb=HEAD collect-pkgs.py].


; email-based error reporting
See [http://dev.laptop.org/git?p=projects/mocktools;a=blob;f=trac_helper.py;hb=HEAD trac_helper.py] and [http://dev.laptop.org/git?p=projects/buildtools;a=blob;f=collect-pkgs.py;hb=HEAD collect-pkgs.py].
: See [http://dev.laptop.org/git?p=projects/buildtools;a=blob;f=email_warnings.py;hb=HEAD email_warnings.py].


; pdb
== Email-based error reporting ==
: <tt>from pdb import set_trace as debug ... debug()</tt>


; rpm makefiles
See [http://dev.laptop.org/git?p=projects/buildtools;a=blob;f=email_warnings.py;hb=HEAD email_warnings.py].
: See [http://dev.laptop.org/git?p=users/mstone/rpm-packaging;a=tree rpm-packaging] as well as individual projects like [http://dev.laptop.org/git/projects/olpc-netutils olpc-netutils] along with my [[Developer/Fedora#Outside Reading|Fedora packaging bibliography]].


; pymeta parser-based controllers
== RPM Makefiles ==
: [http://dev.laptop.org/git?p=users/mstone/triagebot;a=blob;f=grammar.py;hb=grammar triagebot] is based on a model-view-controller architecture where the controller object is assembled at runtime based on data collected with a metaclass.
: [https://launchpad.net/pymeta pymeta] makes it easy to pick the right response to complicated input.


; python gdb macros
See [http://dev.laptop.org/git?p=users/mstone/rpm-packaging;a=tree rpm-packaging] as well as individual projects like [http://dev.laptop.org/git/projects/olpc-netutils] along with my [[Developer/Fedora#Outside Reading|Fedora packaging bibliography]].
: http://wiki.python.org/moin/DebuggingWithGdb


; python memory profiling
== [https://launchpad.net/pymeta pymeta] parser-based controllers ==
: [http://dev.laptop.org/git/users/mstone/guppy guppy] + Tomeu's [[memory leak testing]] writeup.


; tree-based python context management
See [http://dev.laptop.org/git?p=users/mstone/triagebot;a=blob;f=grammar.py;hb=grammar triagebot] for cute tricks.
: [http://dev.laptop.org/git?p=users/mstone/puritan;a=blob;f=main.py;hb=f9#l16 puritan's main.py] and [http://dev.laptop.org/git?p=users/mstone/puritan;a=blob;f=contexts.py;hb=f9 contexts.py]


; custom dbus decorators
== Python GDB Macros ==
: [http://dev.laptop.org/git?p=users/mstone/sds;a=blob;f=sds/service.py;hb=HEAD sds stub]


; ipython for exploring interprocess communication
http://wiki.python.org/moin/DebuggingWithGdb
: [http://ipython.scipy.org IPython] is wonderfully helpful for exploring xml-rpc and dbus interfaces.

; code to make pylint happy
: rainbow's [http://dev.laptop.org/git?p=users/mstone/security;a=blob;f=rainbow/rainbow/inject.py;hb=cli inject.py] can be automatically checked for many errors by [http://www.logilab.org/project/pylint pylint] because it passes all data explicitly through function calls.

; C error handling
: [http://dev.laptop.org/git?p=users/mstone/nss-rainbow;a=tree nss-rainbow] uses a dash of code-generation and a lot of convention to be very consistent about error detection and handling.

; C warning flags & Makefile tips
: nss-rainbow's [http://dev.laptop.org/git?p=users/mstone/nss-rainbow;a=blob;f=Makefile;hb=HEAD#l2 Makefile] gets a number of things right, though it can still be improved in several ways.

; scripts for user creation
: [http://dev.laptop.org/git?p=users/mstone/provisioning;a=tree provision] users on new machines in a scripted fashion.

; program with git
: [[Puritan]] and other parts of our [[build system]] show some silly things you can do with [http://git.or.cz git] if you are so inclined.

; localize shell code
: [http://dev.laptop.org/git?p=users/cjb/xs-rsync;f=xs-upserv;a=blob xs-upserv] - just for kicks: a localized Makefile

Latest revision as of 22:54, 6 March 2011

This page contains pointers to a collection of idioms which I rely on to accomplish tasks quickly and with predictable results.

verbose python tracebacks
import cgitb; cgitb.enable(format="plain")
verbosity controls on logging
See trac_helper.py
pythonic relations
See my relation module and Alloy (which was my inspiration, though I've made nothing more than a poor knockoff).
relational error logging
See trac_helper.py and collect-pkgs.py.
email-based error reporting
See email_warnings.py.
pdb
from pdb import set_trace as debug ... debug()
rpm makefiles
See rpm-packaging as well as individual projects like olpc-netutils along with my Fedora packaging bibliography.
pymeta parser-based controllers
triagebot is based on a model-view-controller architecture where the controller object is assembled at runtime based on data collected with a metaclass.
pymeta makes it easy to pick the right response to complicated input.
python gdb macros
http://wiki.python.org/moin/DebuggingWithGdb
python memory profiling
guppy + Tomeu's memory leak testing writeup.
tree-based python context management
puritan's main.py and contexts.py
custom dbus decorators
sds stub
ipython for exploring interprocess communication
IPython is wonderfully helpful for exploring xml-rpc and dbus interfaces.
code to make pylint happy
rainbow's inject.py can be automatically checked for many errors by pylint because it passes all data explicitly through function calls.
C error handling
nss-rainbow uses a dash of code-generation and a lot of convention to be very consistent about error detection and handling.
C warning flags & Makefile tips
nss-rainbow's Makefile gets a number of things right, though it can still be improved in several ways.
scripts for user creation
provision users on new machines in a scripted fashion.
program with git
Puritan and other parts of our build system show some silly things you can do with git if you are so inclined.
localize shell code
xs-upserv - just for kicks: a localized Makefile