annotate kallithea/bin/kallithea_cli_config.py @ 8997:66fcd3993563 draft i18n

i18n: updated translation for Chinese (Simplified) Currently translated at 45.0% (487 of 1082 strings)
author Poesty Li <poesty7450@gmail.com>
date Tue, 05 Mar 2024 11:40:54 +0100
parents 1f8eaa4c1dff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
1 # -*- coding: utf-8 -*-
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
2 # This program is free software: you can redistribute it and/or modify
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
3 # it under the terms of the GNU General Public License as published by
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
5 # (at your option) any later version.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
6 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
7 # This program is distributed in the hope that it will be useful,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
10 # GNU General Public License for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
11 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
12 # You should have received a copy of the GNU General Public License
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4011
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4011
4959e22af6ca Added ini config maker with dynamic variable replacements.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14
4959e22af6ca Added ini config maker with dynamic variable replacements.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 import os
7634
6df08d78f8e7 cli: fill in git_hook_interpreter at 'config-create' time to really fix potentially invalid interpreter in git hooks (Issue #333)
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7449
diff changeset
16 import sys
4011
4959e22af6ca Added ini config maker with dynamic variable replacements.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 import uuid
6898
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
18 from collections import defaultdict
6896
e338b3468987 make-config: drop support for comma separated custom values - just specify multiple values
Mads Kiilerich <mads@kiilerich.com>
parents: 6864
diff changeset
19
7811
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7786
diff changeset
20 import click
6896
e338b3468987 make-config: drop support for comma separated custom values - just specify multiple values
Mads Kiilerich <mads@kiilerich.com>
parents: 6864
diff changeset
21 import mako.exceptions
e338b3468987 make-config: drop support for comma separated custom values - just specify multiple values
Mads Kiilerich <mads@kiilerich.com>
parents: 6864
diff changeset
22
7811
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7786
diff changeset
23 import kallithea.bin.kallithea_cli_base as cli_base
8712
1f8eaa4c1dff lib: move locale.py to locales.py to avoid shadowing of standard module
Mads Kiilerich <mads@kiilerich.com>
parents: 8429
diff changeset
24 import kallithea.lib.locales
6897
bed1d9158eb4 make-config: use shared inifile library
Mads Kiilerich <mads@kiilerich.com>
parents: 6896
diff changeset
25 from kallithea.lib import inifile
6555
213085032127 gearbox: make a make-config sub-command available again
Mads Kiilerich <madski@unity3d.com>
parents: 5826
diff changeset
26
7811
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7786
diff changeset
27
7406
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
28 def show_defaults(ctx, param, value):
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
29 # Following construct is taken from the Click documentation:
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
30 # https://click.palletsprojects.com/en/7.x/options/#callbacks-and-eager-options
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
31 # "The resilient_parsing flag is applied to the context if Click wants to
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
32 # parse the command line without any destructive behavior that would change
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
33 # the execution flow. In this case, because we would exit the program, we
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
34 # instead do nothing."
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
35 if not value or ctx.resilient_parsing:
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
36 return
6555
213085032127 gearbox: make a make-config sub-command available again
Mads Kiilerich <madski@unity3d.com>
parents: 5826
diff changeset
37
7406
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
38 for key, value in inifile.default_variables.items():
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
39 click.echo('%s=%s' % (key, value))
4011
4959e22af6ca Added ini config maker with dynamic variable replacements.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40
7406
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
41 ctx.exit()
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
42
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
43 @cli_base.register_command()
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
44 @click.option('--show-defaults', callback=show_defaults,
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
45 is_flag=True, expose_value=False, is_eager=True,
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
46 help='Show the default values that can be overridden')
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
47 @click.argument('config_file', type=click.Path(dir_okay=False, writable=True), required=True)
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
48 @click.argument('key_value_pairs', nargs=-1)
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
49 def config_create(config_file, key_value_pairs):
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
50 """Create a new configuration file.
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
51
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
52 This command creates a default configuration file, possibly adding/updating
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
53 settings you specify.
6898
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
54
7387
c677d5839bcc make-config: tweak description - don't call it "bare" and don't reference setup-app
Mads Kiilerich <mads@kiilerich.com>
parents: 7380
diff changeset
55 The primary high level configuration keys and their default values are
7406
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
56 shown with --show-defaults . Custom values for these keys can be specified
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
57 on the command line as key=value arguments.
7387
c677d5839bcc make-config: tweak description - don't call it "bare" and don't reference setup-app
Mads Kiilerich <mads@kiilerich.com>
parents: 7380
diff changeset
58
c677d5839bcc make-config: tweak description - don't call it "bare" and don't reference setup-app
Mads Kiilerich <mads@kiilerich.com>
parents: 7380
diff changeset
59 Additional key=value arguments will be patched/inserted in the [app:main]
c677d5839bcc make-config: tweak description - don't call it "bare" and don't reference setup-app
Mads Kiilerich <mads@kiilerich.com>
parents: 7380
diff changeset
60 section ... until another section name specifies where any following values
c677d5839bcc make-config: tweak description - don't call it "bare" and don't reference setup-app
Mads Kiilerich <mads@kiilerich.com>
parents: 7380
diff changeset
61 should go.
6555
213085032127 gearbox: make a make-config sub-command available again
Mads Kiilerich <madski@unity3d.com>
parents: 5826
diff changeset
62 """
213085032127 gearbox: make a make-config sub-command available again
Mads Kiilerich <madski@unity3d.com>
parents: 5826
diff changeset
63
7634
6df08d78f8e7 cli: fill in git_hook_interpreter at 'config-create' time to really fix potentially invalid interpreter in git hooks (Issue #333)
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7449
diff changeset
64 mako_variable_values = {
8429
04908b44005c ini: put kallithea-config version in the ini file it creates (Issue #373)
Mads Kiilerich <mads@kiilerich.com>
parents: 8261
diff changeset
65 'version': kallithea.__version__,
7634
6df08d78f8e7 cli: fill in git_hook_interpreter at 'config-create' time to really fix potentially invalid interpreter in git hooks (Issue #333)
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7449
diff changeset
66 'git_hook_interpreter': sys.executable,
7778
267c0dbcddd3 kallithea-cli: set ssh_authorized_keys when creating .ini file so it doesn't have to be set manually before using ssh
Mads Kiilerich <mads@kiilerich.com>
parents: 7634
diff changeset
67 'user_home_path': os.path.expanduser('~'),
7779
a185042de98a kallithea-cli: set kallithea_cli_path when creating .ini file so it doesn't have to be set manually before using ssh
Mads Kiilerich <mads@kiilerich.com>
parents: 7778
diff changeset
68 'kallithea_cli_path': cli_base.kallithea_cli_path,
8712
1f8eaa4c1dff lib: move locale.py to locales.py to avoid shadowing of standard module
Mads Kiilerich <mads@kiilerich.com>
parents: 8429
diff changeset
69 'ssh_locale': kallithea.lib.locales.get_current_locale(),
7634
6df08d78f8e7 cli: fill in git_hook_interpreter at 'config-create' time to really fix potentially invalid interpreter in git hooks (Issue #333)
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7449
diff changeset
70 }
6898
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
71 ini_settings = defaultdict(dict)
6897
bed1d9158eb4 make-config: use shared inifile library
Mads Kiilerich <mads@kiilerich.com>
parents: 6896
diff changeset
72
6898
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
73 section_name = None
7406
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
74 for parameter in key_value_pairs:
6897
bed1d9158eb4 make-config: use shared inifile library
Mads Kiilerich <mads@kiilerich.com>
parents: 6896
diff changeset
75 parts = parameter.split('=', 1)
6898
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
76 if len(parts) == 1 and parameter.startswith('[') and parameter.endswith(']'):
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
77 section_name = parameter
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
78 elif len(parts) == 2:
6897
bed1d9158eb4 make-config: use shared inifile library
Mads Kiilerich <mads@kiilerich.com>
parents: 6896
diff changeset
79 key, value = parts
6898
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
80 if section_name is None and key in inifile.default_variables:
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
81 mako_variable_values[key] = value
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
82 else:
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
83 if section_name is None:
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
84 section_name = '[app:main]'
a8b9f2d68e7d make-config: allow configuration of any ini value
Mads Kiilerich <mads@kiilerich.com>
parents: 6897
diff changeset
85 ini_settings[section_name][key] = value
6896
e338b3468987 make-config: drop support for comma separated custom values - just specify multiple values
Mads Kiilerich <mads@kiilerich.com>
parents: 6864
diff changeset
86 else:
e338b3468987 make-config: drop support for comma separated custom values - just specify multiple values
Mads Kiilerich <mads@kiilerich.com>
parents: 6864
diff changeset
87 raise ValueError("Invalid name=value parameter %r" % parameter)
4011
4959e22af6ca Added ini config maker with dynamic variable replacements.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88
6555
213085032127 gearbox: make a make-config sub-command available again
Mads Kiilerich <madski@unity3d.com>
parents: 5826
diff changeset
89 # use default that cannot be replaced
6897
bed1d9158eb4 make-config: use shared inifile library
Mads Kiilerich <mads@kiilerich.com>
parents: 6896
diff changeset
90 mako_variable_values.update({
6555
213085032127 gearbox: make a make-config sub-command available again
Mads Kiilerich <madski@unity3d.com>
parents: 5826
diff changeset
91 'uuid': lambda: uuid.uuid4().hex,
213085032127 gearbox: make a make-config sub-command available again
Mads Kiilerich <madski@unity3d.com>
parents: 5826
diff changeset
92 })
8261
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
93
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
94 click.echo('Creating config file using:')
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
95 for key, value in inifile.default_variables.items():
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
96 if isinstance(value, str):
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
97 options = inifile.variable_options.get(key)
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
98 if options:
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
99 click.echo(' %s=%s (options: %s)' % (key, mako_variable_values.get(key, value), ', '.join(options)))
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
100 else:
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
101 click.echo(' %s=%s' % (key, mako_variable_values.get(key, value)))
b1eee5119416 config-create: show options used for generating .ini, and list what alternative values are supported
Mads Kiilerich <mads@kiilerich.com>
parents: 7811
diff changeset
102
4011
4959e22af6ca Added ini config maker with dynamic variable replacements.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 try:
7406
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
104 config_file_abs = os.path.abspath(config_file)
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
105 inifile.create(config_file_abs, mako_variable_values, ini_settings)
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
106 click.echo('Wrote new config file in %s' % config_file_abs)
7449
7651f0cbca82 kallithea-cli: remind users to generate the front-end
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7406
diff changeset
107 click.echo("Don't forget to build the front-end using 'kallithea-cli front-end-build'.")
4011
4959e22af6ca Added ini config maker with dynamic variable replacements.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108
4959e22af6ca Added ini config maker with dynamic variable replacements.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 except Exception:
7406
7784a1212471 cli: convert 'gearbox make-config' into 'kallithea-cli config-create'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 7387
diff changeset
110 click.echo(mako.exceptions.text_error_template().render())