annotate roundup/configuration.py @ 8446:14c7c07b32d8

feature: add thread local trace_id and trace_reason to logging. Added trace_id to default logging so that all logs for a given request share the same trace_id. This allows correlation of logs across a request. admin_guide.txt, upgrading.txt: add docs update sample configs to include trace_id. rewrite logging docs in admin_guide. Hopefully they are clearer now. clean up some stuff in the logging config file docs. admin.py: add decorators to run_command to enable trace_id. change calls to db.commit() to use run_command to get trace_id. configuration.py: clean up imports. update docstrings, comments and inline docs. add trace_id to default log format. add function for testing decorated with trace_id. add support for dumping stack trace in logging. add check for pytest in sys.modules to enable log propagation when pytest is running. Otherwise tests fail as the caplog logger doesn't see the roundup logs. logcontext.py: new file to handle thread local contextvar mangement. mailgw.py: add decorators for trace_id etc. scripts/roundup_xlmrpc_server.py: add decorators for trace_id etc. fix encoding bug turning bytes into a string. fix command line issue where we can't set encoding. (not sure if changing encoding via command line even works) cgi/client.py decorate two entry points for trace_id etc. cgi/wsgi_handler.py: decorate entry point for trace_id etc. test/test_config.py: add test for trace_id in new log format. test various cases for sinfo and errors in formating msg.
author John Rouillard <rouilj@ieee.org>
date Tue, 16 Sep 2025 22:53:00 -0400
parents 39a6825d10ca
children d06be9346c68
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1 # Roundup Issue Tracker configuration support
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2 #
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
3 __docformat__ = "restructuredtext"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
4
5517
0cdf19b82354 Fix issue2550994: breakage caused by configparser backports.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5494
diff changeset
5 # Some systems have a backport of the Python 3 configparser module to
0cdf19b82354 Fix issue2550994: breakage caused by configparser backports.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5494
diff changeset
6 # Python 2: <https://pypi.org/project/configparser/>. That breaks
0cdf19b82354 Fix issue2550994: breakage caused by configparser backports.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5494
diff changeset
7 # Roundup if used with Python 2 because it generates unicode objects
0cdf19b82354 Fix issue2550994: breakage caused by configparser backports.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5494
diff changeset
8 # where not expected by the Python code. Thus, a version check is
0cdf19b82354 Fix issue2550994: breakage caused by configparser backports.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5494
diff changeset
9 # used here instead of try/except.
7810
890097bc4cd0 chore(ruff): sort imports
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
10 import binascii
890097bc4cd0 chore(ruff): sort imports
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
11 import errno
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
12 import getopt
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
13 import logging
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
14 import os
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
15 import re
7810
890097bc4cd0 chore(ruff): sort imports
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
16 import smtplib
890097bc4cd0 chore(ruff): sort imports
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
17 import sys
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
18 import time
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
19 import traceback
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
20
3620
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
21 import roundup.date
7810
890097bc4cd0 chore(ruff): sort imports
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
22 from roundup.anypy import random_
5726
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
23 from roundup.anypy.strings import b2s
7810
890097bc4cd0 chore(ruff): sort imports
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
24 from roundup.backends import list_backends
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
25 from roundup.i18n import _
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
26 from roundup.logcontext import gen_trace_id, get_context_info
5726
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
27
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
28 if sys.version_info[0] > 2:
7810
890097bc4cd0 chore(ruff): sort imports
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
29 import configparser # Python 3
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
30 else:
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
31 import ConfigParser as configparser # Python 2
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
32
6126
15c68580578f fix broken import
John Rouillard <rouilj@ieee.org>
parents: 6123
diff changeset
33 from roundup.exceptions import RoundupException
6123
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6053
diff changeset
34
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
35 # Exceptions
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
36
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
37
6123
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6053
diff changeset
38 class ConfigurationError(RoundupException):
3777
74aebbbea305 Sorry for the mega-patch - was all done on the train:
Richard Jones <richard@users.sourceforge.net>
parents: 3725
diff changeset
39 pass
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
40
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
41
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6514
diff changeset
42 class ParsingOptionError(ConfigurationError):
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6514
diff changeset
43 def __str__(self):
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6514
diff changeset
44 return self.args[0]
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6514
diff changeset
45
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
46
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
47 class LoggingConfigError(ConfigurationError):
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
48 def __init__(self, message, **attrs):
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
49 super().__init__(message)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
50 for key, value in attrs.items():
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
51 self.__setattr__(key, value)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
52
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
53 def __str__(self):
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
54 return self.args[0]
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
55
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
56
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
57 class NoConfigError(ConfigurationError):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
58
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
59 """Raised when configuration loading fails
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
60
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
61 Constructor parameters: path to the directory that was used as HOME
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
62
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
63 """
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
64
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
65 def __str__(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
66 return "No valid configuration files found in directory %s" \
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
67 % self.args[0]
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
68
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
69
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
70 class InvalidOptionError(ConfigurationError, KeyError, AttributeError):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
71
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
72 """Attempted access to non-existing configuration option
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
73
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
74 Configuration options may be accessed as configuration object
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
75 attributes or items. So this exception instances also are
3820
771248aa8302 typos in docstrings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3788
diff changeset
76 instances of KeyError (invalid item access) and AttributeError
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
77 (invalid attribute access).
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
78
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
79 Constructor parameter: option name
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
80
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
81 """
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
82
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
83 def __str__(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
84 return "Unsupported configuration option: %s" % self.args[0]
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
85
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
86
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
87 class OptionValueError(ConfigurationError, ValueError):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
88
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
89 """Raised upon attempt to assign an invalid value to config option
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
90
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
91 Constructor parameters: Option instance, offending value
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
92 and optional info string.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
93
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
94 """
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
95
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
96 def __str__(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
97 _args = self.args
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
98 _rv = "Invalid value for %(option)s: %(value)r" % {
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
99 "option": _args[0].name, "value": _args[1]}
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
100 if len(_args) > 2:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
101 _rv += "\n".join(("",) + _args[2:])
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
102 return _rv
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
103
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
104
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
105 class OptionUnsetError(ConfigurationError):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
106
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
107 """Raised when no Option value is available - neither set, nor default
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
108
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
109 Constructor parameters: Option instance.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
110
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
111 """
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
112
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
113 def __str__(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
114 return "%s is not set and has no default" % self.args[0].name
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
115
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
116
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
117 class UnsetDefaultValue:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
118
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
119 """Special object meaning that default value for Option is not specified"""
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
120
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
121 def __str__(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
122 return "NO DEFAULT"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
123
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
124
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
125 NODEFAULT = UnsetDefaultValue()
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
126
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
127
5878
1b57d8f3eb97 Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents: 5809
diff changeset
128 def create_token(size=32):
1b57d8f3eb97 Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents: 5809
diff changeset
129 return b2s(binascii.b2a_base64(random_.token_bytes(size)).strip())
5726
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
130
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
131 # Option classes
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
132
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
133
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
134 class Option:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
135
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
136 """Single configuration option.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
137
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
138 Options have following attributes:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
139
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
140 config
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
141 reference to the containing Config object
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
142 section
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
143 name of the section in the tracker .ini file
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
144 setting
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
145 option name in the tracker .ini file
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
146 default
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
147 default option value
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
148 description
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
149 option description. Makes a comment in the tracker .ini file
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
150 name
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
151 "canonical name" of the configuration option.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
152 For items in the 'main' section this is uppercased
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
153 'setting' name. For other sections, the name is
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
154 composed of the section name and the setting name,
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
155 joined with underscore.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
156 aliases
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
157 list of "also known as" names. Used to access the settings
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
158 by old names used in previous Roundup versions.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
159 "Canonical name" is also included.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
160
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
161 The name and aliases are forced to be uppercase.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
162 The setting name is forced to lowercase.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
163
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
164 """
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
165
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
166 class_description = None
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
167
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
168 def __init__(self, config, section, setting,
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
169 default=NODEFAULT, description=None, aliases=None):
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
170 self.config = config
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
171 self.section = section
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
172 self.setting = setting.lower()
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
173 self.default = default
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
174 self.description = description
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
175 self.name = setting.upper()
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
176 if section != "main":
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
177 self.name = "_".join((section.upper(), self.name))
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
178 if aliases:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
179 self.aliases = [alias.upper() for alias in list(aliases)]
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
180 else:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
181 self.aliases = []
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
182 self.aliases.insert(0, self.name)
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
183 # convert default to internal representation
7811
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
184 _value = default if default is NODEFAULT else self.str2value(default)
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
185
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
186 # value is private. use get() and set() to access
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
187 self._value = self._default_value = _value
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
188
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
189 def str2value(self, value):
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
190 """Return 'value' argument converted to internal representation"""
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
191 return value
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
192
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
193 def _value2str(self, value):
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
194 """Return 'value' argument converted to external representation
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
195
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
196 This is actual conversion method called only when value
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
197 is not NODEFAULT. Heirs with different conversion rules
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
198 override this method, not the public .value2str().
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
199
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
200 """
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
201 return str(value)
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
202
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
203 def value2str(self, value=NODEFAULT, current=0):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
204 """Return 'value' argument converted to external representation
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
205
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
206 If 'current' is True, use current option value.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
207
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
208 """
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
209 if current:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
210 value = self._value
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
211 if value is NODEFAULT:
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
212 return str(value)
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
213 else:
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
214 return self._value2str(value)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
215
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
216 def get(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
217 """Return current option value"""
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
218 if self._value is NODEFAULT:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
219 raise OptionUnsetError(self)
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
220 return self._value
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
221
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
222 def set(self, value):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
223 """Update the value"""
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
224 self._value = self.str2value(value)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
225
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
226 def reset(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
227 """Reset the value to default"""
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
228 self._value = self._default_value
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
229
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
230 def isdefault(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
231 """Return True if current value is the default one"""
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
232 return self._value == self._default_value
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
233
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
234 def isset(self):
3820
771248aa8302 typos in docstrings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3788
diff changeset
235 """Return True if the value is available (either set or default)"""
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
236 return self._value != NODEFAULT
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
237
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
238 def __str__(self):
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
239 return self.value2str(self._value)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
240
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
241 def __repr__(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
242 if self.isdefault():
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
243 _format = "<%(class)s %(name)s (default): %(value)s>"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
244 else:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
245 _format = "<%(class)s %(name)s (default: %(default)s): %(value)s>"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
246 return _format % {
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
247 "class": self.__class__.__name__,
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
248 "name": self.name,
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
249 "default": self.value2str(self._default_value),
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
250 "value": self.value2str(self._value),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
251 }
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
252
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
253 def format(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
254 """Return .ini file fragment for this option"""
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
255 _desc_lines = []
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
256 for _description in (self.description, self.class_description):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
257 if _description:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
258 _desc_lines.extend(_description.split("\n"))
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
259 # comment out the setting line if there is no value
7811
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
260 _is_set = "" if self.isset() else "#"
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
261
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
262 _rv = "# %(description)s\n# Default: %(default)s\n" \
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
263 "%(is_set)s%(name)s = %(value)s\n" % {
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
264 "description": "\n# ".join(_desc_lines),
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
265 "default": self.value2str(self._default_value),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
266 "name": self.setting,
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
267 "value": self.value2str(self._value),
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
268 "is_set": _is_set,
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
269 }
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
270 return _rv
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
271
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
272 def load_ini(self, config):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
273 """Load value from ConfigParser object"""
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6514
diff changeset
274 try:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6514
diff changeset
275 if config.has_option(self.section, self.setting):
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6514
diff changeset
276 self.set(config.get(self.section, self.setting))
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
277 except (configparser.InterpolationSyntaxError,
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
278 configparser.InterpolationMissingOptionError) as e:
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6514
diff changeset
279 raise ParsingOptionError(
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
280 _("Error in %(filepath)s with section [%(section)s] at "
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
281 "option %(option)s: %(message)s") % {
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
282 "filepath": self.config.filepath,
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
283 "section": e.section,
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
284 "option": e.option,
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
285 "message": str(e)})
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
286
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
287
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
288 class BooleanOption(Option):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
289
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
290 """Boolean option: yes or no"""
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
291
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
292 class_description = "Allowed values: yes, no"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
293
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
294 def _value2str(self, value):
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
295 if value:
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
296 return "yes"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
297 else:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
298 return "no"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
299
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
300 def str2value(self, value):
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
301 if isinstance(value, type("")):
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
302 _val = value.lower()
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
303 if _val in ("yes", "true", "on", "1"):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
304 _val = 1
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
305 elif _val in ("no", "false", "off", "0"):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
306 _val = 0
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
307 else:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
308 raise OptionValueError(self, value, self.class_description)
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
309 else:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
310 _val = value and 1 or 0
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
311 return _val
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
312
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
313
3544
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
314 class WordListOption(Option):
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
315
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
316 """List of strings"""
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
317
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
318 class_description = "Allowed values: comma-separated list of words"
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
319
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
320 def _value2str(self, value):
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
321 return ','.join(value)
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
322
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
323 def str2value(self, value):
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
324 return value.split(',')
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
325
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
326
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
327 class RunDetectorOption(Option):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
328
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
329 """When a detector is run: always, never or for new items only"""
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
330
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
331 class_description = "Allowed values: yes, no, new"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
332
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
333 def str2value(self, value):
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
334 _val = value.lower()
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
335 if _val in ("yes", "no", "new"):
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
336 return _val
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
337 else:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
338 raise OptionValueError(self, value, self.class_description)
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
339
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
340
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
341 class CsrfSettingOption(Option):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
342
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
343 """How should a csrf measure be enforced: required, yes, logfailure, no"""
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
344
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
345 class_description = "Allowed values: required, yes, logfailure, no"
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
346
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
347 def str2value(self, value):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
348 _val = value.lower()
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
349 if _val in ("required", "yes", "logfailure", "no"):
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
350 return _val
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
351 else:
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
352 raise OptionValueError(self, value, self.class_description)
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
353
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
354
5212
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
355 class SameSiteSettingOption(Option):
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
356
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
357 """How should the SameSite cookie setting be set: strict, lax
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
358 or should it not be added (none)"""
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
359
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
360 class_description = "Allowed values: Strict, Lax, None"
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
361
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
362 def str2value(self, value):
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
363 _val = value.lower()
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
364 if _val in ("strict", "lax", "none"):
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
365 return _val.capitalize()
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
366 else:
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
367 raise OptionValueError(self, value, self.class_description)
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
368
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
369
5748
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
370 class DatabaseBackend(Option):
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
371 """handle exact text of backend and make sure it's available"""
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
372 class_description = "Available backends: %s" % ", ".join(list_backends())
5748
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
373
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
374 def str2value(self, value):
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
375 _val = value.lower()
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
376 if _val in list_backends():
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
377 return _val
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
378 else:
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
379 raise OptionValueError(self, value, self.class_description)
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
380
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
381
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
382 class HtmlToTextOption(Option):
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
383
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
384 """What module should be used to convert emails with only text/html
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
385 parts into text for display in roundup. Choose from beautifulsoup
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
386 4, dehtml - the internal code or none to disable html to text
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
387 conversion. If beautifulsoup chosen but not available, dehtml will
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
388 be used.
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
389
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
390 """
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
391
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
392 class_description = "Allowed values: beautifulsoup, dehtml, none"
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
393
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
394 def str2value(self, value):
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
395 _val = value.lower()
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
396 if _val in ("beautifulsoup", "dehtml", "none"):
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
397 return _val
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
398 else:
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
399 raise OptionValueError(self, value, self.class_description)
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
400
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
401
7964
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
402 class HtmlVersionOption(Option):
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
403 """Accept html4 only for now. Raise error for xhtml which is not
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
404 supported in roundup 2.4 and newer."""
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
405
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
406 class_description = "Allowed values: html4"
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
407
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
408 def str2value(self, value):
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
409 _val = value.lower()
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
410 if _val in ("html4"):
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
411 return _val
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
412 else:
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
413 raise OptionValueError(self, value, self.class_description)
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
414
5117
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
415 class EmailBodyOption(Option):
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
416
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
417 """When to replace message body or strip quoting: always, never
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
418 or for new items only"""
5117
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
419
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
420 class_description = "Allowed values: yes, no, new"
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
421
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
422 def str2value(self, value):
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
423 _val = value.lower()
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
424 if _val in ("yes", "no", "new"):
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
425 return _val
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
426 else:
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
427 raise OptionValueError(self, value, self.class_description)
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
428
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
429
4887
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
430 class IsolationOption(Option):
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
431 """Database isolation levels"""
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
432
7845
0c71ac9cdcd0 chore(lint): change class props from mutable lists to tuples
John Rouillard <rouilj@ieee.org>
parents: 7844
diff changeset
433 allowed = ('read uncommitted', 'read committed', 'repeatable read',
0c71ac9cdcd0 chore(lint): change class props from mutable lists to tuples
John Rouillard <rouilj@ieee.org>
parents: 7844
diff changeset
434 'serializable')
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
435 class_description = "Allowed values: %s" % ', '.join("'%s'" % a
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
436 for a in allowed)
4887
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
437
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
438 def str2value(self, value):
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
439 _val = value.lower()
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
440 if _val in self.allowed:
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
441 return _val
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
442 raise OptionValueError(self, value, self.class_description)
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
443
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
444
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
445 class IndexerOption(Option):
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
446 """Valid options for indexer"""
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
447
7845
0c71ac9cdcd0 chore(lint): change class props from mutable lists to tuples
John Rouillard <rouilj@ieee.org>
parents: 7844
diff changeset
448 allowed = ('', 'xapian', 'whoosh', 'native', 'native-fts')
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
449 class_description = "Allowed values: %s" % ', '.join("'%s'" % a
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
450 for a in allowed)
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
451
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
452 # FIXME this is the result of running:
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
453 # SELECT cfgname FROM pg_ts_config;
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
454 # on a postgresql 14.1 server.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
455 # So the best we can do is hardcode this.
7845
0c71ac9cdcd0 chore(lint): change class props from mutable lists to tuples
John Rouillard <rouilj@ieee.org>
parents: 7844
diff changeset
456 valid_langs = ("simple",
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
457 "custom1",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
458 "custom2",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
459 "custom3",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
460 "custom4",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
461 "custom5",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
462 "arabic",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
463 "armenian",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
464 "basque",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
465 "catalan",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
466 "danish",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
467 "dutch",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
468 "english",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
469 "finnish",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
470 "french",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
471 "german",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
472 "greek",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
473 "hindi",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
474 "hungarian",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
475 "indonesian",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
476 "irish",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
477 "italian",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
478 "lithuanian",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
479 "nepali",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
480 "norwegian",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
481 "portuguese",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
482 "romanian",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
483 "russian",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
484 "serbian",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
485 "spanish",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
486 "swedish",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
487 "tamil",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
488 "turkish",
7845
0c71ac9cdcd0 chore(lint): change class props from mutable lists to tuples
John Rouillard <rouilj@ieee.org>
parents: 7844
diff changeset
489 "yiddish")
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
490
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
491 def str2value(self, value):
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
492 _val = value.lower()
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
493 if _val in self.allowed:
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
494 return _val
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
495 raise OptionValueError(self, value, self.class_description)
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
496
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
497 def validate(self, options):
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
498
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
499 if self._value in ("", "xapian"):
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
500 try:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
501 import xapian
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
502 except ImportError:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
503 # indexer is probably '' and xapian isn't present
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
504 # so just return at end of method
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
505 pass
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
506 else:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
507 try:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
508 lang = options["INDEXER_LANGUAGE"]._value
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
509 xapian.Stem(lang)
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
510 except xapian.InvalidArgumentError:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
511 import textwrap
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
512 lang_avail = b2s(xapian.Stem.get_available_languages())
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
513 languages = textwrap.fill(_("Valid languages: ") +
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
514 lang_avail, 75,
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
515 subsequent_indent=" ")
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
516 raise OptionValueError(options["INDEXER_LANGUAGE"],
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
517 lang, languages)
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
518
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
519 if self._value == "native-fts":
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
520 lang = options["INDEXER_LANGUAGE"]._value
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
521 if lang not in self.valid_langs:
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
522 import textwrap
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
523 languages = textwrap.fill(_("Expected languages: ") +
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
524 " ".join(self.valid_langs), 75,
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
525 subsequent_indent=" ")
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
526 raise OptionValueError(options["INDEXER_LANGUAGE"],
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
527 lang, languages)
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
528
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
529
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
530 class MailAddressOption(Option):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
531
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
532 """Email address
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
533
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
534 Email addresses may be either fully qualified or local.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
535 In the latter case MAIL_DOMAIN is automatically added.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
536
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
537 """
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
538
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
539 def get(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
540 _val = Option.get(self)
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
541 if "@" not in _val:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
542 _val = "@".join((_val, self.config["MAIL_DOMAIN"]))
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
543 return _val
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
544
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
545
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
546 class FilePathOption(Option):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
547
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
548 """File or directory path name
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
549
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
550 Paths may be either absolute or relative to the HOME.
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
551
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
552 """
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
553
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
554 class_description = "The path may be either absolute or relative\n" \
5102
96dc9f07340a issue2161722: oudated docs
John Rouillard <rouilj@ieee.org>
parents: 5098
diff changeset
555 "to the directory containing this config file."
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
556
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
557 def get(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
558 _val = Option.get(self)
2619
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
559 if _val and not os.path.isabs(_val):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
560 _val = os.path.join(self.config["HOME"], _val)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
561 return _val
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
562
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
563
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
564 class SpaceSeparatedListOption(Option):
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
565
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
566 """List of space seperated elements.
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
567 """
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
568
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
569 class_description = "A list of space separated elements."
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
570
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
571 def get(self):
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
572 _val = Option.get(self)
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
573 pathlist = list(_val.split())
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
574 if pathlist:
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
575 return pathlist
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
576 else:
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
577 return None
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
578
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
579
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
580 class LoggingFormatOption(Option):
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
581 """Escape/unescape logging format string '%(' <-> '%%('
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
582
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
583 Config file parsing allows variable interpolation using
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
584 %(keyname)s. However this is exactly the format that we need
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
585 for creating a logging format string. So we tell the user to
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
586 quote the string using %%(...). Then we turn %%( -> %( when
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
587 retrieved and turn %( into %%( when saving the file.
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
588 """
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
589
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
590 class_description = ("Allowed value: Python LogRecord attribute named "
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
591 "formats with % *sign doubled*.\n"
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
592 "Also you can include the following attributes:\n"
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
593 " %%(trace_id)s %%(trace_reason)s and %%(pct_char)s"
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
594 )
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
595
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
596 def str2value(self, value):
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
597 """Validate and convert value of logging format string.
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
598
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
599 This does a dirty check to see if a token is missing a
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
600 specifier. So "%%(ascdate)s %%(level) " would fail because of
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
601 the 's' missing after 'level)'. But "%%(ascdate)s %%(level)s"
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
602 would pass.
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
603
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
604 Note that '%(foo)s' (i.e. unescaped substitution) generates
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
605 a error from the ini parser with a less than wonderful message.
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
606 """
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
607 unquoted_val = value.replace("%%(", "%(")
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
608
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
609 # regexp matches all current logging record object attribute names.
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
610 scanned_result = re.sub(r'%\([A-Za-z_]+\)\S', '', unquoted_val)
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
611 if scanned_result.find('%(') != -1:
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
612 raise OptionValueError(
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
613 self, unquoted_val,
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
614 "Check that all substitution tokens have a format "
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
615 "specifier after the ). Unrecognized use of %%(...) in: "
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
616 "%s" % scanned_result)
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
617
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
618 return str(unquoted_val)
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
619
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
620 def _value2str(self, value):
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
621 """Replace %( with %%( to quote the format substitution param.
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
622 """
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
623 return value.replace("%(", "%%(")
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
624
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
625
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
626 class OriginHeadersListOption(Option):
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
627
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
628 """List of space seperated origin header values.
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
629 """
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
630
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
631 class_description = "A list of space separated case sensitive\norigin headers 'scheme://host'."
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
632
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
633 def set(self, _val):
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
634 pathlist = list(_val.split())
7155
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 7141
diff changeset
635 if '*' in pathlist and pathlist[0] != '*':
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 7141
diff changeset
636 raise OptionValueError(
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 7141
diff changeset
637 self, _val,
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 7141
diff changeset
638 "If using '*' it must be the first element.")
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
639 self._value = pathlist
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
640
6682
0b8d34b64930 issue2551205 bugfix missing _value2str
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
641 def _value2str(self, value):
0b8d34b64930 issue2551205 bugfix missing _value2str
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
642 return ','.join(value)
0b8d34b64930 issue2551205 bugfix missing _value2str
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
643
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
644
5231
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
645 class MultiFilePathOption(Option):
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
646
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
647 """List of space seperated File or directory path name
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
648
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
649 Paths may be either absolute or relative to the HOME. None
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
650 is returned if there are no elements.
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
651
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
652 """
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
653
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
654 class_description = "The space separated paths may be either absolute\n" \
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
655 "or relative to the directory containing this config file."
5231
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
656
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
657 def get(self):
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
658 pathlist = []
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
659 _val = Option.get(self)
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
660 for elem in _val.split():
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
661 if elem and not os.path.isabs(elem):
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
662 pathlist.append(os.path.join(self.config["HOME"], elem))
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
663 else:
7915
82093eb944d6 test - normalize path for MultiFilePathOptions
John Rouillard <rouilj@ieee.org>
parents: 7860
diff changeset
664 pathlist.append(os.path.normpath(elem))
5231
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
665 if pathlist:
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
666 return pathlist
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
667 else:
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
668 return None
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
669
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
670
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
671 class FloatNumberOption(Option):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
672
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
673 """Floating point numbers"""
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
674
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
675 def str2value(self, value):
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
676 try:
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
677 return float(value)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
678 except ValueError:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
679 raise OptionValueError(self, value,
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
680 "Floating point number required")
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
681
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
682 def _value2str(self, value):
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
683 _val = str(value)
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
684 # strip fraction part from integer numbers
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
685 if _val.endswith(".0"):
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
686 _val = _val[:-2]
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
687 return _val
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
688
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
689
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
690 class IntegerNumberOption(Option):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
691
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
692 """Integer numbers"""
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
693
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
694 def str2value(self, value):
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
695 try:
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
696 return int(value)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
697 except ValueError:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
698 raise OptionValueError(self, value, "Integer number required")
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
699
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
700
5772
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
701 class IntegerNumberGeqZeroOption(Option):
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
702
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
703 """Integer numbers greater than or equal to zero."""
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
704
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
705 def str2value(self, value):
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
706 try:
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
707 v = int(value)
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
708 if v < 0:
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
709 raise OptionValueError(self, value,
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
710 "Integer number greater than or equal to zero required")
5773
1151a2b31f1d Yeah, let's actually return the option value.....
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
711 return v
5772
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
712 except OptionValueError:
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
713 raise # pass through subclass
5772
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
714 except ValueError:
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
715 raise OptionValueError(self, value, "Integer number required")
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
716
7567
5e118944ef75 flake8: add extra blank lines
John Rouillard <rouilj@ieee.org>
parents: 7556
diff changeset
717
7556
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
718 class IntegerNumberGtZeroOption(Option):
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
719
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
720 """Integer numbers greater than zero."""
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
721
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
722 def str2value(self, value):
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
723 try:
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
724 v = int(value)
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
725 if v < 1:
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
726 raise OptionValueError(self, value,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
727 "Integer number greater than zero required")
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
728 return v
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
729 except OptionValueError:
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
730 raise # pass through subclass
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
731 except ValueError:
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
732 raise OptionValueError(self, value, "Integer number required")
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
733
7567
5e118944ef75 flake8: add extra blank lines
John Rouillard <rouilj@ieee.org>
parents: 7556
diff changeset
734
3609
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
735 class OctalNumberOption(Option):
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
736
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
737 """Octal Integer numbers"""
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
738
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
739 def str2value(self, value):
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
740 try:
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
741 return int(value, 8)
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
742 except ValueError:
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
743 raise OptionValueError(self, value,
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
744 "Octal Integer number required")
3609
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
745
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
746 def _value2str(self, value):
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
747 return oct(value)
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
748
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
749
5726
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
750 class MandatoryOption(Option):
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
751 """Option must not be empty"""
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
752 def str2value(self, value):
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
753 if not value:
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
754 raise OptionValueError(self, value, "Value must not be empty.")
5726
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
755 else:
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
756 return value
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
757
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
758
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
759 class SecretOption(Option):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
760 """A string not beginning with file:// or a file starting with file://
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
761
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
762 Paths may be either absolute or relative to the HOME.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
763 Value for option is the first line in the file.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
764 It is mean to store secret information in the config file but
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
765 allow the config file to be stored in version control without
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
766 storing the secret there.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
767
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
768 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
769
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
770 class_description = (
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
771 "A string that starts with 'file://' is interpreted\n"
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
772 "as a file path relative to the tracker home. Using\n"
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
773 "'file:///' defines an absolute path. The first\n"
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
774 "line of the file will be used as the value. Any\n"
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
775 "string that does not start with 'file://' is used\n"
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
776 "as is. It removes any whitespace at the end of the\n"
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
777 "line, so a newline can be put in the file.\n")
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
778
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
779 def get(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
780 _val = Option.get(self)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
781 if isinstance(_val, str) and _val.startswith('file://'):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
782 filepath = _val[7:]
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
783 if filepath and not os.path.isabs(filepath):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
784 filepath = os.path.join(self.config["HOME"], filepath.strip())
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
785 try:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
786 with open(filepath) as f:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
787 _val = f.readline().rstrip()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
788 # except FileNotFoundError: py2/py3
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
789 # compatible version
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
790 except EnvironmentError as e:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
791 if e.errno != errno.ENOENT:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
792 raise
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
793 else:
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
794 raise OptionValueError(
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
795 self, _val,
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
796 "Unable to read value for %s. Error opening "
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
797 "%s: %s." % (self.name, e.filename, e.args[1]))
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
798 return self.str2value(_val)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
799
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
800 def validate(self, options):
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
801 if self.name == 'MAIL_PASSWORD':
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
802 if options['MAIL_USERNAME']._value:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
803 # MAIL_PASSWORD is an exception. It is mandatory only
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
804 # if MAIL_USERNAME is set. So check only if username
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
805 # is set.
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
806 try:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
807 self.get()
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
808 except OptionUnsetError:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
809 # provide error message with link to MAIL_USERNAME
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
810 raise OptionValueError(
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
811 options["MAIL_PASSWORD"],
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
812 "not defined",
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
813 "Mail username is set, so this must be defined.")
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
814 else:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
815 self.get()
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
816
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
817
5770
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
818 class WebUrlOption(Option):
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
819 """URL MUST start with http/https scheme and end with '/'"""
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
820
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
821 def str2value(self, value):
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
822 if not value:
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
823 raise OptionValueError(self, value, "Value must not be empty.")
5770
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
824
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
825 error_msg = ''
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
826 if not value.startswith(('http://', 'https://')):
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
827 error_msg = "Value must start with http:// or https://.\n"
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
828
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
829 if not value.endswith('/'):
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
830 error_msg += "Value must end with /."
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
831
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
832 if error_msg:
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
833 raise OptionValueError(self, value, error_msg)
5770
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
834 else:
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
835 return value
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
836
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
837
2624
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
838 class NullableOption(Option):
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
839
4074
e039f3cbbb96 Make RDBMS cache-size configurable.
Stefan Seefeld <stefan@seefeld.name>
parents: 4013
diff changeset
840 """Option that is set to None if its string value is one of NULL strings
2624
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
841
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
842 Default nullable strings list contains empty string only.
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
843 There is constructor parameter allowing to specify different nullables.
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
844
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
845 Conversion to external representation returns the first of the NULL
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
846 strings list when the value is None.
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
847
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
848 """
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
849
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
850 NULL_STRINGS = ("",)
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
851
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
852 def __init__(self, config, section, setting,
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
853 default=NODEFAULT, description=None, aliases=None,
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
854 null_strings=NULL_STRINGS):
2624
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
855 self.null_strings = list(null_strings)
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
856 Option.__init__(self, config, section, setting, default,
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
857 description, aliases)
2624
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
858
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
859 def str2value(self, value):
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
860 if value in self.null_strings:
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
861 return None
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
862 else:
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
863 return value
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
864
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
865 def _value2str(self, value):
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
866 if value is None:
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
867 return self.null_strings[0]
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
868 else:
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
869 return value
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
870
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
871
2624
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
872 class NullableFilePathOption(NullableOption, FilePathOption):
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
873
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
874 # .get() and class_description are from FilePathOption,
2624
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
875 get = FilePathOption.get
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
876 class_description = FilePathOption.class_description
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
877 # everything else taken from NullableOption (inheritance order)
2624
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
878
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
879
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
880 class SecretMandatoryOption(MandatoryOption, SecretOption):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
881 # use get from SecretOption and rest from MandatoryOption
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
882 get = SecretOption.get
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
883 class_description = SecretOption.class_description
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
884
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
885
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
886 class SecretNullableOption(NullableOption, SecretOption):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
887 # use get from SecretOption and rest from NullableOption
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
888 get = SecretOption.get
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
889 class_description = SecretOption.class_description
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
890
7844
b95474b23440 chore(lint): whitespace fixes, double space between class stanzas
John Rouillard <rouilj@ieee.org>
parents: 7812
diff changeset
891
7809
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
892 class ListSecretOption(SecretOption):
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
893 # use get from SecretOption
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
894 def get(self):
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
895 value = SecretOption.get(self)
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
896 return [x.lstrip() for x in value.split(',')]
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
897
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
898 class_description = SecretOption.class_description
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
899
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
900 def validate(self, options): # noqa: ARG002 -- options unused
7809
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
901 if self.name == "WEB_JWT_SECRET":
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
902 secrets = self.get()
7844
b95474b23440 chore(lint): whitespace fixes, double space between class stanzas
John Rouillard <rouilj@ieee.org>
parents: 7812
diff changeset
903 invalid_secrets = [x for x in secrets[1:] if len(x) < 32]
7809
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
904 if invalid_secrets:
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
905 raise OptionValueError(
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
906 self, ", ".join(secrets),
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
907 "One or more secrets less then 32 characters in length\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
908 "found: %s" % ', '.join(invalid_secrets))
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
909 else:
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
910 self.get()
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
911
7844
b95474b23440 chore(lint): whitespace fixes, double space between class stanzas
John Rouillard <rouilj@ieee.org>
parents: 7812
diff changeset
912
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
913 class RedisUrlOption(SecretNullableOption):
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
914 """Do required check to make sure known bad parameters are not
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
915 put in the url.
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
916
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
917 Should I do more URL validation? Validate schema:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
918 redis, rediss, unix? How many cycles to invest
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
919 to keep users from their own mistakes?
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
920 """
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
921
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
922 class_description = SecretNullableOption.class_description
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
923
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
924 def str2value(self, value):
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
925 if value and value.find("decode_responses") != -1:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
926 raise OptionValueError(self, value, "URL must not include "
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
927 "decode_responses. Please remove "
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
928 "the option.")
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
929 return value
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
930
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
931
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
932 class SessiondbBackendOption(Option):
7219
5c71b27aa68e fix typo
John Rouillard <rouilj@ieee.org>
parents: 7183
diff changeset
933 """Make sure that sessiondb is compatible with the primary db.
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
934 Fail with error and suggestions if they are incompatible.
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
935 """
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
936
7845
0c71ac9cdcd0 chore(lint): change class props from mutable lists to tuples
John Rouillard <rouilj@ieee.org>
parents: 7844
diff changeset
937 compatibility_matrix = (
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
938 ('anydbm', 'anydbm'),
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
939 ('anydbm', 'redis'),
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
940 ('sqlite', 'anydbm'),
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
941 ('sqlite', 'sqlite'),
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
942 ('sqlite', 'redis'),
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
943 ('mysql', 'mysql'),
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
944 ('postgresql', 'postgresql'),
7845
0c71ac9cdcd0 chore(lint): change class props from mutable lists to tuples
John Rouillard <rouilj@ieee.org>
parents: 7844
diff changeset
945 )
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
946
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
947 def validate(self, options):
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
948 ''' make sure session db is compatible with primary db.
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
949 also if redis is specified make sure it's available.
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
950 suggest valid session db backends include redis if
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
951 available.
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
952 '''
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
953
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
954 if self.name == 'SESSIONDB_BACKEND':
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
955 rdbms_backend = options['RDBMS_BACKEND']._value
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
956 sessiondb_backend = self._value
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
957
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
958 if not sessiondb_backend:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
959 # unset will choose default
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
960 return
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
961
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
962 redis_available = False
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
963 try:
7810
890097bc4cd0 chore(ruff): sort imports
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
964 import redis # noqa: F401
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
965 redis_available = True
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
966 except ImportError:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
967 if sessiondb_backend == 'redis':
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
968 valid_session_backends = ', '.join(sorted(
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
969 [x[1] for x in self.compatibility_matrix
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
970 if x[0] == rdbms_backend and x[1] != 'redis']))
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
971 raise OptionValueError(
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
972 self, sessiondb_backend,
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
973 "Unable to load redis module. Please install "
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
974 "a redis library or choose\n an alternate "
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
975 "session db: %(valid_session_backends)s" % locals())
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
976
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
977 if ((rdbms_backend, sessiondb_backend) not in
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
978 self.compatibility_matrix):
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
979 valid_session_backends = ', '.join(sorted(
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
980 {x[1] for x in self.compatibility_matrix
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
981 if x[0] == rdbms_backend and
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
982 (redis_available or x[1] != 'redis')}))
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
983
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
984 raise OptionValueError(
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
985 self, sessiondb_backend,
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
986 "You can not use session db type: %(sessiondb_backend)s "
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
987 "with %(rdbms_backend)s.\n Valid session db types: "
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
988 "%(valid_session_backends)s." % locals())
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
989
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
990
3620
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
991 class TimezoneOption(Option):
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
992
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
993 class_description = \
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
994 "If pytz module is installed, value may be any valid\n" \
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
995 "timezone specification (e.g. EET or Europe/Warsaw).\n" \
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
996 "If pytz is not installed, value must be integer number\n" \
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
997 "giving local timezone offset from UTC in hours."
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
998
5754
178ca608ddb9 Fix Issue2551030: Roundup fails to start if pytz to access Olson
John Rouillard <rouilj@ieee.org>
parents: 5748
diff changeset
999 # fix issue2551030, default value for timezone
178ca608ddb9 Fix Issue2551030: Roundup fails to start if pytz to access Olson
John Rouillard <rouilj@ieee.org>
parents: 5748
diff changeset
1000 # Must be 0 if no pytz can be UTC if pytz.
178ca608ddb9 Fix Issue2551030: Roundup fails to start if pytz to access Olson
John Rouillard <rouilj@ieee.org>
parents: 5748
diff changeset
1001 try:
178ca608ddb9 Fix Issue2551030: Roundup fails to start if pytz to access Olson
John Rouillard <rouilj@ieee.org>
parents: 5748
diff changeset
1002 import pytz
178ca608ddb9 Fix Issue2551030: Roundup fails to start if pytz to access Olson
John Rouillard <rouilj@ieee.org>
parents: 5748
diff changeset
1003 defaulttz = "UTC"
178ca608ddb9 Fix Issue2551030: Roundup fails to start if pytz to access Olson
John Rouillard <rouilj@ieee.org>
parents: 5748
diff changeset
1004 except ImportError:
178ca608ddb9 Fix Issue2551030: Roundup fails to start if pytz to access Olson
John Rouillard <rouilj@ieee.org>
parents: 5748
diff changeset
1005 defaulttz = "0"
178ca608ddb9 Fix Issue2551030: Roundup fails to start if pytz to access Olson
John Rouillard <rouilj@ieee.org>
parents: 5748
diff changeset
1006
3620
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
1007 def str2value(self, value):
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
1008 try:
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
1009 roundup.date.get_timezone(value)
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
1010 except KeyError:
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1011 raise OptionValueError(
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1012 self, value,
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1013 "Timezone name or numeric hour offset required")
3620
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
1014 return value
17124caa2491 added timezone option (based on patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3609
diff changeset
1015
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1016
6514
a036712c96f4 Enable HTTP/1.1 support for roundup-server
John Rouillard <rouilj@ieee.org>
parents: 6458
diff changeset
1017 class HttpVersionOption(Option):
a036712c96f4 Enable HTTP/1.1 support for roundup-server
John Rouillard <rouilj@ieee.org>
parents: 6458
diff changeset
1018 """Used by roundup-server to verify http version is set to valid
a036712c96f4 Enable HTTP/1.1 support for roundup-server
John Rouillard <rouilj@ieee.org>
parents: 6458
diff changeset
1019 string."""
a036712c96f4 Enable HTTP/1.1 support for roundup-server
John Rouillard <rouilj@ieee.org>
parents: 6458
diff changeset
1020
a036712c96f4 Enable HTTP/1.1 support for roundup-server
John Rouillard <rouilj@ieee.org>
parents: 6458
diff changeset
1021 def str2value(self, value):
a036712c96f4 Enable HTTP/1.1 support for roundup-server
John Rouillard <rouilj@ieee.org>
parents: 6458
diff changeset
1022 if value not in ["HTTP/1.0", "HTTP/1.1"]:
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1023 raise OptionValueError(
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1024 self, value,
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
1025 "Valid vaues for -V or --http_version are: HTTP/1.0, HTTP/1.1")
6514
a036712c96f4 Enable HTTP/1.1 support for roundup-server
John Rouillard <rouilj@ieee.org>
parents: 6458
diff changeset
1026 return value
a036712c96f4 Enable HTTP/1.1 support for roundup-server
John Rouillard <rouilj@ieee.org>
parents: 6458
diff changeset
1027
a036712c96f4 Enable HTTP/1.1 support for roundup-server
John Rouillard <rouilj@ieee.org>
parents: 6458
diff changeset
1028
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1029 class RegExpOption(Option):
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1030
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1031 """Regular Expression option (value is Regular Expression Object)"""
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1032
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1033 class_description = "Value is Python Regular Expression (UTF8-encoded)."
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1034
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1035 RE_TYPE = type(re.compile(""))
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1036
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1037 def __init__(self, config, section, setting,
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1038 default=NODEFAULT, description=None, aliases=None,
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1039 flags=0):
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1040 self.flags = flags
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1041 Option.__init__(self, config, section, setting, default,
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1042 description, aliases)
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1043
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1044 def _value2str(self, value):
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1045 assert isinstance(value, self.RE_TYPE) # noqa: S101 -- assert is ok
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1046 return value.pattern
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1047
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1048 def str2value(self, value):
5416
56c9bcdea47f Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5395
diff changeset
1049 if not isinstance(value, type(u'')):
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1050 value = str(value)
5416
56c9bcdea47f Python 3 preparation: unicode.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5395
diff changeset
1051 if not isinstance(value, type(u'')):
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1052 # if it is 7-bit ascii, use it as string,
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1053 # otherwise convert to unicode.
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1054 try:
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1055 value.decode("ascii")
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1056 except UnicodeError:
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1057 value = value.decode("utf-8")
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1058 return re.compile(value, self.flags)
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1059
7844
b95474b23440 chore(lint): whitespace fixes, double space between class stanzas
John Rouillard <rouilj@ieee.org>
parents: 7812
diff changeset
1060
7726
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1061 class LogLevelOption(Option):
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1062 """A log level, one of none, debug, info, warning, error, critical"""
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1063
7844
b95474b23440 chore(lint): whitespace fixes, double space between class stanzas
John Rouillard <rouilj@ieee.org>
parents: 7812
diff changeset
1064 values = "none debug info warning error critical".split()
b95474b23440 chore(lint): whitespace fixes, double space between class stanzas
John Rouillard <rouilj@ieee.org>
parents: 7812
diff changeset
1065 class_description = "Allowed values: %s" % (', '.join(values))
7726
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1066
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1067 def str2value(self, value):
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1068 _val = value.lower()
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1069 if _val in self.values:
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1070 return _val
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1071 else:
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1072 raise OptionValueError(self, value, self.class_description)
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1073
7844
b95474b23440 chore(lint): whitespace fixes, double space between class stanzas
John Rouillard <rouilj@ieee.org>
parents: 7812
diff changeset
1074
6730
031996eb9bb5 document jinja2 as valid setting for template_engine in config.ini
John Rouillard <rouilj@ieee.org>
parents: 6688
diff changeset
1075 try:
7810
890097bc4cd0 chore(ruff): sort imports
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
1076 import jinja2 # noqa: F401
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1077 jinja2_avail = "Available found"
6730
031996eb9bb5 document jinja2 as valid setting for template_engine in config.ini
John Rouillard <rouilj@ieee.org>
parents: 6688
diff changeset
1078 except ImportError:
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1079 jinja2_avail = "Unavailable needs"
6730
031996eb9bb5 document jinja2 as valid setting for template_engine in config.ini
John Rouillard <rouilj@ieee.org>
parents: 6688
diff changeset
1080
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1081 # Main configuration layout.
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1082 # Config is described as a sequence of sections,
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1083 # where each section name is followed by a sequence
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1084 # of Option definitions. Each Option definition
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1085 # is a sequence containing class name and constructor
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1086 # parameters, starting from the setting name:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1087 # setting, default, [description, [aliases]]
2627
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1088 # Note: aliases should only exist in historical options for backwards
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1089 # compatibility - new options should *not* have aliases!
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1090
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1091
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1092 SETTINGS = (
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1093 ("main", (
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1094 (FilePathOption, "database", "db", "Database directory path."),
4587
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4570
diff changeset
1095 (Option, "template_engine", "zopetal",
a2eb4fb3e6d8 New Chameleon templating engine, engine is now configurable.
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4570
diff changeset
1096 "Templating engine to use.\n"
6730
031996eb9bb5 document jinja2 as valid setting for template_engine in config.ini
John Rouillard <rouilj@ieee.org>
parents: 6688
diff changeset
1097 "Possible values are:\n"
031996eb9bb5 document jinja2 as valid setting for template_engine in config.ini
John Rouillard <rouilj@ieee.org>
parents: 6688
diff changeset
1098 " 'zopetal' for the old TAL engine ported from Zope,\n"
031996eb9bb5 document jinja2 as valid setting for template_engine in config.ini
John Rouillard <rouilj@ieee.org>
parents: 6688
diff changeset
1099 " 'chameleon' for Chameleon,\n"
031996eb9bb5 document jinja2 as valid setting for template_engine in config.ini
John Rouillard <rouilj@ieee.org>
parents: 6688
diff changeset
1100 " 'jinja2' for jinja2 templating.\n"
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1101 " %s jinja2 module." % jinja2_avail),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1102 (FilePathOption, "templates", "html",
2863
ae2907da636d added STATIC_FILES option
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2850
diff changeset
1103 "Path to the HTML templates directory."),
5231
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
1104 (MultiFilePathOption, "static_files", "",
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
1105 "A list of space separated directory paths (or a single\n"
7094
570abc4c6548 Improve documention on access to templates and static_files.
John Rouillard <rouilj@ieee.org>
parents: 6966
diff changeset
1106 "directory). These directories hold additional public\n"
570abc4c6548 Improve documention on access to templates and static_files.
John Rouillard <rouilj@ieee.org>
parents: 6966
diff changeset
1107 "static files available via Web UI. These directories\n"
570abc4c6548 Improve documention on access to templates and static_files.
John Rouillard <rouilj@ieee.org>
parents: 6966
diff changeset
1108 "may contain sitewide images, CSS stylesheets etc. If a\n"
570abc4c6548 Improve documention on access to templates and static_files.
John Rouillard <rouilj@ieee.org>
parents: 6966
diff changeset
1109 "'-' is included, the list processing ends and the\n"
570abc4c6548 Improve documention on access to templates and static_files.
John Rouillard <rouilj@ieee.org>
parents: 6966
diff changeset
1110 "TEMPLATES directory is not searched after the specified\n"
5231
8743b7226dc7 Fix issue with retreiving raw template files using the @@file mechanism.
John Rouillard <rouilj@ieee.org>
parents: 5214
diff changeset
1111 "directories. If this option is not set, all static\n"
7094
570abc4c6548 Improve documention on access to templates and static_files.
John Rouillard <rouilj@ieee.org>
parents: 6966
diff changeset
1112 "files are taken from the TEMPLATES directory. Access to\n"
570abc4c6548 Improve documention on access to templates and static_files.
John Rouillard <rouilj@ieee.org>
parents: 6966
diff changeset
1113 "these files is public, it is not checked against\n"
570abc4c6548 Improve documention on access to templates and static_files.
John Rouillard <rouilj@ieee.org>
parents: 6966
diff changeset
1114 "registered users. So do not put any sensitive data in\n"
570abc4c6548 Improve documention on access to templates and static_files.
John Rouillard <rouilj@ieee.org>
parents: 6966
diff changeset
1115 "the files in these directories."),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1116 (MailAddressOption, "admin_email", "roundup-admin",
4013
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1117 "Email address that roundup will complain to if it runs\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1118 "into trouble.\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1119 "If no domain is specified then the config item\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1120 "mail -> domain is added."),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1121 (MailAddressOption, "dispatcher_email", "roundup-admin",
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1122 "The 'dispatcher' is a role that can get notified\n"
7658
d30e534b078a clarify doc on dispatcher_email config setting.
John Rouillard <rouilj@ieee.org>
parents: 7567
diff changeset
1123 "when errors occur while sending email to a user.\n"
4013
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1124 "It is used by the ERROR_MESSAGES_TO config setting.\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1125 "If no domain is specified then the config item\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1126 "mail -> domain is added."),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1127 (Option, "email_from_tag", "",
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1128 'Additional text to include in the "name" part\n'
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1129 "of the From: address used in nosy messages.\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1130 'If the sending user is "Foo Bar", the From: line\n'
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1131 'is usually: "Foo Bar" <issue_tracker@tracker.example>\n'
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1132 'the EMAIL_FROM_TAG goes inside the "Foo Bar" quotes like so:\n'
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1133 '"Foo Bar EMAIL_FROM_TAG" <issue_tracker@tracker.example>'),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1134 (Option, "new_web_user_roles", "User",
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1135 "Roles that a user gets when they register\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1136 "with Web User Interface.\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1137 "This is a comma-separated string of role names\n"
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1138 " (e.g. 'Admin,User')."),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1139 (Option, "new_email_user_roles", "User",
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1140 "Roles that a user gets when they register\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1141 "with Email Gateway.\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1142 "This is a comma-separated string of role names\n"
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1143 " (e.g. 'Admin,User')."),
5315
5a014410f254 Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5305
diff changeset
1144 (Option, "obsolete_history_roles", "Admin",
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1145 "On schema changes, properties or classes in the history may\n"
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1146 "become obsolete. Since normal access permissions do not apply\n"
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1147 "(we don't know if a user should see such a property or class)\n"
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1148 "a list of roles is specified here that are allowed to see\n"
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1149 "these obsolete properties in the history. By default only the\n"
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1150 "admin role may see these history entries, you can make them\n"
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1151 "visible to all users by adding, e.g., the 'User' role here."),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1152 (Option, "error_messages_to", "user",
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1153 'Send error message emails to the "dispatcher", "user", \n'
6355
ac5a6ffa377b Description update. Description was a question not a statement.
John Rouillard <rouilj@ieee.org>
parents: 6354
diff changeset
1154 'or "both" (these are the three allowed values).\n'
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1155 'The dispatcher is configured using the DISPATCHER_EMAIL\n'
6211
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1156 ' setting.'),
7964
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
1157 (HtmlVersionOption, "html_version", "html4",
7452
bed28b64c581 Add xhtml deprecation notice.
John Rouillard <rouilj@ieee.org>
parents: 7371
diff changeset
1158 "This setting should be left at the default value of html4.\n"
7964
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
1159 "Support for xhtml has been disabled.\n"
791b61ed11c9 issue2551323 - Remove XHTML support
John Rouillard <rouilj@ieee.org>
parents: 7920
diff changeset
1160 "HTML version to generate. The templates are html4 by default."),
5754
178ca608ddb9 Fix Issue2551030: Roundup fails to start if pytz to access Olson
John Rouillard <rouilj@ieee.org>
parents: 5748
diff changeset
1161 (TimezoneOption, "timezone", TimezoneOption.defaulttz,
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1162 "Default timezone offset,\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1163 "applied when user's timezone is not set.",
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1164 ["DEFAULT_TIMEZONE"]),
2649
1df7d4a41da4 Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents: 2646
diff changeset
1165 (BooleanOption, "instant_registration", "no",
1df7d4a41da4 Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents: 2646
diff changeset
1166 "Register new users instantly, or require confirmation via\n"
1df7d4a41da4 Buncha stuff (sorry about the large checkin):
Richard Jones <richard@users.sourceforge.net>
parents: 2646
diff changeset
1167 "email?"),
3469
d3b02352484f enable registration confirmation by web only [SF#1381675]
Richard Jones <richard@users.sourceforge.net>
parents: 3452
diff changeset
1168 (BooleanOption, "email_registration_confirmation", "yes",
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1169 "Offer registration confirmation by email or only\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1170 "through the web?"),
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
1171 (IndexerOption, "indexer", "",
5096
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5045
diff changeset
1172 "Force Roundup to use a particular text indexer.\n"
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5045
diff changeset
1173 "If no indexer is supplied, the first available indexer\n"
e74c3611b138 - issue2550636, issue2550909: Added support for Whoosh indexer.
John Rouillard <rouilj@ieee.org>
parents: 5045
diff changeset
1174 "will be used in the following order:\n"
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
1175 "Possible values: xapian, whoosh, native (internal), "
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
1176 "native-fts.\nNote 'native-fts' will only be used if set."),
6353
9d209d2b34ae Add indexer_language to change stemmer for xapian FTS indexer
John Rouillard <rouilj@ieee.org>
parents: 6333
diff changeset
1177 (Option, "indexer_language", "english",
9d209d2b34ae Add indexer_language to change stemmer for xapian FTS indexer
John Rouillard <rouilj@ieee.org>
parents: 6333
diff changeset
1178 "Used to determine what language should be used by the\n"
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
1179 "indexer above. Applies to Xapian and PostgreSQL native-fts\n"
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
1180 "indexer. It sets the language for the stemmer, and PostgreSQL\n"
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
1181 "native-fts stopwords and other dictionaries.\n"
6353
9d209d2b34ae Add indexer_language to change stemmer for xapian FTS indexer
John Rouillard <rouilj@ieee.org>
parents: 6333
diff changeset
1182 "Possible values: must be a valid language for the indexer,\n"
9d209d2b34ae Add indexer_language to change stemmer for xapian FTS indexer
John Rouillard <rouilj@ieee.org>
parents: 6333
diff changeset
1183 "see indexer documentation for details."),
3544
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
1184 (WordListOption, "indexer_stopwords", "",
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
1185 "Additional stop-words for the full-text indexer specific to\n"
5cd1c83dea50 Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents: 3469
diff changeset
1186 "your tracker. See the indexer source for the default list of\n"
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
1187 "stop-words (eg. A,AND,ARE,AS,AT,BE,BUT,BY, ...). This is\n"
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
1188 "not used by the postgres native-fts indexer. But is used to\n"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
1189 "filter search terms with the sqlite native-fts indexer."),
5736
1b5bcc5d745f Change umask default to python 3 (put python2 compatible) format with
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
1190 (OctalNumberOption, "umask", "0o002",
3609
f2fda3e6fc8b umask is now configurable (with the same 0002 default)
Richard Jones <richard@users.sourceforge.net>
parents: 3548
diff changeset
1191 "Defines the file creation mode mask."),
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5773
diff changeset
1192 (IntegerNumberGeqZeroOption, 'csv_field_size', '131072',
4255
88af08f8666f New config option csv_field_size:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4088
diff changeset
1193 "Maximum size of a csv-field during import. Roundups export\n"
88af08f8666f New config option csv_field_size:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4088
diff changeset
1194 "format is a csv (comma separated values) variant. The csv\n"
88af08f8666f New config option csv_field_size:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4088
diff changeset
1195 "reader has a limit on the size of individual fields\n"
88af08f8666f New config option csv_field_size:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4088
diff changeset
1196 "starting with python 2.5. Set this to a higher value if you\n"
88af08f8666f New config option csv_field_size:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4088
diff changeset
1197 "get the error 'Error: field larger than field limit' during\n"
88af08f8666f New config option csv_field_size:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4088
diff changeset
1198 "import."),
7161
be7849588372 issue2551252 - increase PBKFD2 default rounds to 2,000,000.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
1199 (IntegerNumberGeqZeroOption, 'password_pbkdf2_default_rounds',
8239
6bd11a73f2ed issue2551253. default hash is PBKDF2-SHA512.
John Rouillard <rouilj@ieee.org>
parents: 8136
diff changeset
1200 '250000',
4486
693c75d56ebe Add new config-option 'password_pbkdf2_default_rounds'...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4484
diff changeset
1201 "Sets the default number of rounds used when encoding passwords\n"
8239
6bd11a73f2ed issue2551253. default hash is PBKDF2-SHA512.
John Rouillard <rouilj@ieee.org>
parents: 8136
diff changeset
1202 "using any PBKDF2 scheme. Set this to a higher value on faster\n"
6bd11a73f2ed issue2551253. default hash is PBKDF2-SHA512.
John Rouillard <rouilj@ieee.org>
parents: 8136
diff changeset
1203 "systems which want more security. Use a minimum of 250000\n"
6bd11a73f2ed issue2551253. default hash is PBKDF2-SHA512.
John Rouillard <rouilj@ieee.org>
parents: 8136
diff changeset
1204 "for PBKDF2-SHA512 which is the default hash in Roundup 2.5.\n"
4488
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1205 "PBKDF2 (Password-Based Key Derivation Function) is a\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1206 "password hashing mechanism that derives hash from the\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1207 "password and a random salt. For authentication this process\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1208 "is repeated with the same salt as in the stored hash.\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1209 "If both hashes match, the authentication succeeds.\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1210 "PBKDF2 supports a variable 'rounds' parameter which varies\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1211 "the time-cost of calculating the hash - doubling the number\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1212 "of rounds doubles the cpu time required to calculate it. The\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1213 "purpose of this is to periodically adjust the rounds as CPUs\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1214 "become faster. The currently enforced minimum number of\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1215 "rounds is 1000.\n"
d483a40e2f82 more verbose description of password hashing, thanks to Eli Collins
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4486
diff changeset
1216 "See: http://en.wikipedia.org/wiki/PBKDF2 and RFC2898"),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1217 )),
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1218 ("tracker", (
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1219 (Option, "name", "Roundup issue tracker",
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1220 "A descriptive name for your roundup instance."),
5770
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
1221 (WebUrlOption, "web", NODEFAULT,
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1222 "The web address that the tracker is viewable at.\n"
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1223 "This will be included in information\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1224 "sent to users of the tracker.\n"
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1225 "The URL MUST include the cgi-bin part or anything else\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1226 "that is required to get to the home page of the tracker.\n"
5770
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5754
diff changeset
1227 "URL MUST start with http/https scheme and end with '/'"),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1228 (MailAddressOption, "email", "issue_tracker",
4013
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1229 "Email address that mail to roundup should go to.\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1230 "If no domain is specified then mail_domain is added."),
5098
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1231 (Option, "replyto_address", "",
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1232 "Controls the reply-to header address used when sending\n"
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1233 "nosy messages.\n"
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1234 "If the value is unset (default) the roundup tracker's\n"
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1235 "email address (above) is used.\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1236 'If set to "AUTHOR" then the primary email address of the\n'
5098
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1237 "author of the change will be used as the reply-to\n"
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1238 "address. This allows email exchanges to occur outside of\n"
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1239 "the view of roundup and exposes the address of the person\n"
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1240 "who updated the issue, but it could be useful in some\n"
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1241 "unusual circumstances.\n"
99e289359798 issue2550803: Replying to NOSY mail goes to the tracker through
John Rouillard <rouilj@ieee.org>
parents: 5096
diff changeset
1242 "If set to some other value, the value is used as the reply-to\n"
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1243 "address. It must be a valid RFC2822 address or people will not\n"
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1244 "be able to reply."),
2922
9d2c5d7c6f85 added CoreConfig options TRACKER_LANGUAGE and MAILGW_LANGUAGE
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2906
diff changeset
1245 (NullableOption, "language", "",
9d2c5d7c6f85 added CoreConfig options TRACKER_LANGUAGE and MAILGW_LANGUAGE
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2906
diff changeset
1246 "Default locale name for this tracker.\n"
9d2c5d7c6f85 added CoreConfig options TRACKER_LANGUAGE and MAILGW_LANGUAGE
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2906
diff changeset
1247 "If this option is not set, the language is determined\n"
9d2c5d7c6f85 added CoreConfig options TRACKER_LANGUAGE and MAILGW_LANGUAGE
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2906
diff changeset
1248 "by OS environment variable LANGUAGE, LC_ALL, LC_MESSAGES,\n"
9d2c5d7c6f85 added CoreConfig options TRACKER_LANGUAGE and MAILGW_LANGUAGE
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2906
diff changeset
1249 "or LANG, in that order of preference."),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1250 )),
3356
2913b42c0810 enabled disabling of REMOTE_USER for when it's not a valid username
Richard Jones <richard@users.sourceforge.net>
parents: 3155
diff changeset
1251 ("web", (
4088
34434785f308 Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents: 4074
diff changeset
1252 (BooleanOption, "allow_html_file", "no",
34434785f308 Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents: 4074
diff changeset
1253 "Setting this option enables Roundup to serve uploaded HTML\n"
34434785f308 Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents: 4074
diff changeset
1254 "file content *as HTML*. This is a potential security risk\n"
34434785f308 Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents: 4074
diff changeset
1255 "and is therefore disabled by default. Set to 'yes' if you\n"
34434785f308 Plug a number of security holes:
Richard Jones <richard@users.sourceforge.net>
parents: 4074
diff changeset
1256 "trust *all* users uploading content to your tracker."),
3452
be505af06586 web_http_auth is boolean value
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3431
diff changeset
1257 (BooleanOption, 'http_auth', "yes",
3356
2913b42c0810 enabled disabling of REMOTE_USER for when it's not a valid username
Richard Jones <richard@users.sourceforge.net>
parents: 3155
diff changeset
1258 "Whether to use HTTP Basic Authentication, if present.\n"
6436
1f2f7c0b8968 issue2550837 - New option for web auth (also http header passing)
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
1259 "Roundup will use either the REMOTE_USER (the value set \n"
1f2f7c0b8968 issue2550837 - New option for web auth (also http header passing)
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
1260 "by http_auth_header) or HTTP_AUTHORIZATION\n"
3356
2913b42c0810 enabled disabling of REMOTE_USER for when it's not a valid username
Richard Jones <richard@users.sourceforge.net>
parents: 3155
diff changeset
1261 "variables supplied by your web server (in that order).\n"
2913b42c0810 enabled disabling of REMOTE_USER for when it's not a valid username
Richard Jones <richard@users.sourceforge.net>
parents: 3155
diff changeset
1262 "Set this option to 'no' if you do not wish to use HTTP Basic\n"
2913b42c0810 enabled disabling of REMOTE_USER for when it's not a valid username
Richard Jones <richard@users.sourceforge.net>
parents: 3155
diff changeset
1263 "Authentication in your web interface."),
6436
1f2f7c0b8968 issue2550837 - New option for web auth (also http header passing)
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
1264 (Option, "http_auth_header", "",
1f2f7c0b8968 issue2550837 - New option for web auth (also http header passing)
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
1265 "The HTTP header that holds the user authentication information.\n"
1f2f7c0b8968 issue2550837 - New option for web auth (also http header passing)
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
1266 "If empty (default) the REMOTE_USER header is used.\n"
1f2f7c0b8968 issue2550837 - New option for web auth (also http header passing)
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
1267 "This is used when the upstream HTTP server authenticates\n"
1f2f7c0b8968 issue2550837 - New option for web auth (also http header passing)
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
1268 "the user and passes the username using this HTTP header."),
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1269 (BooleanOption, "dynamic_compression", "yes",
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1270 "Setting this option makes roundup look at the Accept-Encoding\n"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1271 "header supplied by the client. It will compress the response\n"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1272 "on the fly using a common encoding. Disable it if your\n"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1273 "upstream server does compression of dynamic data."),
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1274 (BooleanOption, "use_precompressed_files", "no",
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1275 "Setting this option enables Roundup to serve precompressed\n"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1276 "static files. The admin must create the compressed files with\n"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1277 "proper extension (.gzip, .br, .zstd) in the same directory as\n"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1278 "the uncompressed file. If a precompressed file doesn't\n"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1279 "exist, the uncompressed file will be served possibly with\n"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6436
diff changeset
1280 "dynamic compression."),
6053
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1281 (BooleanOption, 'http_auth_convert_realm_to_lowercase', "no",
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1282 "If usernames consist of a name and a domain/realm part of\n"
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1283 "the form user@realm and we're using REMOTE_USER for\n"
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1284 "authentication (e.g. via Kerberos), convert the realm part\n"
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1285 "of the incoming REMOTE_USER to lowercase before matching\n"
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1286 "against the roundup username. This allows roundup usernames\n"
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1287 "to be lowercase (including the realm) and still follow the\n"
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1288 "Kerberos convention of using an uppercase realm. In\n"
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1289 "addition this is compatible with Active Directory which\n"
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1290 "stores the username with realm as UserPrincipalName in\n"
380dec305c28 Add config option 'http_auth_convert_realm_to_lowercase'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6004
diff changeset
1291 "lowercase."),
6211
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1292 (BooleanOption, 'cookie_takes_precedence', "no",
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1293 "If the http_auth option is in effect (see above)\n"
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1294 "we're accepting a REMOTE_USER variable resulting from\n"
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1295 "an authentication mechanism implemented in the web-server,\n"
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1296 "e.g., Kerberos login or similar. To override the mechanism\n"
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1297 "provided by the web-server (e.g. for enabling sub-login as\n"
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1298 "another user) we tell roundup that the cookie takes\n"
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1299 "precedence over a REMOTE_USER or HTTP_AUTHORIZATION\n"
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1300 "variable. So if both, a cookie and a REMOTE_USER is\n"
50960479f627 New config-option 'cookie_takes_precedence'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6152
diff changeset
1301 "present, the cookie wins.\n"),
5772
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
1302 (IntegerNumberGeqZeroOption, 'login_attempts_min', "3",
5717
cad18de2b988 issue2550949: Rate limit password guesses/login attempts.
John Rouillard <rouilj@ieee.org>
parents: 5698
diff changeset
1303 "Limit login attempts per user per minute to this number.\n"
cad18de2b988 issue2550949: Rate limit password guesses/login attempts.
John Rouillard <rouilj@ieee.org>
parents: 5698
diff changeset
1304 "By default the 4th login attempt in a minute will notify\n"
cad18de2b988 issue2550949: Rate limit password guesses/login attempts.
John Rouillard <rouilj@ieee.org>
parents: 5698
diff changeset
1305 "the user that they need to wait 20 seconds before trying to\n"
cad18de2b988 issue2550949: Rate limit password guesses/login attempts.
John Rouillard <rouilj@ieee.org>
parents: 5698
diff changeset
1306 "log in again. This limits password guessing attacks and\n"
5772
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
1307 "shouldn't need to be changed. Rate limiting on login can\n"
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
1308 "be disabled by setting the value to 0."),
5974
98a8509ce45c issue2550919 - Anti-bot signup using 4 second delay
John Rouillard <rouilj@ieee.org>
parents: 5956
diff changeset
1309 (IntegerNumberGeqZeroOption, 'registration_delay', "4",
98a8509ce45c issue2550919 - Anti-bot signup using 4 second delay
John Rouillard <rouilj@ieee.org>
parents: 5956
diff changeset
1310 "The number of seconds needed to complete the new user\n"
98a8509ce45c issue2550919 - Anti-bot signup using 4 second delay
John Rouillard <rouilj@ieee.org>
parents: 5956
diff changeset
1311 "registration form. This limits the rate at which bots\n"
98a8509ce45c issue2550919 - Anti-bot signup using 4 second delay
John Rouillard <rouilj@ieee.org>
parents: 5956
diff changeset
1312 "can attempt to sign up. Limit can be disabled by setting\n"
98a8509ce45c issue2550919 - Anti-bot signup using 4 second delay
John Rouillard <rouilj@ieee.org>
parents: 5956
diff changeset
1313 "the value to 0."),
5976
71c68961d9f4 - issue2550920 - Optionally detect duplicate username at registration.
John Rouillard <rouilj@ieee.org>
parents: 5974
diff changeset
1314 (BooleanOption, 'registration_prevalidate_username', "no",
71c68961d9f4 - issue2550920 - Optionally detect duplicate username at registration.
John Rouillard <rouilj@ieee.org>
parents: 5974
diff changeset
1315 "When registering a user, check that the username\n"
71c68961d9f4 - issue2550920 - Optionally detect duplicate username at registration.
John Rouillard <rouilj@ieee.org>
parents: 5974
diff changeset
1316 "is available before sending confirmation email.\n"
71c68961d9f4 - issue2550920 - Optionally detect duplicate username at registration.
John Rouillard <rouilj@ieee.org>
parents: 5974
diff changeset
1317 "Usually a username conflict is detected when\n"
71c68961d9f4 - issue2550920 - Optionally detect duplicate username at registration.
John Rouillard <rouilj@ieee.org>
parents: 5974
diff changeset
1318 "confirming the registration. Disabled by default as\n"
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1319 "it can be used for guessing existing usernames.\n"),
5212
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
1320 (SameSiteSettingOption, 'samesite_cookie_setting', "Lax",
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
1321 """Set the mode of the SameSite cookie option for
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
1322 the session cookie. Choices are 'Lax' or
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
1323 'Strict'. 'None' can be used to suppress the
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
1324 option. Strict mode provides additional security
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
1325 against CSRF attacks, but may confuse users who
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
1326 are logged into roundup and open a roundup link
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
1327 from a source other than roundup (e.g. link in
d4cc71beb102 Added support for SameSite cookie option for CSRF prevention
John Rouillard <rouilj@ieee.org>
parents: 5201
diff changeset
1328 email)."""),
5603
79da1ca2f94b Make xmlrpc and rest APIs configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5517
diff changeset
1329 (BooleanOption, 'enable_xmlrpc', "yes",
79da1ca2f94b Make xmlrpc and rest APIs configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5517
diff changeset
1330 """Whether to enable the XMLRPC API in the roundup web
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1331 interface. By default the XMLRPC endpoint is the string
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1332 'xmlrpc' after the roundup web url configured in the
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1333 'tracker' section. If this variable is set to 'no', the
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1334 xmlrpc path has no special meaning and will yield an
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1335 error message."""),
6658
408fd477761f Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6604
diff changeset
1336 (BooleanOption, 'translate_xmlrpc', 'no',
408fd477761f Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6604
diff changeset
1337 """Whether to enable i18n for the xmlrpc endpoint. Enable it if
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1338 you want to enable translation based on browsers lang
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1339 (if enabled), trackers lang (if set) or environment."""),
5603
79da1ca2f94b Make xmlrpc and rest APIs configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5517
diff changeset
1340 (BooleanOption, 'enable_rest', "yes",
79da1ca2f94b Make xmlrpc and rest APIs configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5517
diff changeset
1341 """Whether to enable the REST API in the roundup web
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1342 interface. By default the REST endpoint is the string
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1343 'rest' plus any additional REST-API parameters after the
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1344 roundup web url configured in the tracker section. If this
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1345 variable is set to 'no', the rest path has no special meaning
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1346 and will yield an error message."""),
6658
408fd477761f Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6604
diff changeset
1347 (BooleanOption, 'translate_rest', 'no',
408fd477761f Add i18n object to roundupdb.Database
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6604
diff changeset
1348 """Whether to enable i18n for the rest endpoint. Enable it if
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1349 you want to enable translation based on browsers lang
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1350 (if enabled), trackers lang (if set) or environment."""),
7726
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1351 (LogLevelOption, 'rest_logging', 'none',
6f66d74d37f3 Add configurable logging for REST
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7719
diff changeset
1352 "Log-Level for REST errors."),
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5773
diff changeset
1353 (IntegerNumberGeqZeroOption, 'api_calls_per_interval', "0",
5732
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1354 "Limit API calls per api_interval_in_sec seconds to\n"
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1355 "this number.\n"
5732
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1356 "Determines the burst rate and the rate that new api\n"
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1357 "calls will be made available. If set to 360 and\n"
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1358 "api_intervals_in_sec is set to 3600, the 361st call in\n"
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1359 "10 seconds results in a 429 error to the caller. It\n"
7556
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1360 "tells them to wait 10 seconds (3600/360) before making\n"
5732
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1361 "another api request. A value of 0 turns off rate\n"
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1362 "limiting in the API. Tune this as needed. See rest\n"
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1363 "documentation for more info.\n"),
7556
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1364 (IntegerNumberGtZeroOption, 'api_interval_in_sec', "3600",
5732
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1365 "Defines the interval in seconds over which an api client can\n"
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1366 "make api_calls_per_interval api calls. Tune this as needed.\n"),
7556
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1367 (IntegerNumberGeqZeroOption, 'api_failed_login_limit', "4",
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1368 "Limit login failure to the API per api_failed_login_interval_in_sec\n"
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1369 "seconds.\n"
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1370 "A value of 0 turns off failed login rate\n"
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1371 "limiting in the API. You should not disable this. See rest\n"
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1372 "documentation for more info.\n"),
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1373 (IntegerNumberGtZeroOption, 'api_failed_login_interval_in_sec', "600",
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1374 "Defines the interval in seconds over which api login failures\n"
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1375 "are recorded. It allows api_failed_login_limit login failures\n"
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7452
diff changeset
1376 "in this time interval. Tune this as needed.\n"),
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1377 (CsrfSettingOption, 'csrf_enforce_token', "yes",
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1378 """How do we deal with @csrf fields in posted forms.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1379 Set this to 'required' to block the post and notify
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1380 the user if the field is missing or invalid.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1381 Set this to 'yes' to block the post and notify the user
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1382 if the token is invalid, but accept the form if
5214
4c48180555fb Fix text formatting, typos and, English grammar of the descriptive text.
John Rouillard <rouilj@ieee.org>
parents: 5212
diff changeset
1383 the field is missing.
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1384 Set this to 'logfailure' to log a notice to the roundup
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1385 log if the field is invalid or missing, but accept
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1386 the post.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1387 Set this to 'no' to ignore the field and accept the post.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1388 """),
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5773
diff changeset
1389 (IntegerNumberGeqZeroOption, 'csrf_token_lifetime', "20160",
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1390 """csrf_tokens have a limited lifetime. If they are not
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1391 used they are purged from the database after this
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1392 number of minutes. Default (20160) is 2 weeks."""),
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1393 (CsrfSettingOption, 'csrf_enforce_header_X-REQUESTED-WITH', "yes",
5698
c7dd1cae3416 Update rest.txt example to include headers required for CSRF
John Rouillard <rouilj@ieee.org>
parents: 5603
diff changeset
1394 """This is only used for xmlrpc and rest requests. This test is
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1395 done after Origin and Referer headers are checked. It only
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1396 verifies that the X-Requested-With header exists. The value
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1397 is ignored.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1398 Set this to 'required' to block the post and notify
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1399 the user if the header is missing or invalid.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1400 Set this to 'yes' is the same as required.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1401 Set this to 'logfailure' is the same as 'no'.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1402 Set this to 'no' to ignore the header and accept the post."""),
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1403 (CsrfSettingOption, 'csrf_enforce_header_referer', "yes",
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1404 """Verify that the Referer http header matches the
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1405 tracker.web setting in config.ini.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1406 Set this to 'required' to block the post and notify
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1407 the user if the header is missing or invalid.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1408 Set this to 'yes' to block the post and notify the user
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1409 if the header is invalid, but accept the form if
8043
69629a4f7262 doc: in description, replace field with header for csrf_* settings
John Rouillard <rouilj@ieee.org>
parents: 8042
diff changeset
1410 the header is missing.
5214
4c48180555fb Fix text formatting, typos and, English grammar of the descriptive text.
John Rouillard <rouilj@ieee.org>
parents: 5212
diff changeset
1411 Set this to 'logfailure' to log a notice to the roundup
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1412 log if the header is invalid or missing, but accept
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1413 the post.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1414 Set this to 'no' to ignore the header and accept the post."""),
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1415 (CsrfSettingOption, 'csrf_enforce_header_origin', "yes",
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1416 """Verify that the Origin http header matches the
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1417 tracker.web setting in config.ini.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1418 Set this to 'required' to block the post and notify
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1419 the user if the header is missing or invalid.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1420 Set this to 'yes' to block the post and notify the user
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1421 if the header is invalid, but accept the form if
8043
69629a4f7262 doc: in description, replace field with header for csrf_* settings
John Rouillard <rouilj@ieee.org>
parents: 8042
diff changeset
1422 the header is missing.
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1423 Set this to 'logfailure' to log a notice to the roundup
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1424 log if the header is invalid or missing, but accept
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1425 the post.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1426 Set this to 'no' to ignore the header and accept the post."""),
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1427 (OriginHeadersListOption, 'allowed_api_origins', "",
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1428 """A comma separated list of additonal valid Origin header
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1429 values used when enforcing the header origin. They are used
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1430 only for the api URL's (/rest and /xmlrpc). They are not
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1431 used for the usual html URL's. These strings must match the
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1432 value of the Origin header exactly. So 'https://bar.edu' and
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1433 'https://Bar.edu' are two different Origin values. Note that
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1434 the origin value is scheme://host. There is no path
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1435 component. So 'https://bar.edu/' would never be valid.
7155
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 7141
diff changeset
1436 The value '*' can be used to match any origin. It must be
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 7141
diff changeset
1437 first in the list if used. Note that this value allows
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 7141
diff changeset
1438 any web page on the internet to make anonymous requests
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 7141
diff changeset
1439 against your Roundup tracker.
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1440
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1441 You need to set these if you have a web application on a
7155
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 7141
diff changeset
1442 different origin accessing your Roundup instance.
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1443
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1444 (The origin from the tracker.web setting in config.ini is
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6658
diff changeset
1445 always valid and does not need to be specified.)"""),
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1446 (CsrfSettingOption, 'csrf_enforce_header_x-forwarded-host', "yes",
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1447 """Verify that the X-Forwarded-Host http header matches
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1448 the host part of the tracker.web setting in config.ini.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1449 Set this to 'required' to block the post and notify
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1450 the user if the header is missing or invalid.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1451 Set this to 'yes' to block the post and notify the user
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1452 if the header is invalid, but accept the form if
8043
69629a4f7262 doc: in description, replace field with header for csrf_* settings
John Rouillard <rouilj@ieee.org>
parents: 8042
diff changeset
1453 the header is missing.
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1454 Set this to 'logfailure' to log a notice to the roundup
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1455 log if the header is invalid or missing, but accept
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1456 the post.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1457 Set this to 'no' to ignore the header and accept the post."""),
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1458 (CsrfSettingOption, 'csrf_enforce_header_host', "yes",
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1459 """"If there is no X-Forward-Host header, verify that
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1460 the Host http header matches the host part of the
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1461 tracker.web setting in config.ini.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1462 Set this to 'required' to block the post and notify
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1463 the user if the header is missing or invalid.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1464 Set this to 'yes' to block the post and notify the user
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1465 if the header is invalid, but accept the form if
8043
69629a4f7262 doc: in description, replace field with header for csrf_* settings
John Rouillard <rouilj@ieee.org>
parents: 8042
diff changeset
1466 the header is missing.
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1467 Set this to 'logfailure' to log a notice to the roundup
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1468 log if the header is invalid or missing, but accept
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1469 the post.
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1470 Set this to 'no' to ignore the header and accept the post."""),
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5773
diff changeset
1471 (IntegerNumberGeqZeroOption, 'csrf_header_min_count', "1",
5201
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1472 """Minimum number of header checks that must pass
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1473 to accept the request. Set to 0 to accept post
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1474 even if no header checks pass. Usually the Host header check
a9ace22e0a2f issue 2550690 - Adding anti-csrf measures to roundup following
John Rouillard <rouilj@ieee.org>
parents: 5189
diff changeset
1475 always passes, so setting it less than 1 is not recommended."""),
3425
2b27c92d64dc add web/use_browser_language option
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3417
diff changeset
1476 (BooleanOption, 'use_browser_language', "yes",
2b27c92d64dc add web/use_browser_language option
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3417
diff changeset
1477 "Whether to use HTTP Accept-Language, if present.\n"
2b27c92d64dc add web/use_browser_language option
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3417
diff changeset
1478 "Browsers send a language-region preference list.\n"
3548
61d48244e7a8 login may now be for a single session
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
1479 "It's usually set in the client's browser or in their\n"
3425
2b27c92d64dc add web/use_browser_language option
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3417
diff changeset
1480 "Operating System.\n"
2b27c92d64dc add web/use_browser_language option
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3417
diff changeset
1481 "Set this option to 'no' if you want to ignore it."),
3548
61d48244e7a8 login may now be for a single session
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
1482 (BooleanOption, "debug", "no",
61d48244e7a8 login may now be for a single session
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
1483 "Setting this option makes Roundup display error tracebacks\n"
61d48244e7a8 login may now be for a single session
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
1484 "in the user's browser rather than emailing them to the\n"
61d48244e7a8 login may now be for a single session
Richard Jones <richard@users.sourceforge.net>
parents: 3544
diff changeset
1485 "tracker admin."),
6684
9ca5cbffa0c4 Switch off using blank passwords for login
John Rouillard <rouilj@ieee.org>
parents: 6682
diff changeset
1486 (BooleanOption, "login_empty_passwords", "no",
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1487 "Setting this option to yes/true allows users with\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1488 "an empty/blank password to login to the\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1489 "web/http interfaces."),
4484
52e13bf0bb40 Add new config-option 'migrate_passwords' in section 'web'...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4474
diff changeset
1490 (BooleanOption, "migrate_passwords", "yes",
52e13bf0bb40 Add new config-option 'migrate_passwords' in section 'web'...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4474
diff changeset
1491 "Setting this option makes Roundup migrate passwords with\n"
52e13bf0bb40 Add new config-option 'migrate_passwords' in section 'web'...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4474
diff changeset
1492 "an insecure password-scheme to a more secure scheme\n"
52e13bf0bb40 Add new config-option 'migrate_passwords' in section 'web'...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4474
diff changeset
1493 "when the user logs in via the web-interface."),
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
1494 (SecretMandatoryOption, "secret_key", create_token(),
5726
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1495 "A per tracker secret used in etag calculations for\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1496 "an object. It must not be empty.\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1497 "It prevents reverse engineering hidden data in an object\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1498 "by calculating the etag for a sample object. Then modifying\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1499 "hidden properties until the sample object's etag matches\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1500 "the one returned by roundup.\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1501 "Changing this changes the etag and invalidates updates by\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1502 "clients. It must be persistent across application restarts.\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1503 "(Note the default value changes every time\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1504 " roundup-admin updateconfig\n"
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5717
diff changeset
1505 "is run, so it must be explicitly set to a non-empty string.\n"),
7809
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1506 (ListSecretOption, "jwt_secret", "disabled",
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1507 "This is used to sign/validate json web tokens\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1508 "(JWT). Even if you don't use JWTs it must not be\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1509 "empty. You can use multiple secrets separated by a\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1510 "comma ','. This allows for secret rotation. The newest\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1511 "secret should be placed first and used for signing. The\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1512 "rest of the secrets are used for validating an old JWT.\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1513 "If the first secret is less than 256 bits (32\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1514 "characters) in length JWTs are disabled. If other secrets\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1515 "are less than 32 chars, the application will exit. Removing\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1516 "a secret from this list invalidates all JWTs signed with\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1517 "the secret. JWT support is experimental and disabled by\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1518 "default. The secrets must be persistent across\n"
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7726
diff changeset
1519 "application restarts.\n"),
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1520 (BooleanOption, "use_browser_date_input", "no",
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1521 "HTML input elements for Date properties: This determines\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1522 "if we use the input type 'datetime-local' (or 'date') for\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1523 "date input fields. If the option is turned off (the default),\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1524 "the type is set to 'text'. Since the widgets generated by\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1525 "browsers determine the date format from the language\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1526 "setting (it is currently not possible to force the\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1527 "international date format server-side) and some browsers\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1528 "ignore the date format set by the operating system, the\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1529 "default is 'no'."),
8314
7ff47307b4b1 issue2551398 - Browser number input
John Rouillard <rouilj@ieee.org>
parents: 8300
diff changeset
1530 (BooleanOption, "use_browser_number_input", "no",
8300
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1531 "HTML input elements for Number properties: This determines\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1532 "if we use the input type 'number' for Number (and Integer)\n"
b99e76e76496 Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8239
diff changeset
1533 "properties. If set to 'no' we use input type 'text'."),
3356
2913b42c0810 enabled disabling of REMOTE_USER for when it's not a valid username
Richard Jones <richard@users.sourceforge.net>
parents: 3155
diff changeset
1534 )),
2634
f47ca4541770 Both RDBMS backends now use the same config.ini section, [rdbms].
Richard Jones <richard@users.sourceforge.net>
parents: 2630
diff changeset
1535 ("rdbms", (
5748
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
1536 (DatabaseBackend, 'backend', NODEFAULT,
943e61bc26d5 Fix issue2551029 (Jinja2 template install error) by deleting
John Rouillard <rouilj@ieee.org>
parents: 5736
diff changeset
1537 "Database backend."),
8136
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1538 (BooleanOption, "debug_filter", "no",
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1539 "Filter debugging: Permissions can define additional filter\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1540 "functions that are used when checking permissions on results\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1541 "returned by the database. This is done to improve\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1542 "performance since the filtering is done in the database\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1543 "backend, not in python (at least for the SQL backends). The\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1544 "user is responsible for making the filter return the same\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1545 "set of results as the check function for a permission. So it\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1546 "makes sense to aid in debugging (and performance\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1547 "measurements) to allow turning off the usage of filter\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1548 "functions using only the check functions."),
2634
f47ca4541770 Both RDBMS backends now use the same config.ini section, [rdbms].
Richard Jones <richard@users.sourceforge.net>
parents: 2630
diff changeset
1549 (Option, 'name', 'roundup',
7719
3071db43bfb6 feat: issue2550852 - support using a specified PostgreSQL db schema
John Rouillard <rouilj@ieee.org>
parents: 7696
diff changeset
1550 "Name of the database to use. For Postgresql, this can\n"
3071db43bfb6 feat: issue2550852 - support using a specified PostgreSQL db schema
John Rouillard <rouilj@ieee.org>
parents: 7696
diff changeset
1551 "be database.schema to use a specific schema within\n"
3071db43bfb6 feat: issue2550852 - support using a specified PostgreSQL db schema
John Rouillard <rouilj@ieee.org>
parents: 7696
diff changeset
1552 "a Postgres database.",
2636
943f9d4592b8 Backwards-compatibility aliases for mysql config.
Richard Jones <richard@users.sourceforge.net>
parents: 2634
diff changeset
1553 ['MYSQL_DBNAME']),
2637
11811b313459 The demo.py script works again using the new configuration system.
Richard Jones <richard@users.sourceforge.net>
parents: 2636
diff changeset
1554 (NullableOption, 'host', 'localhost',
2654
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
1555 "Database server host.",
2636
943f9d4592b8 Backwards-compatibility aliases for mysql config.
Richard Jones <richard@users.sourceforge.net>
parents: 2634
diff changeset
1556 ['MYSQL_DBHOST']),
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1557 (NullableOption, 'port', '',
2654
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
1558 "TCP port number of the database server.\n"
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
1559 "Postgresql usually resides on port 5432 (if any),\n"
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
1560 "for MySQL default port number is 3306.\n"
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
1561 "Leave this option empty to use backend default"),
2637
11811b313459 The demo.py script works again using the new configuration system.
Richard Jones <richard@users.sourceforge.net>
parents: 2636
diff changeset
1562 (NullableOption, 'user', 'roundup',
2654
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
1563 "Database user name that Roundup should use.",
2636
943f9d4592b8 Backwards-compatibility aliases for mysql config.
Richard Jones <richard@users.sourceforge.net>
parents: 2634
diff changeset
1564 ['MYSQL_DBUSER']),
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
1565 (SecretNullableOption, 'password', 'roundup',
2654
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
1566 "Database user password.",
2636
943f9d4592b8 Backwards-compatibility aliases for mysql config.
Richard Jones <richard@users.sourceforge.net>
parents: 2634
diff changeset
1567 ['MYSQL_DBPASSWORD']),
7696
4af0d235b570 feat(db): support using postgresql service connection file
John Rouillard <rouilj@ieee.org>
parents: 7658
diff changeset
1568 (NullableOption, 'service', '',
4af0d235b570 feat(db): support using postgresql service connection file
John Rouillard <rouilj@ieee.org>
parents: 7658
diff changeset
1569 "Name of the PostgreSQL connection service for this Roundup\n"
4af0d235b570 feat(db): support using postgresql service connection file
John Rouillard <rouilj@ieee.org>
parents: 7658
diff changeset
1570 "instance. Only used in Postgresql connections. You need to set\n"
4af0d235b570 feat(db): support using postgresql service connection file
John Rouillard <rouilj@ieee.org>
parents: 7658
diff changeset
1571 "up a pg_service.conf file usable by psql use this option."),
3099
519b92df37dc handle ~/.my.cnf files for MySQL defaults [SF#1096031]
Richard Jones <richard@users.sourceforge.net>
parents: 2922
diff changeset
1572 (NullableOption, 'read_default_file', '~/.my.cnf',
519b92df37dc handle ~/.my.cnf files for MySQL defaults [SF#1096031]
Richard Jones <richard@users.sourceforge.net>
parents: 2922
diff changeset
1573 "Name of the MySQL defaults file.\n"
519b92df37dc handle ~/.my.cnf files for MySQL defaults [SF#1096031]
Richard Jones <richard@users.sourceforge.net>
parents: 2922
diff changeset
1574 "Only used in MySQL connections."),
519b92df37dc handle ~/.my.cnf files for MySQL defaults [SF#1096031]
Richard Jones <richard@users.sourceforge.net>
parents: 2922
diff changeset
1575 (NullableOption, 'read_default_group', 'roundup',
519b92df37dc handle ~/.my.cnf files for MySQL defaults [SF#1096031]
Richard Jones <richard@users.sourceforge.net>
parents: 2922
diff changeset
1576 "Name of the group to use in the MySQL defaults file (.my.cnf).\n"
519b92df37dc handle ~/.my.cnf files for MySQL defaults [SF#1096031]
Richard Jones <richard@users.sourceforge.net>
parents: 2922
diff changeset
1577 "Only used in MySQL connections."),
6333
bd84f43e1d13 Fixes to mysql 2.0 conversion doc issue2551115 Werner Hunger
John Rouillard <rouilj@ieee.org>
parents: 6332
diff changeset
1578 (Option, 'mysql_charset', 'utf8mb4',
7860
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1579 "Charset to use for mysql connection and databases.\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1580 "If set to 'default', no charset option is used when\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1581 "creating the db connection and utf8mb4 is used for the\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1582 "database charset.\n"
6152
546763f4ce44 Make the charset configurable for mysql
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6126
diff changeset
1583 "Otherwise any permissible mysql charset is allowed here.\n"
546763f4ce44 Make the charset configurable for mysql
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6126
diff changeset
1584 "Only used in MySQL connections."),
7860
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1585 (Option, 'mysql_collation', 'utf8mb4_unicode_ci',
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1586 "Comparison/order to use for mysql database/table collations.\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1587 "When upgrading, you can use 'utf8' to match the\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1588 "depricated 'utf8mb3'. This must be compatible with the\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1589 "mysql_charset setting above. Only used by MySQL."),
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1590 (Option, 'mysql_binary_collation', 'utf8mb4_0900_bin',
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1591 "Comparison/order to use for mysql database/table collations\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1592 "when matching case. When upgrading, you can use 'utf8_bin'\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1593 "to match the depricated 'utf8mb3_bin' collation. This must\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1594 "be compatible with the mysql_collation above. Only used\n"
8b31893f5930 issue2551115/issue2551282 - utf8mb4 support in roundup
John Rouillard <rouilj@ieee.org>
parents: 7845
diff changeset
1595 "by MySQL."),
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5773
diff changeset
1596 (IntegerNumberGeqZeroOption, 'sqlite_timeout', '30',
4415
3e35233ea93c new rdbms config item sqlite_timeout...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4411
diff changeset
1597 "Number of seconds to wait when the SQLite database is locked\n"
3e35233ea93c new rdbms config item sqlite_timeout...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4411
diff changeset
1598 "Default: use a 30 second timeout (extraordinarily generous)\n"
3e35233ea93c new rdbms config item sqlite_timeout...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4411
diff changeset
1599 "Only used in SQLite connections."),
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5773
diff changeset
1600 (IntegerNumberGeqZeroOption, 'cache_size', '100',
7920
6aa0525187cd doc: use generated config.ini in reference.txt
John Rouillard <rouilj@ieee.org>
parents: 7915
diff changeset
1601 "Size of the node cache (in elements). Used to keep the\n"
6aa0525187cd doc: use generated config.ini in reference.txt
John Rouillard <rouilj@ieee.org>
parents: 7915
diff changeset
1602 "most recently used data in memory."),
4474
9b4cf6c96ee2 Add flags to allow to restrict DB modifications.
Stefan Seefeld <stefan@seefeld.name>
parents: 4471
diff changeset
1603 (BooleanOption, "allow_create", "yes",
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1604 "Setting this option to 'no' protects the database against\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1605 "table creations."),
4474
9b4cf6c96ee2 Add flags to allow to restrict DB modifications.
Stefan Seefeld <stefan@seefeld.name>
parents: 4471
diff changeset
1606 (BooleanOption, "allow_alter", "yes",
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1607 "Setting this option to 'no' protects the database against\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1608 "table alterations."),
4474
9b4cf6c96ee2 Add flags to allow to restrict DB modifications.
Stefan Seefeld <stefan@seefeld.name>
parents: 4471
diff changeset
1609 (BooleanOption, "allow_drop", "yes",
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1610 "Setting this option to 'no' protects the database against\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1611 "table drops."),
4471
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1612 (NullableOption, 'template', '',
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1613 "Name of the PostgreSQL template for database creation.\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1614 "For database creation the template used has to match\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1615 "the character encoding used (UTF8), there are different\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1616 "PostgreSQL installations using different templates with\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1617 "different encodings. If you get an error:\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1618 " new encoding (UTF8) is incompatible with the encoding of\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1619 " the template database (SQL_ASCII)\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1620 " HINT: Use the same encoding as in the template database,\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1621 " or use template0 as template.\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1622 "then set this option to the template name given in the\n"
4f353d71d716 Configuration issue:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4424
diff changeset
1623 "error message."),
4887
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
1624 (IsolationOption, 'isolation_level', 'read committed',
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
1625 "Database isolation level, currently supported for\n"
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
1626 "PostgreSQL and mysql. See, e.g.,\n"
05c857e5dbed New rdbms configuration option 'isolation_level'
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4786
diff changeset
1627 "http://www.postgresql.org/docs/9.1/static/transaction-iso.html"),
6332
6a6b4651be1f Use server-side cursor for postgres in some cases
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6300
diff changeset
1628 (BooleanOption, "serverside_cursor", "yes",
6a6b4651be1f Use server-side cursor for postgres in some cases
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6300
diff changeset
1629 "Set the database cursor for filter queries to serverside\n"
6a6b4651be1f Use server-side cursor for postgres in some cases
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6300
diff changeset
1630 "cursor, this avoids caching large amounts of data in the\n"
6a6b4651be1f Use server-side cursor for postgres in some cases
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6300
diff changeset
1631 "client. This option only applies for the postgresql backend."),
8136
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1632 ), "Most settings in this section (except for backend and debug_filter)\n"
5a2b9435a04d Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents: 8043
diff changeset
1633 "are used by RDBMS backends only.",
2654
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
1634 ),
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1635 ("sessiondb", (
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1636 (SessiondbBackendOption, "backend", "",
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1637 "Set backend for storing one time key (otk) and session data.\n"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1638 "Values have to be compatible with main backend.\n"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1639 "main\\/ session>| anydbm | sqlite | redis | mysql | postgresql |\n"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1640 " anydbm | D | | X | | |\n"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1641 " sqlite | X | D | X | | |\n"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1642 " mysql | | | | D | |\n"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1643 " postgresql | | | | | D |\n"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1644 " -------------------------------------------------------------+\n"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1645 " D - default if unset, X - compatible choice"),
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1646 (RedisUrlOption, "redis_url",
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1647 "redis://localhost:6379/0?health_check_interval=2",
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1648 "URL used to connect to redis. Default uses unauthenticated\n"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1649 "redis database 0 running on localhost with default port.\n"),
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6730
diff changeset
1650 ), "Choose configuration for session and one time key storage."),
2619
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1651 ("logging", (
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1652 (FilePathOption, "config", "",
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1653 "Path to configuration file for standard Python logging module.\n"
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1654 "If this option is set, logging configuration is loaded\n"
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1655 "from specified file; options 'filename' and 'level'\n"
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1656 "in this section are ignored."),
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1657 (FilePathOption, "filename", "",
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1658 "Log file name for minimal logging facility built into Roundup.\n"
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1659 "If no file name specified, log messages are written on stderr.\n"
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1660 "If above 'config' option is set, this option has no effect."),
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1661 (Option, "level", "ERROR",
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1662 "Minimal severity level of messages written to log file.\n"
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1663 "If above 'config' option is set, this option has no effect.\n"
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1664 "Allowed values: DEBUG, INFO, WARNING, ERROR"),
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1665 (LoggingFormatOption, "format",
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1666 "%(asctime)s %(trace_id)s %(levelname)s %(message)s",
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1667 "Format of the logging messages with all '%' signs\n"
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1668 "doubled so they are not interpreted by the config file."),
5939
94c415c7cd36 Make gunicorn --access-logfile work with custom logging config
John Rouillard <rouilj@ieee.org>
parents: 5878
diff changeset
1669 (BooleanOption, "disable_loggers", "no",
94c415c7cd36 Make gunicorn --access-logfile work with custom logging config
John Rouillard <rouilj@ieee.org>
parents: 5878
diff changeset
1670 "If set to yes, only the loggers configured in this section will\n"
5956
1cfd52dee91b Fix doc typo.
John Rouillard <rouilj@ieee.org>
parents: 5939
diff changeset
1671 "be used. Yes will disable gunicorn's --access-logfile.\n"),
2619
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
1672 )),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1673 ("mail", (
4013
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1674 (Option, "domain", NODEFAULT,
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1675 "The email domain that admin_email, issue_tracker and\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1676 "dispatcher_email belong to.\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1677 "This domain is added to those config items if they don't\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1678 "explicitly include a domain.\n"
a5b68d46bce8 Try to clarify mail_domain config setting
Richard Jones <richard@users.sourceforge.net>
parents: 3945
diff changeset
1679 "Do not include the '@' symbol."),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1680 (Option, "host", NODEFAULT,
2844
5dddfc64816d mailgw backward-compatibility: "MAILHOST" alias for "MAIL_HOST"
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2839
diff changeset
1681 "SMTP mail host that roundup will use to send mail",
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1682 ["MAILHOST"]),
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1683 (Option, "username", "", "SMTP login name.\n"
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
1684 "Set this if your mail host requires authenticated access.\n"
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
1685 "If username is not empty, password (below) MUST be set!"),
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
1686 (SecretMandatoryOption, "password", NODEFAULT, "SMTP login password.\n"
2623
4e1030d49cea fix: Option defaults were applied as strings...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2622
diff changeset
1687 "Set this if your mail host requires authenticated access."),
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5773
diff changeset
1688 (IntegerNumberGeqZeroOption, "port", smtplib.SMTP_PORT,
3878
6d14a3b4e295 allow admin to specify port and local hostname for SMTP connections
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3877
diff changeset
1689 "Default port to send SMTP on.\n"
6d14a3b4e295 allow admin to specify port and local hostname for SMTP connections
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3877
diff changeset
1690 "Set this if your mail server runs on a different port."),
6d14a3b4e295 allow admin to specify port and local hostname for SMTP connections
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3877
diff changeset
1691 (NullableOption, "local_hostname", '',
7920
6aa0525187cd doc: use generated config.ini in reference.txt
John Rouillard <rouilj@ieee.org>
parents: 7915
diff changeset
1692 "The (fully qualified) host/ domain name (FQDN) to use during\n"
6aa0525187cd doc: use generated config.ini in reference.txt
John Rouillard <rouilj@ieee.org>
parents: 7915
diff changeset
1693 "SMTP sessions. If left blank, the underlying SMTP library will\n"
6aa0525187cd doc: use generated config.ini in reference.txt
John Rouillard <rouilj@ieee.org>
parents: 7915
diff changeset
1694 "attempt to detect your FQDN. Set this if your mail server\n"
6aa0525187cd doc: use generated config.ini in reference.txt
John Rouillard <rouilj@ieee.org>
parents: 7915
diff changeset
1695 "requires something specific.\n"),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1696 (BooleanOption, "tls", "no",
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1697 "If your SMTP mail host provides or requires TLS\n"
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1698 "(Transport Layer Security) then set this option to 'yes'."),
2624
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
1699 (NullableFilePathOption, "tls_keyfile", "",
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1700 "If TLS is used, you may set this option to the name\n"
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1701 "of a PEM formatted file that contains your private key."),
2624
f40d5f0f1086 added NullableOption, NullableFilePathOption;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2623
diff changeset
1702 (NullableFilePathOption, "tls_certfile", "",
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1703 "If TLS is used, you may set this option to the name\n"
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1704 "of a PEM formatted certificate chain file."),
2627
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1705 (Option, "charset", "utf-8",
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1706 "Character set to encode email headers with.\n"
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1707 "We use utf-8 by default, as it's the most flexible.\n"
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1708 "Some mail readers (eg. Eudora) can't cope with that,\n"
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1709 "so you might need to specify a more limited character set\n"
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1710 "(eg. iso-8859-1).",
2627
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1711 ["EMAIL_CHARSET"]),
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1712 (FilePathOption, "debug", "",
5214
4c48180555fb Fix text formatting, typos and, English grammar of the descriptive text.
John Rouillard <rouilj@ieee.org>
parents: 5212
diff changeset
1713 "Setting this option makes Roundup write all outgoing email\n"
2627
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1714 "messages to this file *instead* of sending them.\n"
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1715 "This option has the same effect as the environment variable\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1716 "SENDMAILDEBUG.\nEnvironment variable takes precedence."),
3877
83748b2de465 Make addition of line about new submission/comment at top of each message...
Erik Forsberg <forsberg@users.sourceforge.net>
parents: 3854
diff changeset
1717 (BooleanOption, "add_authorinfo", "yes",
83748b2de465 Make addition of line about new submission/comment at top of each message...
Erik Forsberg <forsberg@users.sourceforge.net>
parents: 3854
diff changeset
1718 "Add a line with author information at top of all messages\n"
83748b2de465 Make addition of line about new submission/comment at top of each message...
Erik Forsberg <forsberg@users.sourceforge.net>
parents: 3854
diff changeset
1719 "sent by roundup"),
83748b2de465 Make addition of line about new submission/comment at top of each message...
Erik Forsberg <forsberg@users.sourceforge.net>
parents: 3854
diff changeset
1720 (BooleanOption, "add_authoremail", "yes",
7371
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1721 "Add the mail address of the author to the author information\n"
a210f4437b49 Incomplete work to generate config doc from config.ini
John Rouillard <rouilj@ieee.org>
parents: 7251
diff changeset
1722 "at the top of all messages.\n"
3879
454ee9411e85 Fix truncated comment for add_authoremail option.
Erik Forsberg <forsberg@users.sourceforge.net>
parents: 3878
diff changeset
1723 "If this is false but add_authorinfo is true, only the name\n"
454ee9411e85 Fix truncated comment for add_authoremail option.
Erik Forsberg <forsberg@users.sourceforge.net>
parents: 3878
diff changeset
1724 "of the actor is added which protects the mail address of the\n"
454ee9411e85 Fix truncated comment for add_authoremail option.
Erik Forsberg <forsberg@users.sourceforge.net>
parents: 3878
diff changeset
1725 "actor from being exposed at mail archives, etc."),
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1726 ), "Outgoing email options.\n"
7920
6aa0525187cd doc: use generated config.ini in reference.txt
John Rouillard <rouilj@ieee.org>
parents: 7915
diff changeset
1727 "Used for nosy messages, password reset and registration approval\n"
6aa0525187cd doc: use generated config.ini in reference.txt
John Rouillard <rouilj@ieee.org>
parents: 7915
diff changeset
1728 "requests."),
2627
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1729 ("mailgw", (
5117
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
1730 (EmailBodyOption, "keep_quoted_text", "yes",
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1731 "Keep email citations when accepting messages.\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1732 'Setting this to "no" strips out "quoted" text\n'
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1733 'from the message. Setting this to "new" keeps quoted\n'
5117
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
1734 "text only if a new issue is being created.\n"
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1735 "Signatures are also stripped.",
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1736 ["EMAIL_KEEP_QUOTED_TEXT"]),
5117
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
1737 (EmailBodyOption, "leave_body_unchanged", "no",
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1738 'Setting this to "yes" preserves the email body\n'
5117
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
1739 "as is - that is, keep the citations _and_ signatures.\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1740 'Setting this to "new" keeps the body only if we are\n'
5117
14abd0a67207 Fix issue934009: Have New Issues Submitted By Email *Not* Change Body!
John Rouillard <rouilj@ieee.org>
parents: 5102
diff changeset
1741 "creating a new issue.",
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1742 ["EMAIL_LEAVE_BODY_UNCHANGED"]),
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1743 (Option, "default_class", "issue",
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1744 "Default class to use in the mailgw\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1745 "if one isn't supplied in email subjects.\n"
2627
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1746 "To disable, leave the value blank.",
ce6a965a86f4 Move around some option groupings as I see them.
Richard Jones <richard@users.sourceforge.net>
parents: 2625
diff changeset
1747 ["MAIL_DEFAULT_CLASS"]),
2922
9d2c5d7c6f85 added CoreConfig options TRACKER_LANGUAGE and MAILGW_LANGUAGE
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2906
diff changeset
1748 (NullableOption, "language", "",
9d2c5d7c6f85 added CoreConfig options TRACKER_LANGUAGE and MAILGW_LANGUAGE
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2906
diff changeset
1749 "Default locale name for the tracker mail gateway.\n"
9d2c5d7c6f85 added CoreConfig options TRACKER_LANGUAGE and MAILGW_LANGUAGE
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2906
diff changeset
1750 "If this option is not set, mail gateway will use\n"
9d2c5d7c6f85 added CoreConfig options TRACKER_LANGUAGE and MAILGW_LANGUAGE
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2906
diff changeset
1751 "the language of the tracker instance."),
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1752 (Option, "subject_prefix_parsing", "strict",
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1753 "Controls the parsing of the [prefix] on subject\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1754 'lines in incoming emails. "strict" will return an\n'
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1755 "error to the sender if the [prefix] is not recognised.\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1756 '"loose" will attempt to parse the [prefix] but just\n'
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1757 "pass it through as part of the issue title if not\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1758 'recognised. "none" will always pass any [prefix]\n'
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1759 "through as part of the issue title."),
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1760 (Option, "subject_suffix_parsing", "strict",
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1761 "Controls the parsing of the [suffix] on subject\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1762 'lines in incoming emails. "strict" will return an\n'
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1763 "error to the sender if the [suffix] is not recognised.\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1764 '"loose" will attempt to parse the [suffix] but just\n'
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1765 "pass it through as part of the issue title if not\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1766 'recognised. "none" will always pass any [suffix]\n'
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1767 "through as part of the issue title."),
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1768 (Option, "subject_suffix_delimiters", "[]",
3725
65badf6ab7ad fix config documentation
Richard Jones <richard@users.sourceforge.net>
parents: 3620
diff changeset
1769 "Defines the brackets used for delimiting the prefix and \n"
65badf6ab7ad fix config documentation
Richard Jones <richard@users.sourceforge.net>
parents: 3620
diff changeset
1770 'suffix in a subject line. The presence of "suffix" in\n'
65badf6ab7ad fix config documentation
Richard Jones <richard@users.sourceforge.net>
parents: 3620
diff changeset
1771 "the config option name is a historical artifact and may\n"
65badf6ab7ad fix config documentation
Richard Jones <richard@users.sourceforge.net>
parents: 3620
diff changeset
1772 "be ignored."),
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1773 (Option, "subject_content_match", "always",
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1774 "Controls matching of the incoming email subject line\n"
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1775 "against issue titles in the case where there is no\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1776 'designator [prefix]. "never" turns off matching.\n'
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1777 '"creation + interval" or "activity + interval"\n'
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1778 "will match an issue for the interval after the issue's\n"
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1779 "creation or last activity. The interval is a standard\n"
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1780 "Roundup interval."),
4405
863ec554525c new mailgw config option subject_updates_title...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4342
diff changeset
1781 (BooleanOption, "subject_updates_title", "yes",
863ec554525c new mailgw config option subject_updates_title...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4342
diff changeset
1782 "Update issue title if incoming subject of email is different.\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1783 'Setting this to "no" will ignore the title part of'
4405
863ec554525c new mailgw config option subject_updates_title...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4342
diff changeset
1784 " the subject\nof incoming email messages.\n"),
5809
936275dfe1fa Try to fix:
John Rouillard <rouilj@ieee.org>
parents: 5774
diff changeset
1785 (RegExpOption, "refwd_re", r"(\s*\W?\s*(fw|fwd|re|aw|sv|ang)\W)+",
3831
14ec78618bd5 Allow customisation of regular expressions used in email parsing...
Richard Jones <richard@users.sourceforge.net>
parents: 3820
diff changeset
1786 "Regular expression matching a single reply or forward\n"
14ec78618bd5 Allow customisation of regular expressions used in email parsing...
Richard Jones <richard@users.sourceforge.net>
parents: 3820
diff changeset
1787 "prefix prepended by the mailer. This is explicitly\n"
14ec78618bd5 Allow customisation of regular expressions used in email parsing...
Richard Jones <richard@users.sourceforge.net>
parents: 3820
diff changeset
1788 "stripped from the subject during parsing."),
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1789 (RegExpOption, "origmsg_re",
5809
936275dfe1fa Try to fix:
John Rouillard <rouilj@ieee.org>
parents: 5774
diff changeset
1790 r"^[>|\s]*-----\s?Original Message\s?-----$",
3831
14ec78618bd5 Allow customisation of regular expressions used in email parsing...
Richard Jones <richard@users.sourceforge.net>
parents: 3820
diff changeset
1791 "Regular expression matching start of an original message\n"
14ec78618bd5 Allow customisation of regular expressions used in email parsing...
Richard Jones <richard@users.sourceforge.net>
parents: 3820
diff changeset
1792 "if quoted the in body."),
5809
936275dfe1fa Try to fix:
John Rouillard <rouilj@ieee.org>
parents: 5774
diff changeset
1793 (RegExpOption, "sign_re", r"^[>|\s]*-- ?$",
3831
14ec78618bd5 Allow customisation of regular expressions used in email parsing...
Richard Jones <richard@users.sourceforge.net>
parents: 3820
diff changeset
1794 "Regular expression matching the start of a signature\n"
14ec78618bd5 Allow customisation of regular expressions used in email parsing...
Richard Jones <richard@users.sourceforge.net>
parents: 3820
diff changeset
1795 "in the message body."),
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1796 (RegExpOption, "eol_re", r"[\r\n]+",
3831
14ec78618bd5 Allow customisation of regular expressions used in email parsing...
Richard Jones <richard@users.sourceforge.net>
parents: 3820
diff changeset
1797 "Regular expression matching end of line."),
3835
b66615f3007b added RegExpOption
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3831
diff changeset
1798 (RegExpOption, "blankline_re", r"[\r\n]+\s*[\r\n]+",
3831
14ec78618bd5 Allow customisation of regular expressions used in email parsing...
Richard Jones <richard@users.sourceforge.net>
parents: 3820
diff changeset
1799 "Regular expression matching a blank line."),
4424
f1affb6b7a08 Mail gateway fixes and improvements.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4415
diff changeset
1800 (BooleanOption, "unpack_rfc822", "no",
f1affb6b7a08 Mail gateway fixes and improvements.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4415
diff changeset
1801 "Unpack attached messages (encoded as message/rfc822 in MIME)\n"
f1affb6b7a08 Mail gateway fixes and improvements.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4415
diff changeset
1802 "as multiple parts attached as files to the issue, if not\n"
f1affb6b7a08 Mail gateway fixes and improvements.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4415
diff changeset
1803 "set we handle message/rfc822 attachments as a single file."),
3945
1dd64778bc45 Mail improvements:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3922
diff changeset
1804 (BooleanOption, "ignore_alternatives", "no",
1dd64778bc45 Mail improvements:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3922
diff changeset
1805 "When parsing incoming mails, roundup uses the first\n"
1dd64778bc45 Mail improvements:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3922
diff changeset
1806 "text/plain part it finds. If this part is inside a\n"
1dd64778bc45 Mail improvements:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3922
diff changeset
1807 "multipart/alternative, and this option is set, all other\n"
1dd64778bc45 Mail improvements:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3922
diff changeset
1808 "parts of the multipart/alternative are ignored. The default\n"
1dd64778bc45 Mail improvements:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3922
diff changeset
1809 "is to keep all parts and attach them to the issue."),
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
1810 (HtmlToTextOption, "convert_htmltotext", "none",
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
1811 "If an email has only text/html parts, use this module\n"
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
1812 "to convert the html to text. Choose from beautifulsoup 4,\n"
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
1813 "dehtml - (internal code), or none to disable conversion.\n"
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
1814 "If 'none' is selected, email without a text/plain part\n"
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
1815 "will be returned to the user with a message. If\n"
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
1816 "beautifulsoup is selected but not installed dehtml will\n"
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
1817 "be used instead."),
5045
a46d5d0fd5f8 Fix issue1615201: Added a new configuration option EMAIL_KEEP_REAL_FROM
Peter Funk <pf@artcom-gmbh.de>
parents: 5041
diff changeset
1818 (BooleanOption, "keep_real_from", "no",
a46d5d0fd5f8 Fix issue1615201: Added a new configuration option EMAIL_KEEP_REAL_FROM
Peter Funk <pf@artcom-gmbh.de>
parents: 5041
diff changeset
1819 "When handling emails ignore the Resent-From:-header\n"
a46d5d0fd5f8 Fix issue1615201: Added a new configuration option EMAIL_KEEP_REAL_FROM
Peter Funk <pf@artcom-gmbh.de>
parents: 5041
diff changeset
1820 "and use the original senders From:-header instead.\n"
a46d5d0fd5f8 Fix issue1615201: Added a new configuration option EMAIL_KEEP_REAL_FROM
Peter Funk <pf@artcom-gmbh.de>
parents: 5041
diff changeset
1821 "(This might be desirable in some situations where a moderator\n"
a46d5d0fd5f8 Fix issue1615201: Added a new configuration option EMAIL_KEEP_REAL_FROM
Peter Funk <pf@artcom-gmbh.de>
parents: 5041
diff changeset
1822 "reads incoming messages first before bouncing them to Roundup)",
a46d5d0fd5f8 Fix issue1615201: Added a new configuration option EMAIL_KEEP_REAL_FROM
Peter Funk <pf@artcom-gmbh.de>
parents: 5041
diff changeset
1823 ["EMAIL_KEEP_REAL_FROM"]),
a46d5d0fd5f8 Fix issue1615201: Added a new configuration option EMAIL_KEEP_REAL_FROM
Peter Funk <pf@artcom-gmbh.de>
parents: 5041
diff changeset
1824 ), "Roundup Mail Gateway options"),
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3882
diff changeset
1825 ("pgp", (
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3882
diff changeset
1826 (BooleanOption, "enable", "no",
5494
b7fa56ced601 use gpg module instead of pyme module for PGP encryption
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5424
diff changeset
1827 "Enable PGP processing. Requires gpg. If you're planning\n"
4541
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1828 "to send encrypted PGP mail to the tracker, you should also\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1829 "enable the encrypt-option below, otherwise mail received\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1830 "encrypted might be sent unencrypted to another user."),
3922
586679a314f7 role checking for PGP mail and docs
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3915
diff changeset
1831 (NullableOption, "roles", "",
586679a314f7 role checking for PGP mail and docs
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3915
diff changeset
1832 "If specified, a comma-separated list of roles to perform\n"
586679a314f7 role checking for PGP mail and docs
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3915
diff changeset
1833 "PGP processing on. If not specified, it happens for all\n"
4541
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1834 "users. Note that received PGP messages (signed and/or\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1835 "encrypted) will be processed with PGP even if the user\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1836 "doesn't have one of the PGP roles, you can use this to make\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1837 "PGP processing completely optional by defining a role here\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1838 "and not assigning any users to that role."),
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3882
diff changeset
1839 (NullableOption, "homedir", "",
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3882
diff changeset
1840 "Location of PGP directory. Defaults to $HOME/.gnupg if\n"
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3882
diff changeset
1841 "not specified."),
4541
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1842 (BooleanOption, "encrypt", "no",
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1843 "Enable PGP encryption. All outgoing mails are encrypted.\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1844 "This requires that keys for all users (with one of the gpg\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1845 "roles above or all users if empty) are available. Note that\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1846 "it makes sense to educate users to also send mails encrypted\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1847 "to the tracker, to enforce this, set 'require_incoming'\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1848 "option below (but see the note)."),
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1849 (Option, "require_incoming", "signed",
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1850 "Require that pgp messages received by roundup are either\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1851 "'signed', 'encrypted' or 'both'. If encryption is required\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1852 "we do not return the message (in clear) to the user but just\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1853 "send an informational message that the message was rejected.\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1854 "Note that this still presents known-plaintext to an attacker\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1855 "when the users sends the mail a second time with encryption\n"
62239a524beb PGP support is again working (pyme API has changed significantly)...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4488
diff changeset
1856 "turned on."),
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3882
diff changeset
1857 ), "OpenPGP mail processing options"),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1858 ("nosy", (
4547
d9d7319afffa Add config-option "nosy" to messages_to_author setting in [nosy] section...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4541
diff changeset
1859 (Option, "messages_to_author", "no",
d9d7319afffa Add config-option "nosy" to messages_to_author setting in [nosy] section...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4541
diff changeset
1860 "Send nosy messages to the author of the message.\n"
d9d7319afffa Add config-option "nosy" to messages_to_author setting in [nosy] section...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4541
diff changeset
1861 "Allowed values: yes, no, new, nosy -- if yes, messages\n"
d9d7319afffa Add config-option "nosy" to messages_to_author setting in [nosy] section...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4541
diff changeset
1862 "are sent to the author even if not on the nosy list, same\n"
d9d7319afffa Add config-option "nosy" to messages_to_author setting in [nosy] section...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4541
diff changeset
1863 "for new (but only for new messages). When set to nosy,\n"
d9d7319afffa Add config-option "nosy" to messages_to_author setting in [nosy] section...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4541
diff changeset
1864 "the nosy list controls sending messages to the author.",
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1865 ["MESSAGES_TO_AUTHOR"]),
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1866 (Option, "signature_position", "bottom",
2630
a65bae7af6d1 NOSY_MESSAGES_TO_AUTHOR is RunDetectorOption (values: yes, no, new)...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2629
diff changeset
1867 "Where to place the email signature.\n"
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1868 "Allowed values: top, bottom, none",
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1869 ["EMAIL_SIGNATURE_POSITION"]),
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1870 (RunDetectorOption, "add_author", "new",
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1871 "Does the author of a message get placed on the nosy list\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1872 "automatically? If 'new' is used, then the author will\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1873 "only be added when a message creates a new issue.\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1874 "If 'yes', then the author will be added on followups too.\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1875 "If 'no', they're never added to the nosy.\n",
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1876 ["ADD_AUTHOR_TO_NOSY"]),
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1877 (RunDetectorOption, "add_recipients", "new",
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1878 "Do the recipients (To:, Cc:) of a message get placed on the\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1879 "nosy list? If 'new' is used, then the recipients will\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1880 "only be added when a message creates a new issue.\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1881 "If 'yes', then the recipients will be added on followups too.\n"
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1882 "If 'no', they're never added to the nosy.\n",
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1883 ["ADD_RECIPIENTS_TO_NOSY"]),
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1884 (Option, "email_sending", "single",
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1885 "Controls the email sending from the nosy reactor. If\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1886 '"multiple" then a separate email is sent to each\n'
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1887 'recipient. If "single" then a single email is sent with\n'
3417
07c696890f55 mailgw subject parsing has configurable levels of strictness
Richard Jones <richard@users.sourceforge.net>
parents: 3356
diff changeset
1888 "each recipient as a CC address."),
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5773
diff changeset
1889 (IntegerNumberGeqZeroOption, "max_attachment_size", sys.maxsize,
3882
46ef2a6fd79d config option to limit nosy attachments based on size
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3879
diff changeset
1890 "Attachments larger than the given number of bytes\n"
46ef2a6fd79d config option to limit nosy attachments based on size
Justus Pendleton <jpend@users.sourceforge.net>
parents: 3879
diff changeset
1891 "won't be attached to nosy mails. They will be replaced by\n"
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1892 "a link to the tracker's download page for the file."),
2654
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
1893 ), "Nosy messages sending"),
6277
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6211
diff changeset
1894 ("markdown", (
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6211
diff changeset
1895 (BooleanOption, "break_on_newline", "no",
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6211
diff changeset
1896 "If yes/true, render single new line characters in markdown\n"
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6211
diff changeset
1897 "text with <br>. Set true if you want GitHub Flavored Markdown\n"
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6211
diff changeset
1898 "(GFM) handling of embedded newlines."),
957a0fc20021 issue2551094 - markdown mismatch - new config for embedded newine
John Rouillard <rouilj@ieee.org>
parents: 6211
diff changeset
1899 ), "Markdown rendering options."),
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1900 )
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1901
6966
8733aa2a8e40 flake8 fixes.
John Rouillard <rouilj@ieee.org>
parents: 6915
diff changeset
1902 # Configuration classes
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1903
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
1904
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1905 class Config:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1906
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1907 """Base class for configuration objects.
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1908
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1909 Configuration options may be accessed as attributes or items
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1910 of instances of this class. All option names are uppercased.
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1911
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1912 """
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1913
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1914 # Config file name
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1915 INI_FILE = "config.ini"
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1916
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1917 # Object attributes that should not be taken as common configuration
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1918 # options in __setattr__ (most of them are initialized in constructor):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1919 # builtin pseudo-option - package home directory
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1920 HOME = "."
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1921 # names of .ini file sections, in order
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1922 sections = None
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1923 # section comments
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1924 section_descriptions = None
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1925 # lists of option names for each section, in order
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1926 section_options = None
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1927 # mapping from option names and aliases to Option instances
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1928 options = None
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
1929 # actual name of the config file. set on load.
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
1930 filepath = os.path.join(HOME, INI_FILE)
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1931
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
1932 # List of option names that need additional validation after
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
1933 # all options are loaded.
7251
ab0ea9f03866 fix initialization of option_validator
John Rouillard <rouilj@ieee.org>
parents: 7219
diff changeset
1934 option_validators = None
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
1935
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
1936 def __init__(self, config_path=None, layout=None, settings=None):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1937 """Initialize confing instance
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1938
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1939 Parameters:
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
1940 config_path:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
1941 optional directory or file name of the config file.
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
1942 If passed, load the config after processing layout (if any).
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
1943 If config_path is a directory name, use default base name
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
1944 of the config file.
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1945 layout:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1946 optional configuration layout, a sequence of
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1947 section definitions suitable for .add_section()
3431
26dc6b92ac26 Config, CoreConfig: accept setting overrides in constructor
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3425
diff changeset
1948 settings:
26dc6b92ac26 Config, CoreConfig: accept setting overrides in constructor
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3425
diff changeset
1949 optional setting overrides (dictionary).
26dc6b92ac26 Config, CoreConfig: accept setting overrides in constructor
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3425
diff changeset
1950 The overrides are applied after loading config file.
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1951
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1952 """
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
1953 if settings is None:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
1954 settings = {}
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1955 # initialize option containers:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1956 self.sections = []
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1957 self.section_descriptions = {}
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1958 self.section_options = {}
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1959 self.options = {}
7251
ab0ea9f03866 fix initialization of option_validator
John Rouillard <rouilj@ieee.org>
parents: 7219
diff changeset
1960 self.option_validators = []
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1961 # add options from the layout structure
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1962 if layout:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1963 for section in layout:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1964 self.add_section(*section)
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
1965 if config_path is not None:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
1966 self.load(config_path)
3431
26dc6b92ac26 Config, CoreConfig: accept setting overrides in constructor
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3425
diff changeset
1967 for (name, value) in settings.items():
26dc6b92ac26 Config, CoreConfig: accept setting overrides in constructor
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3425
diff changeset
1968 self[name.upper()] = value
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1969
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1970 def add_section(self, section, options, description=None):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1971 """Define new config section
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1972
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1973 Parameters:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1974 section - name of the config.ini section
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1975 options - a sequence of Option definitions.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1976 Each Option definition is a sequence
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1977 containing class object and constructor
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1978 parameters, starting from the setting name:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1979 setting, default, [description, [aliases]]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1980 description - optional section comment
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1981
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1982 Note: aliases should only exist in historical options
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1983 for backwards compatibility - new options should
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1984 *not* have aliases!
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1985
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1986 """
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
1987 if description or (section not in self.section_descriptions):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1988 self.section_descriptions[section] = description
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1989 for option_def in options:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1990 klass = option_def[0]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1991 args = option_def[1:]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1992 option = klass(self, section, *args)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
1993 self.add_option(option)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1994
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1995 def add_option(self, option):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1996 """Adopt a new Option object"""
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1997 _section = option.section
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1998 _name = option.setting
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1999 if _section not in self.sections:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2000 self.sections.append(_section)
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2001 _options = self._get_section_options(_section)
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2002 if _name not in _options:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2003 _options.append(_name)
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2004 # (section, name) key is used for writing .ini file
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2005 self.options[(_section, _name)] = option
4074
e039f3cbbb96 Make RDBMS cache-size configurable.
Stefan Seefeld <stefan@seefeld.name>
parents: 4013
diff changeset
2006 # make the option known under all of its A.K.A.s
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2007 for _name in option.aliases:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2008 self.options[_name] = option
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2009
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
2010 if hasattr(option, 'validate'):
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
2011 self.option_validators.append(option.name)
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
2012
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2013 def update_option(self, name, klass,
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
2014 default=NODEFAULT, description=None):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2015 """Override behaviour of early created option.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2016
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2017 Parameters:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2018 name:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2019 option name
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2020 klass:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2021 one of the Option classes
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2022 default:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2023 optional default value for the option
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2024 description:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2025 optional new description for the option
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2026
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2027 Conversion from current option value to new class value
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2028 is done via string representation.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2029
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2030 This method may be used to attach some brains
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2031 to options autocreated by UserConfig.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2032
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2033 """
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2034 # fetch current option
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2035 option = self._get_option(name)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2036 # compute constructor parameters
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2037 if default is NODEFAULT:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2038 default = option.default
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2039 if description is None:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2040 description = option.description
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2041 value = option.value2str(current=1)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2042 # resurrect the option
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2043 option = klass(self, option.section, option.setting,
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
2044 default=default, description=description)
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2045 # apply the value
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2046 option.set(value)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2047 # incorporate new option
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2048 del self[name]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2049 self.add_option(option)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2050
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2051 def reset(self):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2052 """Set all options to their default values"""
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2053 for _option in self.items():
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2054 _option.reset()
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2055
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2056 # Meant for commandline tools.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2057 # Allows automatic creation of configuration files like this:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2058 # roundup-server -p 8017 -u roundup --save-config
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2059 def getopt(self, args, short_options="", long_options=(),
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
2060 config_load_options=("C", "config"), **options):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2061 """Apply options specified in command line arguments.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2062
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2063 Parameters:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2064 args:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2065 command line to parse (sys.argv[1:])
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2066 short_options:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2067 optional string of letters for command line options
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2068 that are not config options
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2069 long_options:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2070 optional list of names for long options
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2071 that are not config options
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2072 config_load_options:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2073 two-element sequence (letter, long_option) defining
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2074 the options for config file. If unset, don't load
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2075 config file; otherwise config file is read prior
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2076 to applying other options. Short option letter
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2077 must not have a colon and long_option name must
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2078 not have an equal sign or '--' prefix.
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2079 options:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2080 mapping from option names to command line option specs.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2081 e.g. server_port="p:", server_user="u:"
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2082 Names are forced to lower case for commandline parsing
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2083 (long options) and to upper case to find config options.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2084 Command line options accepting no value are assumed
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2085 to be binary and receive value 'yes'.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2086
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2087 Return value: same as for python standard getopt(), except that
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2088 processed options are removed from returned option list.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2089
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2090 """
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2091 # take a copy of long_options
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2092 long_options = list(long_options)
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2093 # build option lists
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2094 cfg_names = {}
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2095 booleans = []
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2096 for (name, letter) in options.items():
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2097 cfg_name = name.upper()
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2098 short_opt = "-" + letter[0]
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
2099 name = name.lower().replace("_", "-") # noqa: PLW2901 change name
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2100 cfg_names.update({short_opt: cfg_name, "--" + name: cfg_name})
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2101
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2102 short_options += letter
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2103 if letter[-1] == ":":
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2104 long_options.append(name + "=")
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2105 else:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2106 booleans.append(short_opt)
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2107 long_options.append(name)
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2108
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2109 if config_load_options:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2110 short_options += config_load_options[0] + ":"
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2111 long_options.append(config_load_options[1] + "=")
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2112 # compute names that will be searched in getopt return value
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2113 config_load_options = (
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2114 "-" + config_load_options[0],
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2115 "--" + config_load_options[1],
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2116 )
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2117 # parse command line arguments
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2118 optlist, args = getopt.getopt(args, short_options, long_options)
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2119 # load config file if requested
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2120 if config_load_options:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2121 for option in optlist:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2122 if option[0] in config_load_options:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2123 self.load_ini(option[1])
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2124 optlist.remove(option)
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2125 break
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2126 # apply options
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2127 extra_options = []
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2128 for (opt, arg) in optlist:
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
2129 if (opt in booleans): # and not arg
7812
ecc34b7917e2 chore(refactor): multiple changes/cleanups
John Rouillard <rouilj@ieee.org>
parents: 7811
diff changeset
2130 arg = "yes" # noqa: PLW2901 -- change arg
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2131 try:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2132 name = cfg_names[opt]
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2133 except KeyError:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2134 extra_options.append((opt, arg))
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2135 else:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2136 self[name] = arg
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2137 return (extra_options, args)
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2138
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2139 # option and section locators (used in option access methods)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2140
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2141 def _get_option(self, name):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2142 try:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2143 return self.options[name]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2144 except KeyError:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2145 raise InvalidOptionError(name)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2146
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2147 def _get_section_options(self, name):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2148 return self.section_options.setdefault(name, [])
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2149
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2150 def _get_unset_options(self):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2151 """Return options that need manual adjustments
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2152
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2153 Return value is a dictionary where keys are section
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2154 names and values are lists of option names as they
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2155 appear in the config file.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2156
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2157 """
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2158 need_set = {}
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2159 for option in self.items():
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2160 if not option.isset():
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2161 need_set.setdefault(option.section, []).append(option.setting)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2162 return need_set
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2163
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2164 def _adjust_options(self, config):
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2165 """Load ad-hoc option definitions from ConfigParser instance."""
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2166 pass
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2167
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2168 def _get_name(self):
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2169 """Return the service name for config file heading"""
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2170 return ""
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2171
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2172 # file operations
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2173
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2174 def load_ini(self, config_path, defaults=None):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2175 """Set options from config.ini file in given home_dir
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2176
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2177 Parameters:
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2178 config_path:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2179 directory or file name of the config file.
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2180 If config_path is a directory name, use default
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2181 base name of the config file
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2182 defaults:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2183 optional dictionary of defaults for ConfigParser
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2184
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2185 Note: if home_dir does not contain config.ini file,
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2186 no error is raised. Config will be reset to defaults.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2187
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2188 """
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2189 if os.path.isdir(config_path):
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2190 home_dir = config_path
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2191 config_path = os.path.join(config_path, self.INI_FILE)
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2192 else:
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2193 home_dir = os.path.dirname(config_path)
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2194 # parse the file
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2195 config_defaults = {"HOME": home_dir}
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2196 if defaults:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2197 config_defaults.update(defaults)
5246
c5dd7b151ec2 Make an import work with either Python 2 or 3.
Eric S. Raymond <esr@thyrsus.com>
parents: 5231
diff changeset
2198 config = configparser.ConfigParser(config_defaults)
2839
f965de0c1e75 fix load_ini: configuration file name was ignored after all
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2770
diff changeset
2199 config.read([config_path])
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2200 # .ini file loaded ok.
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2201 self.HOME = home_dir
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2202 self.filepath = config_path
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2203 self._adjust_options(config)
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2204 # set the options, starting from HOME
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2205 self.reset()
2654
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
2206 for option in self.items():
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
2207 option.load_ini(config)
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2208
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2209 def load(self, home_dir):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2210 """Load configuration settings from home_dir"""
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2211 self.load_ini(home_dir)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2212
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2213 def save(self, ini_file=None):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2214 """Write current configuration to .ini file
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2215
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2216 'ini_file' argument, if passed, must be valid full path
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2217 to the file to write. If omitted, default file in current
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2218 HOME is created.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2219
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2220 If the file to write already exists, it is saved with '.bak'
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2221 extension.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2222
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2223 """
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2224 if ini_file is None:
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2225 ini_file = self.filepath
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2226 _tmp_file = os.path.splitext(ini_file)[0]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2227 _bak_file = _tmp_file + ".bak"
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2228 _tmp_file = _tmp_file + ".tmp"
7811
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2229 with open(_tmp_file, "wt") as _fp:
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2230 _fp.write("# %s configuration file\n" % self._get_name())
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2231 _fp.write("# Autogenerated at %s\n" % time.asctime())
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2232 need_set = self._get_unset_options()
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2233 if need_set:
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2234 _fp.write("\n# WARNING! Following options need adjustments:\n")
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2235 for section, options in need_set.items():
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2236 _fp.write("# [%s]: %s\n" % (section, ", ".join(options)))
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2237 for section in self.sections:
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2238 comment = self.section_descriptions.get(section, None)
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2239 if comment:
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2240 _fp.write("\n# ".join([""] + comment.split("\n")) + "\n")
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2241 else:
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2242 # no section comment - just leave a blank line between sections
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2243 _fp.write("\n")
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2244 _fp.write("[%s]\n" % section)
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2245 for option in self._get_section_options(section):
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2246 _fp.write("\n" + self.options[(section, option)].format())
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2247
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2248 if os.access(ini_file, os.F_OK):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2249 if os.access(_bak_file, os.F_OK):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2250 os.remove(_bak_file)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2251 os.rename(ini_file, _bak_file)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2252 os.rename(_tmp_file, ini_file)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2253
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2254 # container emulation
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2255
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2256 def __len__(self):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2257 return len(self.items())
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2258
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2259 def __getitem__(self, name):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2260 if name == "HOME":
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2261 return self.HOME
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2262 else:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2263 return self._get_option(name).get()
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2264
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2265 def __setitem__(self, name, value):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2266 if name == "HOME":
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2267 self.HOME = value
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2268 else:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2269 self._get_option(name).set(value)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2270
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2271 def __delitem__(self, name):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2272 _option = self._get_option(name)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2273 _section = _option.section
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2274 _name = _option.setting
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2275 self._get_section_options(_section).remove(_name)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2276 del self.options[(_section, _name)]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2277 for _alias in _option.aliases:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2278 del self.options[_alias]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2279
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2280 def items(self):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2281 """Return the list of Option objects, in .ini file order
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2282
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2283 Note that HOME is not included in this list
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2284 because it is builtin pseudo-option, not a real Option
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2285 object loaded from or saved to .ini file.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2286
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2287 """
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2288 return [self.options[(_section, _name)]
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
2289 for _section in self.sections
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
2290 for _name in self._get_section_options(_section)]
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2291
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2292 def keys(self):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2293 """Return the list of "canonical" names of the options
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2294
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2295 Unlike .items(), this list also includes HOME
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2296
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2297 """
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2298 return ["HOME"] + [_option.name for _option in self.items()]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2299
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2300 # .values() is not implemented because i am not sure what should be
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2301 # the values returned from this method: Option instances or config values?
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2302
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2303 # attribute emulation
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2304
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2305 def __setattr__(self, name, value):
5128
4058fc1ec746 replacing depricated has_key references by in to support python 3. Errors reported by python -3 roundup_server. Unit tests test_config test_security pass although test_config is a bit weak in coverage.
John Rouillard <rouilj@ieee.org>
parents: 5117
diff changeset
2306 if (name in self.__dict__) or hasattr(self.__class__, name):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2307 self.__dict__[name] = value
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2308 else:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2309 self._get_option(name).set(value)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2310
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2311 # Note: __getattr__ is not symmetric to __setattr__:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2312 # self.__dict__ lookup is done before calling this method
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2313 def __getattr__(self, name):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2314 return self[name]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2315
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
2316
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2317 class UserConfig(Config):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2318
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2319 """Configuration for user extensions.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2320
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2321 Instances of this class have no predefined configuration layout.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2322 Options are created on the fly for each setting present in the
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2323 config file.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2324
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2325 """
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2326
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2327 def _adjust_options(self, config):
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2328 # config defaults appear in all sections.
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2329 # we'll need to filter them out.
5395
23b8e6067f7c Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5386
diff changeset
2330 defaults = list(config.defaults().keys())
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2331 # see what options are already defined and add missing ones
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2332 preset = [(option.section, option.setting) for option in self.items()]
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2333 for section in config.sections():
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2334 for name in config.options(section):
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2335 if ((section, name) not in preset) \
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
2336 and (name not in defaults):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2337 self.add_option(Option(self, section, name))
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2338
6004
55f5060e0508 flake8 formatting fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents: 5976
diff changeset
2339
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2340 class CoreConfig(Config):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2341
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2342 """Roundup instance configuration.
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2343
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2344 Core config has a predefined layout (see the SETTINGS structure),
6354
b61de764c8cc Remove left over python style config remnant, doc update.
John Rouillard <rouilj@ieee.org>
parents: 6353
diff changeset
2345 two additional attributes:
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2346 detectors:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2347 user-defined configuration for detectors
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2348 ext:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2349 user-defined configuration for extensions
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2350
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2351 """
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2352
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2353 # user configs
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2354 ext = None
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2355 detectors = None
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2356
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
2357 def __init__(self, home_dir=None, settings=None):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
2358 if settings is None:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
2359 settings = {}
3431
26dc6b92ac26 Config, CoreConfig: accept setting overrides in constructor
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 3425
diff changeset
2360 Config.__init__(self, home_dir, layout=SETTINGS, settings=settings)
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2361 # load the config if home_dir given
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2362 if home_dir is None:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2363 self.init_logging()
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2364
4342
94c992852f12 add in-memory hyperdb implementation to speed up testing
Richard Jones <richard@users.sourceforge.net>
parents: 4337
diff changeset
2365 def copy(self):
94c992852f12 add in-memory hyperdb implementation to speed up testing
Richard Jones <richard@users.sourceforge.net>
parents: 4337
diff changeset
2366 new = CoreConfig()
94c992852f12 add in-memory hyperdb implementation to speed up testing
Richard Jones <richard@users.sourceforge.net>
parents: 4337
diff changeset
2367 new.sections = list(self.sections)
94c992852f12 add in-memory hyperdb implementation to speed up testing
Richard Jones <richard@users.sourceforge.net>
parents: 4337
diff changeset
2368 new.section_descriptions = dict(self.section_descriptions)
94c992852f12 add in-memory hyperdb implementation to speed up testing
Richard Jones <richard@users.sourceforge.net>
parents: 4337
diff changeset
2369 new.section_options = dict(self.section_options)
94c992852f12 add in-memory hyperdb implementation to speed up testing
Richard Jones <richard@users.sourceforge.net>
parents: 4337
diff changeset
2370 new.options = dict(self.options)
94c992852f12 add in-memory hyperdb implementation to speed up testing
Richard Jones <richard@users.sourceforge.net>
parents: 4337
diff changeset
2371 return new
94c992852f12 add in-memory hyperdb implementation to speed up testing
Richard Jones <richard@users.sourceforge.net>
parents: 4337
diff changeset
2372
2654
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
2373 def _get_unset_options(self):
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
2374 need_set = Config._get_unset_options(self)
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
2375 # remove MAIL_PASSWORD if MAIL_USER is empty
7811
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2376 if "password" in need_set.get("mail", []) and \
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2377 not self["MAIL_USERNAME"]:
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2378 settings = need_set["mail"]
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2379 settings.remove("password")
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2380 if not settings:
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2381 del need_set["mail"]
2654
eccb8e15a83f implemented section comments;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2649
diff changeset
2382 return need_set
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2383
2770
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2384 def _get_name(self):
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2385 return self["TRACKER_NAME"]
cdf6787ffeda implement getopt().
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2654
diff changeset
2386
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2387 @gen_trace_id()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2388 def _logging_test(self, sinfo, msg="test %(a)s\n%(sinfo)s", args=None):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2389 """Test method for logging formatting.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2390
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2391 Not used in production.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2392 """
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2393 logger = logging.getLogger('roundup')
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2394 if args:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2395 logger.info(msg, *args)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2396 else:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2397 logger.info(msg, extra={"a": "a_var", "sinfo": sinfo})
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2398
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2399 def reset(self):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2400 Config.reset(self)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2401 if self.ext:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2402 self.ext.reset()
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2403 if self.detectors:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2404 self.detectors.reset()
2619
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
2405 self.init_logging()
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
2406
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2407 def gather_callstack(self, keep_full_stack=False):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2408 # Locate logging call in stack
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2409 stack = traceback.extract_stack()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2410 if keep_full_stack:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2411 last_frame_index = len(stack)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2412 else:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2413 for last_frame_index, frame in enumerate(stack):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2414 # Walk from the top of stack looking for
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2415 # "logging" in filename (really
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2416 # filepath). Can't use /logging/ as
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2417 # windows uses \logging\.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2418 #
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2419 # Filtering by looking for "logging" in
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2420 # the filename isn't great.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2421 if "logging" in frame.filename:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2422 break
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2423 if not keep_full_stack:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2424 stack = stack[0:last_frame_index]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2425 return (stack, last_frame_index)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2426
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2427 def context_filter(self, record):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2428 """Add context to record, expand context references in record.msg
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2429 Define pct_char as '%'
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2430 """
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2431
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2432 # This method can be called multiple times on different handlers.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2433 # However it modifies the record on the first call and the changes
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2434 # persist in the record. So we only want to be called once per
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2435 # record.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2436 if hasattr(record, "ROUNDUP_CONTEXT_FILTER_CALLED"):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2437 return True
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2438
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2439 for name, value in get_context_info():
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2440 if not hasattr(record, name):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2441 setattr(record, name, value)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2442 record.pct_char = "%"
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2443 record.ROUNDUP_CONTEXT_FILTER_CALLED = True
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2444
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2445 if hasattr(record, "sinfo"):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2446 # sinfo has to be set via extras argument to logging commands
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2447 # to activate this.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2448 #
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2449 # sinfo value can be:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2450 # non-integer: "", None etc. Print 5 elements of
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2451 # stack before logging call
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2452 # integer N > 0: print N elements of stack before
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2453 # logging call
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2454 # 0: print whole stack before logging call
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2455 # integer N < 0: undocumented print stack starting at
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2456 # extract_stack() below. I.E. do not set bottom of
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2457 # stack to the logging call.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2458 # if |N| is greater than stack height, print whole stack.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2459 stack_height = record.sinfo
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2460 keep_full_stack = False
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2461
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2462 if isinstance(stack_height, int):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2463 if stack_height < 0:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2464 keep_full_stack = True
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2465 stack_height = abs(stack_height)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2466 if stack_height == 0:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2467 # None will set value to actual stack height.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2468 stack_height = None
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2469 else:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2470 stack_height = 5
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2471
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2472 stack, last_frame_index = self.gather_callstack(keep_full_stack)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2473
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2474 if stack_height is None:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2475 stack_height = last_frame_index
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2476 elif stack_height > last_frame_index:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2477 stack_height = last_frame_index # start at frame 0
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2478
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2479 # report the stack info
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2480 record.sinfo = "".join(
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2481 traceback.format_list(
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2482 stack[last_frame_index - stack_height:last_frame_index]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2483 )
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2484 )
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2485
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2486 # if args are present, just return. Logging will
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2487 # expand the arguments.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2488 if record.args:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2489 return True
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2490
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2491 # Since args not present, try formatting msg using
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2492 # named arguments.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2493 try:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2494 record.msg = record.msg % record.__dict__
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2495 except (ValueError, TypeError):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2496 # ValueError: means there is a % sign in the msg
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2497 # somewhere that is not meant to be a format token. So
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2498 # just leave msg unexpanded.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2499 #
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2500 # TypeError - a positional format string is being
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2501 # handled without setting record.args. E.G.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2502 # .info("result is %f")
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2503 # Leave message unexpanded.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2504 pass
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2505 return True
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2506
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2507 def add_logging_context_filter(self):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2508 """Update log record with contextvar values and expand msg
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2509
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2510 The contextvar values are stored as attributes on the log
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2511 record object in record.__dict__. They should not exist
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2512 when this is called. Do not overwrite them if they do exist
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2513 as they can be set in a logger call using::
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2514
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2515 logging.warning("a message", extra = {"trace_id": foo})
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2516
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2517 the extra argument/parameter.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2518
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2519 Attempt to expand msg using the variables in
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2520 record.__dict__. This makes::
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2521
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2522 logging.warning("the URL was: %(trace_reason)s")
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2523
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2524 work and replaces the ``%(trace_reason)s`` token with the value.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2525 Note that you can't use positional params and named params
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2526 together. For example::
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2527
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2528 logging.warning("user = %s and URL was: %(trace_reason)s", user)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2529
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2530 will result in an exception in logging when it formats the
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2531 message.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2532
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2533 Also ``%(pct_char)`` is defined to allow the addition of %
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2534 characters in the format string as bare % chars can't make
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2535 it past the configparser and %% encoded ones run into issue
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2536 with the format verifier.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2537
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2538 Calling a logger (.warning() etc.) with the argument::
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2539
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2540 extra={"sinfo": an_int}
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2541
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2542 will result in a stack trace starting at the logger call
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2543 and going up the stack for `an_int` frames. Using "True"
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2544 in place of `an_int` will print only the call to the logger.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2545
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2546 Note that logging untrusted strings in the msg set by user
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2547 (untrusted) may be an issue. So don't do something like:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2548
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2549 .info("%s" % web_url)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2550
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2551 as web_url could include '%(trace_id)s'. Instead use:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2552
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2553 .info("%(url)s", extra=("url": web_url))
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2554
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2555 Even in the problem case, I think the damage is contained since:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2556
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2557 * data doesn't leak as the log string is not exposed to the
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2558 user.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2559
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2560 * the log string isn't executed or used internally.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2561
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2562 * log formating can raise an exception. But this won't
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2563 affect the application as the exception is swallowed in
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2564 the logging package. The raw message would be printed by
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2565 the fallback logging handler.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2566
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2567 but if it is a concern, make sure user data is added using
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2568 the extra dict when calling one of the logging functions.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2569 """
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2570 loggers = [logging.getLogger(name) for name in
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2571 logging.root.manager.loggerDict]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2572 # append the root logger as it is not listed in loggerDict
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2573 loggers.append(logging.getLogger())
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2574 for logger in loggers:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2575 for hdlr in logger.handlers:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2576 hdlr.addFilter(self.context_filter)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2577
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2578 def load_config_dict_from_json_file(self, filename):
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2579 import json
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2580 comment_re = re.compile(
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
2581 r"""^\s*//#.* # comment at beginning of line possibly indented.
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2582 | # or
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
2583 ^(.*)\s\s\s\//.* # comment char preceeded by at least three spaces.
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2584 """, re.VERBOSE)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2585
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2586 config_list = []
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2587 with open(filename) as config_file:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2588 for line in config_file:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2589 match = comment_re.search(line)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2590 if match:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2591 if match.lastindex:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2592 config_list.append(match.group(1) + "\n")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2593 else:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2594 # insert blank line for comment line to
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2595 # keep line numbers in sync.
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2596 config_list.append("\n")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2597 continue
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2598 config_list.append(line)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2599
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2600 try:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2601 config_dict = json.loads("".join(config_list))
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2602 except json.decoder.JSONDecodeError as e:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2603 error_at_doc_line = e.lineno
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2604 # subtract 1 - zero index on config_list
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2605 # remove '\n' for display
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2606 line = config_list[error_at_doc_line - 1][:-1]
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2607
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2608 hint = ""
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
2609 if line.find('//') != -1:
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
2610 hint = "\nMaybe bad inline comment, 3 spaces needed before //."
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2611
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2612 raise LoggingConfigError(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2613 'Error parsing json logging dict (%(file)s) '
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2614 'near \n\n %(line)s\n\n'
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2615 '%(msg)s: line %(lineno)s column %(colno)s.%(hint)s' %
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2616 {"file": filename,
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2617 "line": line,
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2618 "msg": e.msg,
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2619 "lineno": error_at_doc_line,
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2620 "colno": e.colno,
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2621 "hint": hint},
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2622 config_file=self.filepath,
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2623 source="json.loads"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2624 )
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2625
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2626 return config_dict
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 8314
diff changeset
2627
2619
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
2628 def init_logging(self):
4b4ca3bd086b added logging support;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2618
diff changeset
2629 _file = self["LOGGING_CONFIG"]
8434
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2630 if _file and os.path.isfile(_file):
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2631 if _file.endswith(".ini"):
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2632 logging.config.fileConfig(
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2633 _file,
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2634 disable_existing_loggers=self["LOGGING_DISABLE_LOGGERS"])
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2635 elif _file.endswith(".json"):
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2636 config_dict = self.load_config_dict_from_json_file(_file)
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2637 try:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2638 logging.config.dictConfig(config_dict)
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2639 except ValueError as e:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2640 # docs say these exceptions:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2641 # ValueError, TypeError, AttributeError, ImportError
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2642 # could be raised, but
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2643 # looking through the code, it looks like
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2644 # configure() maps all exceptions (including
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2645 # ImportError, TypeError) raised by functions to
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2646 # ValueError.
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2647 context = "No additional information available."
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2648 if hasattr(e, '__context__') and e.__context__:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2649 # get additional error info. E.G. if INFO
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2650 # is replaced by MANGO, context is:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2651 # ValueError("Unknown level: 'MANGO'")
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2652 # while str(e) is "Unable to configure handler 'access'"
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2653 context = e.__context__
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2654
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2655 raise LoggingConfigError(
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2656 'Error loading logging dict from %(file)s.\n'
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2657 '%(msg)s\n%(context)s\n' % {
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2658 "file": _file,
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2659 "msg": type(e).__name__ + ": " + str(e),
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2660 "context": context
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2661 },
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2662 config_file=self.filepath,
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2663 source="dictConfig"
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2664 )
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2665 else:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2666 raise OptionValueError(
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2667 self.options['LOGGING_CONFIG'],
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2668 _file,
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2669 "Unable to load logging config file. "
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2670 "File extension must be '.ini' or '.json'.\n"
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2671 )
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2672
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2673 self.add_logging_context_filter()
3155
57b60bda9473 Python 2.3 minimum version - bye bye roundup.rlog, you had a short life.
Richard Jones <richard@users.sourceforge.net>
parents: 3099
diff changeset
2674 return
57b60bda9473 Python 2.3 minimum version - bye bye roundup.rlog, you had a short life.
Richard Jones <richard@users.sourceforge.net>
parents: 3099
diff changeset
2675
8434
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2676 if _file:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2677 raise OptionValueError(self.options['LOGGING_CONFIG'],
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2678 _file,
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
2679 "Unable to find logging config file.")
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2680
3155
57b60bda9473 Python 2.3 minimum version - bye bye roundup.rlog, you had a short life.
Richard Jones <richard@users.sourceforge.net>
parents: 3099
diff changeset
2681 _file = self["LOGGING_FILENAME"]
4411
39660ba47b7c - No longer use the root logger, use a logger with prefix "roundup"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4405
diff changeset
2682 # set file & level on the roundup logger
39660ba47b7c - No longer use the root logger, use a logger with prefix "roundup"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4405
diff changeset
2683 logger = logging.getLogger('roundup')
7811
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2684 hdlr = logging.FileHandler(_file) if _file else \
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2685 logging.StreamHandler(sys.stdout)
a4b71f16c264 chore(refactor): use 'with open'; if ternarys; unnested if statements
John Rouillard <rouilj@ieee.org>
parents: 7810
diff changeset
2686
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
2687 formatter = logging.Formatter(self["LOGGING_FORMAT"])
3155
57b60bda9473 Python 2.3 minimum version - bye bye roundup.rlog, you had a short life.
Richard Jones <richard@users.sourceforge.net>
parents: 3099
diff changeset
2688 hdlr.setFormatter(formatter)
57b60bda9473 Python 2.3 minimum version - bye bye roundup.rlog, you had a short life.
Richard Jones <richard@users.sourceforge.net>
parents: 3099
diff changeset
2689 # no logging API to remove all existing handlers!?!
4337
9225a37fbeae Fix file handle leak in some web interfaces with logging turned on
Richard Jones <richard@users.sourceforge.net>
parents: 4255
diff changeset
2690 for h in logger.handlers:
9225a37fbeae Fix file handle leak in some web interfaces with logging turned on
Richard Jones <richard@users.sourceforge.net>
parents: 4255
diff changeset
2691 h.close()
9225a37fbeae Fix file handle leak in some web interfaces with logging turned on
Richard Jones <richard@users.sourceforge.net>
parents: 4255
diff changeset
2692 logger.removeHandler(hdlr)
3155
57b60bda9473 Python 2.3 minimum version - bye bye roundup.rlog, you had a short life.
Richard Jones <richard@users.sourceforge.net>
parents: 3099
diff changeset
2693 logger.handlers = [hdlr]
5424
fd0481aa17b8 Python 3 preparation: avoid logging._levelNames.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5416
diff changeset
2694 logger.setLevel(self["LOGGING_LEVEL"] or "ERROR")
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2695 if 'pytest' not in sys.modules:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2696 # logger.propatgate is True by default. This is
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2697 # needed so that pytest caplog code will work. In
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2698 # production leaving it set to True relogs everything
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2699 # using the root logger with logging BASIC_FORMAT:
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2700 # "%(level)s:%(name)s:%(message)s
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2701 logger.propagate = False
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2702
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
2703 self.add_logging_context_filter()
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2704
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2705 def validator(self, options):
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2706 """ Validate options once all options are loaded.
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2707
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2708 Used to validate settings when options are dependent
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2709 on each other. E.G. indexer_language can only be
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2710 validated if xapian indexer is used.
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2711 """
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2712
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
2713 for option in self.option_validators:
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
2714 # validate() should throw an exception if there is an issue.
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
2715 options[option].validate(options)
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6562
diff changeset
2716
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2717 def load(self, home_dir):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2718 """Load configuration from path designated by home_dir argument"""
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2719 if os.path.isfile(os.path.join(home_dir, self.INI_FILE)):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2720 self.load_ini(home_dir)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2721 else:
6300
778a9f455067 Remove old code import imp, old style trackers db/backend_name
John Rouillard <rouilj@ieee.org>
parents: 6277
diff changeset
2722 raise NoConfigError(home_dir)
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2723
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2724 # validator does inter-setting validation checks.
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2725 # when there are dependencies between options.
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2726 self.validator(self.options)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6355
diff changeset
2727
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2728 self.init_logging()
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2729 self.ext = UserConfig(os.path.join(home_dir, "extensions"))
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2730 self.detectors = UserConfig(os.path.join(home_dir, "detectors"))
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2731
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2732 def load_ini(self, home_dir, defaults=None):
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2733 """Set options from config.ini file in given home_dir directory"""
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2734 config_defaults = {"TRACKER_HOME": home_dir}
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2735 if defaults:
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2736 config_defaults.update(defaults)
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2737 Config.load_ini(self, home_dir, config_defaults)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2738
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2739 # in this config, HOME is also known as TRACKER_HOME
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2740 def __getitem__(self, name):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2741 if name == "TRACKER_HOME":
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2742 return self.HOME
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2743 else:
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2744 return Config.__getitem__(self, name)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2745
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2746 def __setitem__(self, name, value):
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2747 if name == "TRACKER_HOME":
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2748 self.HOME = value
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2749 else:
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2750 self._get_option(name).set(value)
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2751
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2752 def __setattr__(self, name, value):
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2753 if name == "TRACKER_HOME":
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2754 self.__dict__["HOME"] = value
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2755 else:
2646
fd7b2fc1eb28 Config is now base class for all configurations...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2637
diff changeset
2756 Config.__setattr__(self, name, value)
2618
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2757
8b08558e30a0 Roundup Issue Tracker configuration support
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2758 # vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/