summaryrefslogtreecommitdiff
path: root/repoze/bfg/paster.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-10-19 18:43:01 +0000
committerChris McDonough <chrism@agendaless.com>2009-10-19 18:43:01 +0000
commitb3e9ee1f5863cbe0d092f29e25cb4363d7398b64 (patch)
treeb6798fb91ac73a366b6435ab0c8ca70e8a25772f /repoze/bfg/paster.py
parentd5b2f46f323571ec32fa7e9c77ccf83f62a03fea (diff)
downloadpyramid-b3e9ee1f5863cbe0d092f29e25cb4363d7398b64.tar.gz
pyramid-b3e9ee1f5863cbe0d092f29e25cb4363d7398b64.tar.bz2
pyramid-b3e9ee1f5863cbe0d092f29e25cb4363d7398b64.zip
- ``paster bfgshell`` now supports IPython if it's available for
import. Thanks to Daniel Holth for the initial patch.
Diffstat (limited to 'repoze/bfg/paster.py')
-rw-r--r--repoze/bfg/paster.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/repoze/bfg/paster.py b/repoze/bfg/paster.py
index c60d0b437..de5dc1f79 100644
--- a/repoze/bfg/paster.py
+++ b/repoze/bfg/paster.py
@@ -9,6 +9,12 @@ from paste.util.template import paste_script_template_renderer
from repoze.bfg.scripting import get_root
+try:
+ from IPython.Shell import IPShellEmbed
+except ImportError:
+ IPShellEmbed = None
+
+
class StarterProjectTemplate(Template):
_template_dir = 'paster_templates/starter'
summary = 'repoze.bfg starter project'
@@ -66,8 +72,14 @@ class BFGShellCommand(Command):
group_name = 'bfg'
parser = Command.standard_parser(simulate=True)
+ parser.add_option('-d', '--disable-ipython',
+ action='store_true',
+ dest='disable_ipython',
+ help="Don't use IPython even if it is available")
+
interact = (interact,) # for testing
loadapp = (loadapp,) # for testing
+ IPShellEmbed = IPShellEmbed # for testing
verbose = 3
def command(self):
@@ -77,8 +89,17 @@ class BFGShellCommand(Command):
config_file, section_name = self.args
app = get_app(config_file, section_name, loadapp=self.loadapp[0])
root, closer = get_root(app)
- try:
- self.interact[0](banner, local={'root':root})
- finally:
- closer()
-
+ if self.IPShellEmbed is not None and not self.options.disable_ipython:
+ shell = self.IPShellEmbed(argv=self.args)
+ shell.set_banner(shell.IP.BANNER + '\n\n' + banner)
+ try:
+ shell(local_ns={'root':root}, global_ns={})
+ finally:
+ closer()
+ else:
+ try:
+ self.interact[0](banner, local={'root':root})
+ finally:
+ closer()
+
+