Messages with Subject: Re: only are now processed correctly.
[mailman.git] / port_me / show_config.py
blob31a60b068147707994dfc414fb0a6763f3634467
1 # Copyright (C) 2006-2019 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
8 # any later version.
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 import re
19 import sys
20 import pprint
21 import optparse
23 from mailman.configuration import config
24 from mailman.core.i18n import _
25 from mailman.version import MAILMAN_VERSION
28 # List of names never to show even if --verbose
29 NEVER_SHOW = ['__builtins__', '__doc__']
33 def parseargs():
34 parser = optparse.OptionParser(version=MAILMAN_VERSION,
35 usage=_("""\
36 %%prog [options] [pattern ...]
38 Show the values of various Defaults.py/mailman.cfg variables.
39 If one or more patterns are given, show only those variables
40 whose names match a pattern"""))
41 parser.add_option('-v', '--verbose',
42 default=False, action='store_true',
43 help=_(
44 "Show all configuration names, not just 'settings'."))
45 parser.add_option('-i', '--ignorecase',
46 default=False, action='store_true',
47 help=_("Match patterns case-insensitively."))
48 parser.add_option('-C', '--config',
49 help=_('Alternative configuration file to use'))
50 opts, args = parser.parse_args()
51 return parser, opts, args
55 def main():
56 parser, opts, args = parseargs()
58 patterns = []
59 if opts.ignorecase:
60 flag = re.IGNORECASE
61 else:
62 flag = 0
63 for pattern in args:
64 patterns.append(re.compile(pattern, flag))
66 pp = pprint.PrettyPrinter(indent=4)
67 config.load(opts.config)
68 names = config.__dict__.keys()
69 names.sort()
70 for name in names:
71 if name in NEVER_SHOW:
72 continue
73 if not opts.verbose:
74 if name.startswith('_') or re.search('[a-z]', name):
75 continue
76 if patterns:
77 hit = False
78 for pattern in patterns:
79 if pattern.search(name):
80 hit = True
81 break
82 if not hit:
83 continue
84 value = config.__dict__[name]
85 if isinstance(value, str):
86 if re.search('\n', value):
87 print '%s = """%s"""' %(name, value)
88 else:
89 print "%s = '%s'" % (name, value)
90 else:
91 print '%s = ' % name,
92 pp.pprint(value)
96 if __name__ == '__main__':
97 main()