This commit is contained in:
winlu 2014-05-06 06:06:30 +00:00
commit 600809f8cd
4 changed files with 57 additions and 42 deletions

View file

@ -107,13 +107,13 @@ Setting name (followed by default value, if any)
to the default values for this setting, you'll need to
include them explicitly and enumerate the full list of
desired Markdown extensions.)
``OUTPUT_PATH = 'output/'`` Where to output the generated files.
``PATH = None`` Path to content directory to be processed by Pelican.
``PAGE_DIR = 'pages'`` Directory to look at for pages, relative to `PATH`.
``PAGE_EXCLUDES = ()`` A list of directories to exclude when looking for pages.
``ARTICLE_DIR = ''`` Directory to look at for articles, relative to `PATH`.
``ARTICLE_EXCLUDES = ('pages',)`` A list of directories to exclude when looking for articles.
``OUTPUT_SOURCES = False`` Set to True if you want to copy the articles and pages in their
``OUTPUT_PATH = ('output/')`` Where to output the generated files.
``PATH = (None)`` Path to content directory to be processed by Pelican.
``PAGE_PATHS = (['pages'])`` Directories to look at for pages, relative to `PATH`.
``PAGE_EXCLUDES = (())`` A list of directories to exclude when looking for pages.
``ARTICLE_PATHS = ([''])`` Directories to look at for articles, relative to `PATH`.
``ARTICLE_EXCLUDES = (('pages',))`` A list of directories to exclude when looking for articles.
``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
specified ``OUTPUT_PATH``.
``OUTPUT_SOURCES_EXTENSION = '.text'`` Controls the extension that will be used by the SourcesGenerator.

View file

@ -110,29 +110,31 @@ class Generator(object):
return True
return False
def get_files(self, path, exclude=[], extensions=None):
def get_files(self, paths, exclude=[], extensions=None):
"""Return a list of files to use, based on rules
:param path: the path to search (relative to self.path)
:param paths: the list pf paths to search (relative to self.path)
:param exclude: the list of path to exclude
:param extensions: the list of allowed extensions (if False, all
extensions are allowed)
"""
files = []
root = os.path.join(self.path, path)
if os.path.isdir(root):
for dirpath, dirs, temp_files in os.walk(root, followlinks=True):
for e in exclude:
if e in dirs:
dirs.remove(e)
reldir = os.path.relpath(dirpath, self.path)
for f in temp_files:
fp = os.path.join(reldir, f)
if self._include_path(fp, extensions):
files.append(fp)
elif os.path.exists(root) and self._include_path(path, extensions):
files.append(path) # can't walk non-directories
files = []
for path in paths:
root = os.path.join(self.path, path)
if os.path.isdir(root):
for dirpath, dirs, temp_files in os.walk(root, followlinks=True):
for e in exclude:
if e in dirs:
dirs.remove(e)
reldir = os.path.relpath(dirpath, self.path)
for f in temp_files:
fp = os.path.join(reldir, f)
if self._include_path(fp, extensions):
files.append(fp)
elif os.path.exists(root) and self._include_path(path, extensions):
files.append(path) # can't walk non-directories
return files
def add_source_path(self, content):
@ -462,7 +464,7 @@ class ArticlesGenerator(CachingGenerator):
all_articles = []
all_drafts = []
for f in self.get_files(
self.settings['ARTICLE_DIR'],
self.settings['ARTICLE_PATHS'],
exclude=self.settings['ARTICLE_EXCLUDES']):
article = self.get_cached_data(f, None)
if article is None:
@ -586,7 +588,7 @@ class PagesGenerator(CachingGenerator):
all_pages = []
hidden_pages = []
for f in self.get_files(
self.settings['PAGE_DIR'],
self.settings['PAGE_PATHS'],
exclude=self.settings['PAGE_EXCLUDES']):
page = self.get_cached_data(f, None)
if page is None:
@ -661,19 +663,17 @@ class StaticGenerator(Generator):
def generate_context(self):
self.staticfiles = []
# walk static paths
for static_path in self.settings['STATIC_PATHS']:
for f in self.get_files(
static_path, extensions=False):
static = self.readers.read_file(
base_path=self.path, path=f, content_class=Static,
fmt='static', context=self.context,
preread_signal=signals.static_generator_preread,
preread_sender=self,
context_signal=signals.static_generator_context,
context_sender=self)
self.staticfiles.append(static)
self.add_source_path(static)
for f in self.get_files(
self.settings['STATIC_PATHS'], extensions=False):
static = self.readers.read_file(
base_path=self.path, path=f, content_class=Static,
fmt='static', context=self.context,
preread_signal=signals.static_generator_preread,
preread_sender=self,
context_signal=signals.static_generator_context,
context_sender=self)
self.staticfiles.append(static)
self.add_source_path(static)
self._update_context(('staticfiles',))
signals.static_generator_finalized.send(self)

View file

@ -29,9 +29,9 @@ DEFAULT_THEME = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'themes', 'notmyidea')
DEFAULT_CONFIG = {
'PATH': os.curdir,
'ARTICLE_DIR': '',
'ARTICLE_PATHS': [''],
'ARTICLE_EXCLUDES': ('pages',),
'PAGE_DIR': 'pages',
'PAGE_PATHS': ['pages'],
'PAGE_EXCLUDES': (),
'THEME': DEFAULT_THEME,
'OUTPUT_PATH': 'output',
@ -311,6 +311,15 @@ def configure_settings(settings):
key=lambda r: r[0],
)
# move {ARTICLE,PAGE}_DIR -> {ARTICLE,PAGE}_PATHS
for key in ['ARTICLE', 'PAGE']:
old_key = key + '_DIR'
new_key = key + '_PATHS'
if old_key in settings:
logger.warning('Deprecated {}, moving it to {}'.format(
old_key, new_key))
settings[new_key] = [settings[old_key]] # also make a list
# Save people from accidentally setting a string rather than a list
path_keys = (
'ARTICLE_EXCLUDES',
@ -324,6 +333,8 @@ def configure_settings(settings):
'PLUGINS',
'STATIC_PATHS',
'THEME_STATIC_PATHS',
'ARTICLE_PATHS',
'PAGE_PATHS',
)
for PATH_KEY in filter(lambda k: k in settings, path_keys):
if isinstance(settings[PATH_KEY], six.string_types):
@ -336,6 +347,10 @@ def configure_settings(settings):
('LESS_GENERATOR', 'the Webassets plugin', None),
('FILES_TO_COPY', 'STATIC_PATHS and EXTRA_PATH_METADATA',
'https://github.com/getpelican/pelican/blob/master/docs/settings.rst#path-metadata'),
('ARTICLE_DIR', 'ARTICLE_PATHS',
'https://github.com/getpelican/pelican/blob/master/docs/settings.rst'),
('PAGE_DIR', 'PAGE_PATHS',
'https://github.com/getpelican/pelican/blob/master/docs/settings.rst'),
]:
if old in settings:
message = 'The {} setting has been removed in favor of {}'.format(

View file

@ -372,8 +372,8 @@ class TestPageGenerator(unittest.TestCase):
def test_generate_context(self):
settings = get_settings(filenames={})
settings['PAGE_DIR'] = 'TestPages' # relative to CUR_DIR
settings['CACHE_PATH'] = self.temp_cache
settings['PAGE_PATHS'] = ['TestPages'] # relative to CUR_DIR
settings['CACHE_DIRECTORY'] = self.temp_cache
settings['DEFAULT_DATE'] = (1970, 1, 1)
generator = PagesGenerator(