diff options
| author | Barry Warsaw | 2015-01-02 17:16:51 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2015-01-02 17:16:51 -0500 |
| commit | f3eb8f655dde84eb2111b1cbcd5249e1bfe3c340 (patch) | |
| tree | bc2e79653823ff9b02b9bba10e87da98bb701395 /src/mailman | |
| parent | 3b97444c92f1178cc997024081f5239773048f42 (diff) | |
| download | mailman-f3eb8f655dde84eb2111b1cbcd5249e1bfe3c340.tar.gz mailman-f3eb8f655dde84eb2111b1cbcd5249e1bfe3c340.tar.zst mailman-f3eb8f655dde84eb2111b1cbcd5249e1bfe3c340.zip | |
Add $cfg_file as an expansion variable for relative paths in the mailman.cfg
file, and improve the error message when an expansion loop is found. With the
`[mailman]layout: dev` path setting, put $var_dir relative to the mailman.cfg
file.
Diffstat (limited to 'src/mailman')
| -rw-r--r-- | src/mailman/config/config.py | 22 | ||||
| -rw-r--r-- | src/mailman/config/mailman.cfg | 2 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/mailman/config/config.py b/src/mailman/config/config.py index e7d8b6b17..1aab4a82a 100644 --- a/src/mailman/config/config.py +++ b/src/mailman/config/config.py @@ -46,6 +46,8 @@ from zope.interface import implementer SPACE = ' ' +SPACERS = '\n' + MAILMAN_CFG_TEMPLATE = """\ # AUTOMATICALLY GENERATED BY MAILMAN ON {} @@ -185,26 +187,32 @@ class Configuration: lock_file = category.lock_file, pid_file = category.pid_file, ) + # Add the path to the .cfg file, if one was given on the command line. + if self.filename is not None: + substitutions['cfg_file'] = self.filename # Now, perform substitutions recursively until there are no more # variables with $-vars in them, or until substitutions are not # helping any more. last_dollar_count = 0 while True: + expandables = [] # Mutate the dictionary during iteration. - dollar_count = 0 - for key in substitutions.keys(): + for key in substitutions: raw_value = substitutions[key] value = Template(raw_value).safe_substitute(substitutions) if '$' in value: # Still more work to do. - dollar_count += 1 + expandables.append((key, value)) substitutions[key] = value - if dollar_count == 0: + if len(expandables) == 0: break - if dollar_count == last_dollar_count: - print('Path expansion infloop detected', file=sys.stderr) + if len(expandables) == last_dollar_count: + print('Path expansion infloop detected:\n', + SPACERS.join('\t{}: {}'.format(key, value) + for key, value in sorted(expandables)), + file=sys.stderr) sys.exit(1) - last_dollar_count = dollar_count + last_dollar_count = len(expandables) # Ensure that all paths are normalized and made absolute. Handle the # few special cases first. Most of these are due to backward # compatibility. diff --git a/src/mailman/config/mailman.cfg b/src/mailman/config/mailman.cfg index 24e81ec91..80da56ddc 100644 --- a/src/mailman/config/mailman.cfg +++ b/src/mailman/config/mailman.cfg @@ -25,7 +25,7 @@ [paths.dev] # Convenient development layout where everything is put in the current # directory. -var_dir: var +var_dir: $cfg_file/../.. [paths.fhs] # Filesystem Hiearchy Standard 2.3 |
