Debug web2py Actions with iPython

My Notes re debugging web2py Actions with iPython

My system

  • Using web2py 2.9.5-stable+timestamp.2014.03.16.02.35.39 (Running on Rocket 1.2.6, Python 2.7.5)
  • On Windows XP in C:\web2py

iPython log

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.13.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: cd C:\web2py
C:\web2py

In [2]: from gluon import shell

In [3]: shell.run('fish/default/view_or_add_client_trips/?client_id=2', plain=True, import_models=True)
{'grid': <gluon.html.DIV object at 0x0289C930>}

In [4]:
Advertisements

Run Ipython magic functions from your profile startup python script

This is the  setup I did for a Music21 project named “chordMe”.

On WIN XP the .ipython configuration dir is in C:Documents and SettingsAdministrator.ipython

Create a profile for your project.

Open a command line shell and type the following to create a new profile

> ipython profile create chordMe
[ProfileCreate] Generating default config file: u'C:Documents and SettingsAdministrator.ipythonprofile_chordMeipython_config.py'

Now add the following python file to:
C:Documents and SettingsAdministrator.ipythonprofile_chordMestartup

000-start.py  file content:
# 000-start.py
# usage:
#     $ ipython --profile=chordMe

import os
from IPython.core.interactiveshell import InteractiveShell 
os.chdir(r"C:/1d/PythonPjs/music21Pjs/chordMePj/chordMe")

# from http://ipython.org/ipython-doc/rel-0.13/api/generated/IPython.core.interactiveshell.html
# run_line_magic(magic_name, line)
# magic_name : str  "Name of the desired magic function, without ‘%’ prefix."
# line : str "The rest of the input line as a single string."

get_ipython().run_line_magic(u"logstart", u"-o ipython_log.py append")
from music21 import *

Running Ipython with the startup commands. 
To the command line say:
> ipython --profile=chordMe