Browse Source

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>
devuan-deployment
Niels Thykier 10 months ago
parent
commit
35aed10291
No known key found for this signature in database GPG Key ID: A65B78DBE67C7AAC
3 changed files with 48 additions and 1 deletions
  1. +15
    -0
      britney.py
  2. +1
    -1
      britney2/completer.py
  3. +32
    -0
      britney2/console.py

+ 15
- 0
britney.py View File

@@ -1306,6 +1306,13 @@ class Britney(object):

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:
# read the command from the command line
try:
@@ -1319,6 +1326,14 @@ class Britney(object):
# quit the hint tester
if user_input and user_input[0] in ('quit', 'exit'):
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
elif user_input and user_input[0] in ('easy', 'hint', 'force-hint'):
mi_factory = self._migration_item_factory


+ 1
- 1
britney2/completer.py View File

@@ -33,7 +33,7 @@ class Completer(object):
self.cmds = ['easy', 'hint', 'force-hint', 'force', 'remove',
'force', 'age-days', 'urgent', 'block-all',
'block', 'block-udeb', 'unblock', 'unblock-udeb',
'approve', 'exit', 'quit']
'approve', 'exit', 'quit', 'python-console']
self.britney = britney
suite_info = britney.suite_info
# generate a completion list from excuses.


+ 32
- 0
britney2/console.py View 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…
Cancel
Save