old_contents: # -*- coding: utf-8 -*-
  from flask.ext import script
  from alchemist import db
  import sys
  
  
  def _make_context():
      """Create the namespace of items already pre-imported when using shell-plus
      """
  
      namespace = {'db': db, 'session': db.session}
  
      for component, registry in db.registry.items():
          namespace.update(registry)
  
      return namespace
  
  
  class Shell(script.Shell):
      """
      Runs a Python shell inside an application context with all
      models pre-loaded.
      """
  
      name = 'shell'
  
      def __init__(self, *args, **kwargs):
          # # Default the context maker.
          kwargs.setdefault('make_context', _make_context)
  
          # Continue initialization.
          super(Shell, self).__init__(*args, **kwargs)
  
      def get_options(self):
          options = super(Shell, self).get_options()
  
          # Add an additional option that allows for piping of input
          # to the shell.
          options += script.Option('--pipe', action="store_true"),
  
          return options
  
      def run(self, pipe, *args, **kwargs):
          if pipe:
              # User is attempting to pipe in script through stdin.
              text = sys.stdin.read()
              exec(text, None, None) # _make_context(quiet=True))
              return
  
          # Fallback to normal cycle.
          super(Shell, self).run(*args, **kwargs)
  
new_contents: # -*- coding: utf-8 -*-
  from flask.ext import script
  from alchemist import db
  from termcolor import colored
  from collections import defaultdict
  import sys
  
  
  
  def _make_context():
      """Create the namespace of items already pre-imported when using shell-plus
      """
  
      namespace = {'db': db, 'session': db.session}
  
      for component, registry in db.registry.items():
          namespace.update(registry)
  
      return namespace
  
  
  class Shell(script.Shell):
      """
      Runs a Python shell inside an application context with all
      models pre-loaded.
      """
  
      name = 'shell'
  
      @property
      def banner(self):
          text = colored('from alchemist import db\n', 'green')
          text += colored('session = db.session\n', 'green')
  
          modules = defaultdict(set)
          for component, registry in db.registry.items():
              for name, model in registry.items():
                  modules[model.__module__].add(name)
  
          for module, name in modules.items():
              text += colored('from %s import %s\n' % (module, ', '.join(name)), 'green')
  
          return text
  
      @banner.setter
      def banner(self, value):
          pass
  
      def __init__(self, *args, **kwargs):
          # # Default the context maker.
          kwargs.setdefault('make_context', _make_context)
          kwargs.setdefault('banner')
  
          # Continue initialization.
          super(Shell, self).__init__(*args, **kwargs)
  
      def get_options(self):
          options = super(Shell, self).get_options()
  
          # Add an additional option that allows for piping of input
          # to the shell.
          options += script.Option('--pipe', action="store_true"),
  
          return options
  
      def run(self, pipe, *args, **kwargs):
          if pipe:
              # User is attempting to pipe in script through stdin.
              text = sys.stdin.read()
              exec(text, None, None) # _make_context(quiet=True))
              return
  
          # Fallback to normal cycle.
          super(Shell, self).run(*args, **kwargs)
  
subject: Add a fancy banner.