Commit f9e08a39 authored by Barry Warsaw's avatar Barry Warsaw

* The `mailman.cfg` configuration file will now automatically be detected if

   it exists in an `etc` directory which is a sibling of argv0.
parent b6fdf26f
......@@ -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
......
......@@ -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)
......
......@@ -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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment