mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-05-24 00:41:30 +00:00
Add python-console command to the hint-tester
This enables interactive state exploration of britney's internals for a given data set. Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
parent
8d5805b8de
commit
35aed10291
15
britney.py
15
britney.py
@ -1306,6 +1306,13 @@ class Britney(object):
|
|||||||
|
|
||||||
known_hints = self._hint_parser.registered_hints
|
known_hints = self._hint_parser.registered_hints
|
||||||
|
|
||||||
|
print("Britney hint tester")
|
||||||
|
print()
|
||||||
|
print("Besides inputting known britney hints, the follow commands are also available")
|
||||||
|
print(" * quit/exit - terminates the shell")
|
||||||
|
print(" * python-console - jump into an interactive python shell (with the current loaded dataset)")
|
||||||
|
print()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# read the command from the command line
|
# read the command from the command line
|
||||||
try:
|
try:
|
||||||
@ -1319,6 +1326,14 @@ class Britney(object):
|
|||||||
# quit the hint tester
|
# quit the hint tester
|
||||||
if user_input and user_input[0] in ('quit', 'exit'):
|
if user_input and user_input[0] in ('quit', 'exit'):
|
||||||
break
|
break
|
||||||
|
elif user_input and user_input[0] == 'python-console':
|
||||||
|
try:
|
||||||
|
import britney2.console
|
||||||
|
except ImportError as e:
|
||||||
|
print("Failed to import britney.console module: %s" % repr(e))
|
||||||
|
continue
|
||||||
|
britney2.console.run_python_console(self)
|
||||||
|
print("Returning to the britney hint-tester console")
|
||||||
# run a hint
|
# run a hint
|
||||||
elif user_input and user_input[0] in ('easy', 'hint', 'force-hint'):
|
elif user_input and user_input[0] in ('easy', 'hint', 'force-hint'):
|
||||||
mi_factory = self._migration_item_factory
|
mi_factory = self._migration_item_factory
|
||||||
|
@ -33,7 +33,7 @@ class Completer(object):
|
|||||||
self.cmds = ['easy', 'hint', 'force-hint', 'force', 'remove',
|
self.cmds = ['easy', 'hint', 'force-hint', 'force', 'remove',
|
||||||
'force', 'age-days', 'urgent', 'block-all',
|
'force', 'age-days', 'urgent', 'block-all',
|
||||||
'block', 'block-udeb', 'unblock', 'unblock-udeb',
|
'block', 'block-udeb', 'unblock', 'unblock-udeb',
|
||||||
'approve', 'exit', 'quit']
|
'approve', 'exit', 'quit', 'python-console']
|
||||||
self.britney = britney
|
self.britney = britney
|
||||||
suite_info = britney.suite_info
|
suite_info = britney.suite_info
|
||||||
# generate a completion list from excuses.
|
# generate a completion list from excuses.
|
||||||
|
32
britney2/console.py
Normal file
32
britney2/console.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import code
|
||||||
|
|
||||||
|
|
||||||
|
class SubInterpreterExit(SystemExit):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def console_quit():
|
||||||
|
raise SubInterpreterExit()
|
||||||
|
|
||||||
|
|
||||||
|
def run_python_console(britney_obj):
|
||||||
|
console_locals = {
|
||||||
|
'britney': britney_obj,
|
||||||
|
'__name__': '__console__',
|
||||||
|
'__doc__': None,
|
||||||
|
'quit': console_quit,
|
||||||
|
'exit': console_quit,
|
||||||
|
}
|
||||||
|
console = code.InteractiveConsole(locals=console_locals)
|
||||||
|
banner = """\
|
||||||
|
Interactive python (REPL) shell in britney.
|
||||||
|
|
||||||
|
Locals available
|
||||||
|
* britney: Instance of the Britney object.
|
||||||
|
* quit()/exit(): leave this REPL console.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
console.interact(banner=banner, exitmsg='')
|
||||||
|
except SubInterpreterExit:
|
||||||
|
pass
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user