Add {PAGE,ARTICLE}_PATHS to {ARTICLE,PAGE}_EXCLUDES automatically

This makes it easier for someone to change PAGE_PATHS without the
need to change ARTICLE_EXCLUDES accordingly.
This commit is contained in:
Ondrej Grover 2014-05-14 14:30:21 +02:00
commit 6aa0e4346d
3 changed files with 22 additions and 5 deletions

View file

@ -112,9 +112,11 @@ Setting name (followed by default value, if any)
and content path is not specified via an argument to the ``pelican`` and content path is not specified via an argument to the ``pelican``
command, Pelican will use the current working directory. command, Pelican will use the current working directory.
``PAGE_PATHS = ['pages']`` A list of directories to look at for pages, relative to ``PATH``. ``PAGE_PATHS = ['pages']`` A list of directories to look at for pages, relative to ``PATH``.
``PAGE_EXCLUDES = ()`` A list of directories to exclude when looking for pages. ``PAGE_EXCLUDES = []`` A list of directories to exclude when looking for pages in addition
to ``ARTICLE_PATHS``.
``ARTICLE_PATHS = ['']`` A list of directories to look at for articles, relative to ``PATH``. ``ARTICLE_PATHS = ['']`` A list of directories to look at for articles, relative to ``PATH``.
``ARTICLE_EXCLUDES = ('pages',)`` A list of directories to exclude when looking for articles. ``ARTICLE_EXCLUDES = []`` A list of directories to exclude when looking for articles in addition
to ``PAGE_PATHS``.
``OUTPUT_SOURCES = False`` Set to True if you want to copy the articles and pages in their ``OUTPUT_SOURCES = False`` Set to True if you want to copy the articles and pages in their
original format (e.g. Markdown or reStructuredText) to the original format (e.g. Markdown or reStructuredText) to the
specified ``OUTPUT_PATH``. specified ``OUTPUT_PATH``.

View file

@ -30,9 +30,9 @@ DEFAULT_THEME = os.path.join(os.path.dirname(os.path.abspath(__file__)),
DEFAULT_CONFIG = { DEFAULT_CONFIG = {
'PATH': os.curdir, 'PATH': os.curdir,
'ARTICLE_PATHS': [''], 'ARTICLE_PATHS': [''],
'ARTICLE_EXCLUDES': ('pages',), 'ARTICLE_EXCLUDES': [],
'PAGE_PATHS': ['pages'], 'PAGE_PATHS': ['pages'],
'PAGE_EXCLUDES': (), 'PAGE_EXCLUDES': [],
'THEME': DEFAULT_THEME, 'THEME': DEFAULT_THEME,
'OUTPUT_PATH': 'output', 'OUTPUT_PATH': 'output',
'READERS': {}, 'READERS': {},
@ -348,6 +348,18 @@ def configure_settings(settings):
% PATH_KEY) % PATH_KEY)
settings[PATH_KEY] = DEFAULT_CONFIG[PATH_KEY] settings[PATH_KEY] = DEFAULT_CONFIG[PATH_KEY]
# Add {PAGE,ARTICLE}_PATHS to {ARTICLE,PAGE}_EXCLUDES
mutually_exclusive = ('ARTICLE', 'PAGE')
for type_1, type_2 in [mutually_exclusive, mutually_exclusive[::-1]]:
try:
includes = settings[type_1 + '_PATHS']
excludes = settings[type_2 + '_EXCLUDES']
for path in includes:
if path not in excludes:
excludes.append(path)
except KeyError:
continue # setting not specified, nothing to do
for old, new, doc in [ for old, new, doc in [
('LESS_GENERATOR', 'the Webassets plugin', None), ('LESS_GENERATOR', 'the Webassets plugin', None),
('FILES_TO_COPY', 'STATIC_PATHS and EXTRA_PATH_METADATA', ('FILES_TO_COPY', 'STATIC_PATHS and EXTRA_PATH_METADATA',

View file

@ -43,7 +43,10 @@ class TestSettingsConfiguration(unittest.TestCase):
# Providing no file should return the default values. # Providing no file should return the default values.
settings = read_settings(None) settings = read_settings(None)
expected = copy.deepcopy(DEFAULT_CONFIG) expected = copy.deepcopy(DEFAULT_CONFIG)
expected['FEED_DOMAIN'] = '' # Added by configure settings # Added by configure settings
expected['FEED_DOMAIN'] = ''
expected['ARTICLE_EXCLUDES'] = ['pages']
expected['PAGE_EXCLUDES'] = ['']
self.maxDiff = None self.maxDiff = None
self.assertDictEqual(settings, expected) self.assertDictEqual(settings, expected)