mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
More pep8 fixes and refactor the check for old settings.
This commit is contained in:
parent
18e6ec9f02
commit
fb4b894b77
1 changed files with 60 additions and 67 deletions
|
|
@ -31,6 +31,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Pelican(object):
|
class Pelican(object):
|
||||||
|
|
||||||
def __init__(self, settings):
|
def __init__(self, settings):
|
||||||
"""
|
"""
|
||||||
Pelican initialisation, performs some checks on the environment before
|
Pelican initialisation, performs some checks on the environment before
|
||||||
|
|
@ -67,9 +68,11 @@ class Pelican(object):
|
||||||
if isinstance(plugin, six.string_types):
|
if isinstance(plugin, six.string_types):
|
||||||
logger.debug("Loading plugin `{0}`".format(plugin))
|
logger.debug("Loading plugin `{0}`".format(plugin))
|
||||||
try:
|
try:
|
||||||
plugin = __import__(plugin, globals(), locals(), str('module'))
|
plugin = __import__(plugin, globals(), locals(),
|
||||||
|
str('module'))
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
logger.error("Can't find plugin `{0}`: {1}".format(plugin, e))
|
logger.error(
|
||||||
|
"Can't find plugin `{0}`: {1}".format(plugin, e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logger.debug("Registering plugin `{0}`".format(plugin.__name__))
|
logger.debug("Registering plugin `{0}`".format(plugin.__name__))
|
||||||
|
|
@ -118,34 +121,18 @@ class Pelican(object):
|
||||||
self.settings[setting])
|
self.settings[setting])
|
||||||
logger.warning("%s = '%s'" % (setting, self.settings[setting]))
|
logger.warning("%s = '%s'" % (setting, self.settings[setting]))
|
||||||
|
|
||||||
if self.settings.get('FEED', False):
|
for new, old in [('FEED', 'FEED_ATOM'), ('TAG_FEED', 'TAG_FEED_ATOM'),
|
||||||
logger.warning('Found deprecated `FEED` in settings. Modify FEED'
|
('CATEGORY_FEED', 'CATEGORY_FEED_ATOM'),
|
||||||
' to FEED_ATOM in your settings and theme for the same behavior.'
|
('TRANSLATION_FEED', 'TRANSLATION_FEED_ATOM')]:
|
||||||
' Temporarily setting FEED_ATOM for backwards compatibility.')
|
if self.settings.get(new, False):
|
||||||
self.settings['FEED_ATOM'] = self.settings['FEED']
|
logger.warning(
|
||||||
|
'Found deprecated `%(new)s` in settings. Modify %(new)s '
|
||||||
if self.settings.get('TAG_FEED', False):
|
'to %(old)s in your settings and theme for the same '
|
||||||
logger.warning('Found deprecated `TAG_FEED` in settings. Modify '
|
'behavior. Temporarily setting %(old)s for backwards '
|
||||||
' TAG_FEED to TAG_FEED_ATOM in your settings and theme for the '
|
'compatibility.',
|
||||||
'same behavior. Temporarily setting TAG_FEED_ATOM for backwards '
|
{'new': new, 'old': old}
|
||||||
'compatibility.')
|
)
|
||||||
self.settings['TAG_FEED_ATOM'] = self.settings['TAG_FEED']
|
self.settings[old] = self.settings[new]
|
||||||
|
|
||||||
if self.settings.get('CATEGORY_FEED', False):
|
|
||||||
logger.warning('Found deprecated `CATEGORY_FEED` in settings. '
|
|
||||||
'Modify CATEGORY_FEED to CATEGORY_FEED_ATOM in your settings and '
|
|
||||||
'theme for the same behavior. Temporarily setting '
|
|
||||||
'CATEGORY_FEED_ATOM for backwards compatibility.')
|
|
||||||
self.settings['CATEGORY_FEED_ATOM'] =\
|
|
||||||
self.settings['CATEGORY_FEED']
|
|
||||||
|
|
||||||
if self.settings.get('TRANSLATION_FEED', False):
|
|
||||||
logger.warning('Found deprecated `TRANSLATION_FEED` in settings. '
|
|
||||||
'Modify TRANSLATION_FEED to TRANSLATION_FEED_ATOM in your '
|
|
||||||
'settings and theme for the same behavior. Temporarily setting '
|
|
||||||
'TRANSLATION_FEED_ATOM for backwards compatibility.')
|
|
||||||
self.settings['TRANSLATION_FEED_ATOM'] =\
|
|
||||||
self.settings['TRANSLATION_FEED']
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Run the generators and return"""
|
"""Run the generators and return"""
|
||||||
|
|
@ -182,8 +169,10 @@ class Pelican(object):
|
||||||
|
|
||||||
signals.finalized.send(self)
|
signals.finalized.send(self)
|
||||||
|
|
||||||
articles_generator = next(g for g in generators if isinstance(g, ArticlesGenerator))
|
articles_generator = next(g for g in generators
|
||||||
pages_generator = next(g for g in generators if isinstance(g, PagesGenerator))
|
if isinstance(g, ArticlesGenerator))
|
||||||
|
pages_generator = next(g for g in generators
|
||||||
|
if isinstance(g, PagesGenerator))
|
||||||
|
|
||||||
print('Done: Processed {} articles and {} pages in {:.2f} seconds.'.format(
|
print('Done: Processed {} articles and {} pages in {:.2f} seconds.'.format(
|
||||||
len(articles_generator.articles) + len(articles_generator.translations),
|
len(articles_generator.articles) + len(articles_generator.translations),
|
||||||
|
|
@ -216,31 +205,34 @@ class Pelican(object):
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
parser = argparse.ArgumentParser(description="""A tool to generate a
|
parser = argparse.ArgumentParser(
|
||||||
static blog, with restructured text input files.""",
|
description="""A tool to generate a static blog,
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
with restructured text input files.""",
|
||||||
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(dest='path', nargs='?',
|
parser.add_argument(dest='path', nargs='?',
|
||||||
help='Path where to find the content files.',
|
help='Path where to find the content files.',
|
||||||
default=None)
|
default=None)
|
||||||
|
|
||||||
parser.add_argument('-t', '--theme-path', dest='theme',
|
parser.add_argument('-t', '--theme-path', dest='theme',
|
||||||
help='Path where to find the theme templates. If not specified, it '
|
help='Path where to find the theme templates. If not '
|
||||||
'will use the default one included with pelican.')
|
'specified, it will use the default one included with '
|
||||||
|
'pelican.')
|
||||||
|
|
||||||
parser.add_argument('-o', '--output', dest='output',
|
parser.add_argument('-o', '--output', dest='output',
|
||||||
help='Where to output the generated files. If not specified, a '
|
help='Where to output the generated files. If not '
|
||||||
'directory will be created, named "output" in the current path.')
|
'specified, a directory will be created, named '
|
||||||
|
'"output" in the current path.')
|
||||||
|
|
||||||
parser.add_argument('-s', '--settings', dest='settings',
|
parser.add_argument('-s', '--settings', dest='settings',
|
||||||
help='The settings of the application, this is automatically set to '
|
help='The settings of the application, this is '
|
||||||
'{0} if a file exists with this name.'.format(DEFAULT_CONFIG_NAME))
|
'automatically set to {0} if a file exists with this '
|
||||||
|
'name.'.format(DEFAULT_CONFIG_NAME))
|
||||||
|
|
||||||
parser.add_argument('-d', '--delete-output-directory',
|
parser.add_argument('-d', '--delete-output-directory',
|
||||||
dest='delete_outputdir',
|
dest='delete_outputdir', action='store_true',
|
||||||
action='store_true',
|
default=None, help='Delete the output directory.')
|
||||||
default=None,
|
|
||||||
help='Delete the output directory.')
|
|
||||||
|
|
||||||
parser.add_argument('-v', '--verbose', action='store_const',
|
parser.add_argument('-v', '--verbose', action='store_const',
|
||||||
const=logging.INFO, dest='verbosity',
|
const=logging.INFO, dest='verbosity',
|
||||||
|
|
@ -259,8 +251,8 @@ def parse_arguments():
|
||||||
|
|
||||||
parser.add_argument('-r', '--autoreload', dest='autoreload',
|
parser.add_argument('-r', '--autoreload', dest='autoreload',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="Relaunch pelican each time a modification occurs"
|
help='Relaunch pelican each time a modification occurs'
|
||||||
" on the content files.")
|
' on the content files.')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -345,7 +337,8 @@ def main():
|
||||||
logger.warning('No valid files found in content.')
|
logger.warning('No valid files found in content.')
|
||||||
|
|
||||||
if modified['theme'] is None:
|
if modified['theme'] is None:
|
||||||
logger.warning('Empty theme folder. Using `basic` theme.')
|
logger.warning('Empty theme folder. Using `basic` '
|
||||||
|
'theme.')
|
||||||
|
|
||||||
pelican.run()
|
pelican.run()
|
||||||
|
|
||||||
|
|
@ -381,7 +374,7 @@ def main():
|
||||||
|
|
||||||
logger.critical(msg)
|
logger.critical(msg)
|
||||||
|
|
||||||
if (args.verbosity == logging.DEBUG):
|
if args.verbosity == logging.DEBUG:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
sys.exit(getattr(e, 'exitcode', 1))
|
sys.exit(getattr(e, 'exitcode', 1))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue