From b06fbd78cc6093d73fea8f11bc3610a097d5b1d7 Mon Sep 17 00:00:00 2001 From: Will Dowling Date: Mon, 25 Mar 2013 10:39:22 +0000 Subject: [PATCH 1/4] Load a default-named configuration file if present --- pelican/__init__.py | 10 ++++++++-- pelican/utils.py | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index a2bdefa4..a57ecb4c 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -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): diff --git a/pelican/utils.py b/pelican/utils.py index 3ae88402..36d2995c 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -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""" From 608e398386b88476facfa86632d95b6b1da0bf62 Mon Sep 17 00:00:00 2001 From: Will Dowling Date: Mon, 25 Mar 2013 10:45:43 +0000 Subject: [PATCH 2/4] Removing utils.file_exists and replacing with os.path.isfile --- pelican/__init__.py | 4 ++-- pelican/utils.py | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index a57ecb4c..3be8ceb8 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -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, - file_exists, NoFilesError) + NoFilesError) from pelican.writers import Writer __major__ = 3 @@ -272,7 +272,7 @@ def get_config(args): def get_instance(args): config_file = args.settings - if config_file is None and file_exists(DEFAULT_CONFIG_NAME): + if config_file is None and os.path.isfile(DEFAULT_CONFIG_NAME): config_file = DEFAULT_CONFIG_NAME settings = read_settings(config_file, override=get_config(args)) diff --git a/pelican/utils.py b/pelican/utils.py index 36d2995c..3ae88402 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -268,14 +268,6 @@ 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""" From 0d43017704ebab869f635277a05f30bd43951588 Mon Sep 17 00:00:00 2001 From: Will Dowling Date: Tue, 26 Mar 2013 10:37:37 +0800 Subject: [PATCH 3/4] Adding information to argparse help --- pelican/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 3be8ceb8..61638727 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -222,7 +222,8 @@ def parse_arguments(): 'them separated by commas.') parser.add_argument('-s', '--settings', dest='settings', - help='The settings of the application.') + help='The settings of the application, this defaults to {0} if a file, ' + 'exists with this name.'.format(DEFAULT_CONFIG_NAME)) parser.add_argument('-d', '--delete-output-directory', dest='delete_outputdir', From de6973977403e2ccf75de0b91704bd60f38361df Mon Sep 17 00:00:00 2001 From: Will Dowling Date: Tue, 26 Mar 2013 02:42:11 +0000 Subject: [PATCH 4/4] Fixing help text --- pelican/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 61638727..aa283f11 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -222,8 +222,8 @@ def parse_arguments(): 'them separated by commas.') parser.add_argument('-s', '--settings', dest='settings', - help='The settings of the application, this defaults to {0} if a file, ' - 'exists with this name.'.format(DEFAULT_CONFIG_NAME)) + help='The settings of the application, this is automatically set to ' + '{0} if a file exists with this name.'.format(DEFAULT_CONFIG_NAME)) parser.add_argument('-d', '--delete-output-directory', dest='delete_outputdir',