Load a default-named configuration file if present

This commit is contained in:
Will Dowling 2013-03-25 10:39:22 +00:00
commit b06fbd78cc
2 changed files with 16 additions and 2 deletions

View file

@ -17,7 +17,7 @@ from pelican.generators import (ArticlesGenerator, PagesGenerator,
from pelican.log import init
from pelican.settings import read_settings
from pelican.utils import (clean_output_dir, files_changed, file_changed,
NoFilesError)
file_exists, NoFilesError)
from pelican.writers import Writer
__major__ = 3
@ -25,6 +25,8 @@ __minor__ = 2
__micro__ = 0
__version__ = "{0}.{1}.{2}".format(__major__, __minor__, __micro__)
DEFAULT_CONFIG_NAME = 'pelicanconf.py'
logger = logging.getLogger(__name__)
@ -269,7 +271,11 @@ def get_config(args):
def get_instance(args):
settings = read_settings(args.settings, override=get_config(args))
config_file = args.settings
if config_file is None and file_exists(DEFAULT_CONFIG_NAME):
config_file = DEFAULT_CONFIG_NAME
settings = read_settings(config_file, override=get_config(args))
cls = settings.get('PELICAN_CLASS')
if isinstance(cls, six.string_types):

View file

@ -268,6 +268,14 @@ def copy(path, source, destination, destination_path=None, overwrite=False):
logger.warning('skipped copy %s to %s' % (source_, destination_))
def file_exists(path):
"""Checks path exists and is a file
:param path: the path to be checked
"""
return os.path.exists(path) and os.path.isfile(path)
def clean_output_dir(path):
"""Remove all the files from the output directory"""