Add an option to trytond-console to run a script file

This commit is contained in:
Cédric Krier
2025-10-21 16:05:39 +02:00
parent ac39a44d3b
commit 0d677b4f74
3 changed files with 10 additions and 1 deletions
+1
View File
@@ -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)
+3
View File
@@ -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',
+6 -1
View File
@@ -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)