diff options
| author | Barry Warsaw | 2012-02-27 10:52:12 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2012-02-27 10:52:12 -0500 |
| commit | f9e08a392daa5e7e5270a2cab4fce9723a6811b5 (patch) | |
| tree | 4324f12d8436606edf1e35acc02a1f4216b7e109 | |
| parent | b6fdf26f8003dd8441d86ffc23666efce0f92c34 (diff) | |
| download | mailman-f9e08a392daa5e7e5270a2cab4fce9723a6811b5.tar.gz mailman-f9e08a392daa5e7e5270a2cab4fce9723a6811b5.tar.zst mailman-f9e08a392daa5e7e5270a2cab4fce9723a6811b5.zip | |
| -rw-r--r-- | src/mailman/core/initialize.py | 15 | ||||
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 2 | ||||
| -rw-r--r-- | src/mailman/tests/test_configfile.py | 34 |
3 files changed, 45 insertions, 6 deletions
diff --git a/src/mailman/core/initialize.py b/src/mailman/core/initialize.py index 8339eb825..721877056 100644 --- a/src/mailman/core/initialize.py +++ b/src/mailman/core/initialize.py @@ -37,6 +37,7 @@ __all__ = [ import os +import sys from pkg_resources import resource_string from zope.configuration import xmlconfig @@ -63,19 +64,25 @@ def search_for_configuration_file(): config_path = os.getenv('MAILMAN_CONFIG_FILE') # Both None and the empty string are considered "missing". if config_path and os.path.exists(config_path): - return config_path + return os.path.abspath(config_path) # ./mailman.cfg config_path = os.path.abspath('mailman.cfg') if os.path.exists(config_path): - return config_path + return os.path.abspath(config_path) # ~/.mailman.cfg config_path = os.path.join(os.getenv('HOME'), '.mailman.cfg') if os.path.exists(config_path): - return config_path + return os.path.abspath(config_path) # /etc/mailman.cfg config_path = '/etc/mailman.cfg' if os.path.exists(config_path): - return config_path + return os.path.abspath(config_path) + # $argv0/../../etc/mailman.cfg + bindir = os.path.dirname(sys.argv[0]) + parent = os.path.dirname(bindir) + config_path = os.path.join(parent, 'etc', 'mailman.cfg') + if os.path.exists(config_path): + return os.path.abspath(config_path) # Are there any others we should search by default? return None diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 528009ef6..1370c2d9b 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -45,6 +45,8 @@ Interfaces Commands -------- + * The `mailman.cfg` configuration file will now automatically be detected if + it exists in an `etc` directory which is a sibling of argv0. * `bin/mailman shell` is an alias for `withlist`. * The `confirm` email command now properly handles `Re:`-like prefixes, even if they contain non-ASCII characters. (LP: #685261) diff --git a/src/mailman/tests/test_configfile.py b/src/mailman/tests/test_configfile.py index ce996e061..67e7fd35a 100644 --- a/src/mailman/tests/test_configfile.py +++ b/src/mailman/tests/test_configfile.py @@ -25,6 +25,7 @@ __all__ = [ import os +import sys import shutil import tempfile import unittest @@ -40,8 +41,10 @@ from mailman.core.initialize import search_for_configuration_file def fakedirs(path): """Create and clean up a directory hierarchy.""" os.makedirs(path) - yield - shutil.rmtree(path) + try: + yield + finally: + shutil.rmtree(path) @contextmanager @@ -69,6 +72,17 @@ def chdir(new_cwd): os.chdir(old_cwd) +@contextmanager +def argv0(new_argv0): + """Change argv0, then back again.""" + old_argv0 = sys.argv[0] + sys.argv[0] = new_argv0 + try: + yield + finally: + sys.argv[0] = old_argv0 + + class TestConfigFileBase(unittest.TestCase): """Common test infrastructure.""" @@ -179,3 +193,19 @@ class TestConfigFileSearchWithChroot(TestConfigFileBase): with open(os.path.join(fake_testdir, 'mailman.cfg'), 'w') as fp: print >> fp, '# Fake mailman.cfg file' self.assertEqual(search_for_configuration_file(), config_file) + + def test_sibling_directory(self): + # Test $argv0/../../etc/mailman.cfg + fake_root = '/usr/local/mm3' + fake_testdir = self._make_fake(fake_root) + config_file = os.path.join(fake_testdir, 'etc', 'mailman.cfg') + fake_config_file = os.path.join(fake_root, 'etc', 'mailman.cfg') + fake_argv0 = os.path.join(fake_root, 'bin', 'mailman') + with fakedirs(fake_testdir): + with argv0(fake_argv0): + os.mkdir(os.path.dirname(config_file)) + # Write a mostly empty configuration file. + with open(config_file, 'w') as fp: + print >> fp, '# Fake mailman.cfg file' + self.assertEqual(search_for_configuration_file(), + fake_config_file) |
