Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge djmitche/build-relengapi:repl-subcommand (PR #217)
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Apr 8, 2015
2 parents 25cf8b9 + 573c12d commit d3e5981
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/development/@relengapi/databases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,27 @@ The list of database names is at ``current_app.db.database_names``.

The known metadata for each database is in ``current_app.db.metadata``, keyed by database name.

Interactive Use
---------------

It can sometimes be useful to "live" ORM operations at an interactive prompt.
The ``relengapi repl`` command will run a read-eval-print loop with an active RelengAPI app:

.. code-block:: none
$ relengapi repl
2015-04-08 15:20:16,642 registering blueprint badpenny
2015-04-08 15:20:16,644 registering blueprint base
2015-04-08 15:20:16,645 registering blueprint tokenauth
2015-04-08 15:20:16,646 registering blueprint auth
2015-04-08 15:20:16,647 registering blueprint docs
'app' is the current application.
Python 2.7.9 (default, Feb 22 2015, 12:26:28)
[GCC 4.8.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> s = app.db.session('relengapi')
Alternative Column types
------------------------

Expand Down
22 changes: 22 additions & 0 deletions relengapi/blueprints/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,25 @@ def make_parser(self, subparsers):

def run(self, parser, args):
current_app.aws._spawn_sqs_listeners()


class ReplSubcommand(subcommands.Subcommand):

def make_parser(self, subparsers):
parser = subparsers.add_parser(
'repl', help='Open a Python REPL in the RelengAPI application context; '
'`app` is the current app.')
return parser

def run(self, parser, args):
import code
# try to get readline for the interactive interpreter (it
# only uses it if it's already loaded)
try:
import readline
assert readline
except ImportError:
readline = None

print "'app' is the current application."
code.InteractiveConsole(locals={'app': current_app}).interact()

0 comments on commit d3e5981

Please sign in to comment.