Skip to content

Instantly share code, notes, and snippets.

@llazzaro
Forked from samv/shell.py
Last active August 29, 2015 14:03
Show Gist options
  • Save llazzaro/313a4800d17bee31d3e3 to your computer and use it in GitHub Desktop.
Save llazzaro/313a4800d17bee31d3e3 to your computer and use it in GitHub Desktop.
"""
The SQLAlchemy Shell.
This is just a wrapper for code.InteractiveConsole with some useful
defaults for using SQLAlchemy
"""
import sys
from IPython import embed
def _banner(symbols):
"""Shows the currently defined symbols for use by the interactive shell.
must be passed in the currently active symbol table, as a dictionary."""
import os
(_height, _width) = os.popen('stty size', 'r').read().split()
_width = int(_width)
print "Welcome to the SQLAlchemy shell. This is a python shell, with "
print "these globals defined:"
count = 0
for (_x, _v) in symbols.items():
if not _x.startswith("_"):
count += 1
r = repr(_v)
if (len(_x) + len(r) + len(" = ") + 1) > _width:
r = r[0:(_width - len(_x) - 4 - 4)] + "..."
print " \033[1m{x}\033[0m = {v}".format(x=_x, v=r)
def main(argv=sys.argv):
ic = embed()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment