diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 890bf31924..5971ac6c7b 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Add an option to trytond-console to run a script file * Store only immutable structure in MemoryCache * Replace ``clean_days`` with ``log_size`` in the cron configuration * Enforce access check in export_data (issue14366) diff --git a/trytond/trytond/commandline.py b/trytond/trytond/commandline.py index 17e9630b6f..9a15232dee 100644 --- a/trytond/trytond/commandline.py +++ b/trytond/trytond/commandline.py @@ -172,6 +172,9 @@ def get_parser_console(): "-d", "--database", dest="database_name", required=True, metavar='DATABASE', help="specify the database name").completer = database_completer + parser.add_argument( + "-f", "--file", dest="file", + help="the Python script file to execute") parser.add_argument("--histsize", dest="histsize", type=int, default=500, help="set the number of commands to remember in the command history") parser.add_argument("--readonly", dest="readonly", action='store_true', diff --git a/trytond/trytond/console.py b/trytond/trytond/console.py index 1966d82359..4a2af3b301 100644 --- a/trytond/trytond/console.py +++ b/trytond/trytond/console.py @@ -53,7 +53,12 @@ def run(options): 'pool': pool, 'transaction': transaction, } - if sys.stdin.isatty(): + if options.file: + console = InteractiveConsole(local) + with open(options.file, 'r') as f: + console.runsource( + f.read(), filename=options.file, symbol='exec') + elif sys.stdin.isatty(): console = Console(local, histsize=options.histsize) banner = "Tryton %s, Python %s on %s" % ( __version__, sys.version, sys.platform)