Add command line completion with argcomplete
issue11592 review419481003
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Add command line completion with argcomplete
|
||||
* Include record name and value in validation error message
|
||||
* Add header parameter on export data
|
||||
* Enforce certificate validation for SMTP connection (issue11564)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import glob
|
||||
@@ -7,6 +8,11 @@ import os
|
||||
import sys
|
||||
import threading
|
||||
|
||||
try:
|
||||
import argcomplete
|
||||
except ImportError:
|
||||
argcomplete = None
|
||||
|
||||
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
|
||||
'..', '..', 'trytond')))
|
||||
if os.path.isdir(DIR):
|
||||
@@ -16,6 +22,8 @@ import trytond.commandline as commandline
|
||||
from trytond.config import config, split_netloc
|
||||
|
||||
parser = commandline.get_parser_daemon()
|
||||
if argcomplete:
|
||||
argcomplete.autocomplete(parser)
|
||||
options = parser.parse_args()
|
||||
commandline.config_log(options)
|
||||
extra_files = config.update_etc(options.configfile)
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
import argcomplete
|
||||
except ImportError:
|
||||
argcomplete = None
|
||||
|
||||
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
|
||||
'..', '..', 'trytond')))
|
||||
if os.path.isdir(DIR):
|
||||
@@ -13,6 +19,8 @@ import trytond.commandline as commandline
|
||||
from trytond.config import config
|
||||
|
||||
parser = commandline.get_parser_admin()
|
||||
if argcomplete:
|
||||
argcomplete.autocomplete(parser)
|
||||
options = parser.parse_args()
|
||||
config.update_etc(options.configfile)
|
||||
commandline.config_log(options)
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
import argcomplete
|
||||
except ImportError:
|
||||
argcomplete = None
|
||||
|
||||
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
|
||||
'..', '..', 'trytond')))
|
||||
if os.path.isdir(DIR):
|
||||
@@ -13,6 +19,8 @@ import trytond.commandline as commandline
|
||||
from trytond.config import config
|
||||
|
||||
parser = commandline.get_parser_console()
|
||||
if argcomplete:
|
||||
argcomplete.autocomplete(parser)
|
||||
options = parser.parse_args()
|
||||
config.update_etc(options.configfile)
|
||||
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
import argcomplete
|
||||
except ImportError:
|
||||
argcomplete = None
|
||||
|
||||
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
|
||||
'..', '..', 'trytond')))
|
||||
if os.path.isdir(DIR):
|
||||
@@ -13,6 +19,8 @@ import trytond.commandline as commandline
|
||||
from trytond.config import config
|
||||
|
||||
parser = commandline.get_parser_cron()
|
||||
if argcomplete:
|
||||
argcomplete.autocomplete(parser)
|
||||
options = parser.parse_args()
|
||||
config.update_etc(options.configfile)
|
||||
commandline.config_log(options)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import curses
|
||||
@@ -8,6 +9,11 @@ import os
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
try:
|
||||
import argcomplete
|
||||
except ImportError:
|
||||
argcomplete = None
|
||||
|
||||
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
|
||||
'..', '..', 'trytond')))
|
||||
if os.path.isdir(DIR):
|
||||
@@ -17,6 +23,8 @@ import trytond.commandline as commandline
|
||||
from trytond.config import config
|
||||
|
||||
parser = commandline.get_parser_stat()
|
||||
if argcomplete:
|
||||
argcomplete.autocomplete(parser)
|
||||
options = parser.parse_args()
|
||||
config.update_etc(options.configfile)
|
||||
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
import argcomplete
|
||||
except ImportError:
|
||||
argcomplete = None
|
||||
|
||||
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
|
||||
'..', '..', 'trytond')))
|
||||
if os.path.isdir(DIR):
|
||||
@@ -13,6 +19,8 @@ import trytond.commandline as commandline
|
||||
from trytond.config import config
|
||||
|
||||
parser = commandline.get_parser_worker()
|
||||
if argcomplete:
|
||||
argcomplete.autocomplete(parser)
|
||||
options = parser.parse_args()
|
||||
config.update_etc(options.configfile)
|
||||
commandline.config_log(options)
|
||||
|
||||
@@ -173,6 +173,7 @@ setup(name=name,
|
||||
'weasyprint': ['weasyprint'],
|
||||
'coroutine': ['gevent>=1.1'],
|
||||
'image': ['pillow'],
|
||||
'completion': ['argcomplete'],
|
||||
},
|
||||
dependency_links=dependency_links,
|
||||
zip_safe=False,
|
||||
|
||||
+32
-6
@@ -6,6 +6,7 @@ import logging
|
||||
import logging.config
|
||||
import logging.handlers
|
||||
import os
|
||||
import os.path
|
||||
from contextlib import contextmanager
|
||||
from io import StringIO
|
||||
|
||||
@@ -14,6 +15,25 @@ from trytond import __version__
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def database_completer(parsed_args, **kwargs):
|
||||
from trytond.config import config
|
||||
from trytond.transaction import Transaction
|
||||
config.update_etc(parsed_args.configfile)
|
||||
with Transaction().start(
|
||||
None, 0, readonly=True, close=True) as transaction:
|
||||
return transaction.database.list()
|
||||
|
||||
|
||||
def module_completer(**kwargs):
|
||||
from trytond.modules import get_module_list
|
||||
return get_module_list()
|
||||
|
||||
|
||||
def language_completer(**kwargs):
|
||||
files = os.listdir(os.path.join(os.path.dirname(__file__), 'ir', 'locale'))
|
||||
return [os.path.splitext(f)[0] for f in files]
|
||||
|
||||
|
||||
def get_base_parser():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--version', action='version',
|
||||
@@ -37,8 +57,10 @@ def get_parser():
|
||||
db_names = list(next(csv.reader(StringIO(db_names))))
|
||||
else:
|
||||
db_names = []
|
||||
parser.add_argument("-d", "--database", dest="database_names", nargs='+',
|
||||
default=db_names, metavar='DATABASE', help="specify the database name")
|
||||
parser.add_argument(
|
||||
"-d", "--database", dest="database_names", nargs='+',
|
||||
default=db_names, metavar='DATABASE',
|
||||
help="specify the database name").completer = database_completer
|
||||
parser.add_argument("--logconf", dest="logconf", metavar='FILE',
|
||||
help="logging configuration file (ConfigParser format)")
|
||||
|
||||
@@ -77,8 +99,10 @@ def get_parser_cron():
|
||||
def get_parser_admin():
|
||||
parser = get_parser()
|
||||
|
||||
parser.add_argument("-u", "--update", dest="update", nargs='+', default=[],
|
||||
metavar='MODULE', help="activate or update a module")
|
||||
parser.add_argument(
|
||||
"-u", "--update", dest="update", nargs='+', default=[],
|
||||
metavar='MODULE',
|
||||
help="activate or update a module").completer = module_completer
|
||||
parser.add_argument("--all", dest="update", action="append_const",
|
||||
const="ir", help="update all activated modules")
|
||||
parser.add_argument("--activate-dependencies", dest="activatedeps",
|
||||
@@ -93,8 +117,10 @@ def get_parser_admin():
|
||||
help="Send a test email to the specified address.")
|
||||
parser.add_argument("-m", "--update-modules-list", action="store_true",
|
||||
dest="update_modules_list", help="Update list of tryton modules")
|
||||
parser.add_argument("-l", "--language", dest="languages", nargs='+',
|
||||
default=[], metavar='CODE', help="Load language translations")
|
||||
parser.add_argument(
|
||||
"-l", "--language", dest="languages", nargs='+',
|
||||
default=[], metavar='CODE',
|
||||
help="Load language translations").completer = language_completer
|
||||
parser.add_argument("--hostname", dest="hostname", default=None,
|
||||
help="Limit database listing to the hostname")
|
||||
parser.add_argument("--validate", dest="validate", nargs='*',
|
||||
|
||||
Reference in New Issue
Block a user