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__))
|
||||||
|
|
@ -82,8 +85,8 @@ class Pelican(object):
|
||||||
|
|
||||||
if self.settings.get('CLEAN_URLS', False):
|
if self.settings.get('CLEAN_URLS', False):
|
||||||
logger.warning('Found deprecated `CLEAN_URLS` in settings.'
|
logger.warning('Found deprecated `CLEAN_URLS` in settings.'
|
||||||
' Modifying the following settings for the'
|
' Modifying the following settings for the'
|
||||||
' same behaviour.')
|
' same behaviour.')
|
||||||
|
|
||||||
self.settings['ARTICLE_URL'] = '{slug}/'
|
self.settings['ARTICLE_URL'] = '{slug}/'
|
||||||
self.settings['ARTICLE_LANG_URL'] = '{slug}-{lang}/'
|
self.settings['ARTICLE_LANG_URL'] = '{slug}-{lang}/'
|
||||||
|
|
@ -96,8 +99,8 @@ class Pelican(object):
|
||||||
|
|
||||||
if self.settings.get('ARTICLE_PERMALINK_STRUCTURE', False):
|
if self.settings.get('ARTICLE_PERMALINK_STRUCTURE', False):
|
||||||
logger.warning('Found deprecated `ARTICLE_PERMALINK_STRUCTURE` in'
|
logger.warning('Found deprecated `ARTICLE_PERMALINK_STRUCTURE` in'
|
||||||
' settings. Modifying the following settings for'
|
' settings. Modifying the following settings for'
|
||||||
' the same behaviour.')
|
' the same behaviour.')
|
||||||
|
|
||||||
structure = self.settings['ARTICLE_PERMALINK_STRUCTURE']
|
structure = self.settings['ARTICLE_PERMALINK_STRUCTURE']
|
||||||
|
|
||||||
|
|
@ -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,51 +205,54 @@ 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',
|
||||||
help='Show all messages.')
|
help='Show all messages.')
|
||||||
|
|
||||||
parser.add_argument('-q', '--quiet', action='store_const',
|
parser.add_argument('-q', '--quiet', action='store_const',
|
||||||
const=logging.CRITICAL, dest='verbosity',
|
const=logging.CRITICAL, dest='verbosity',
|
||||||
help='Show only critical errors.')
|
help='Show only critical errors.')
|
||||||
|
|
||||||
parser.add_argument('-D', '--debug', action='store_const',
|
parser.add_argument('-D', '--debug', action='store_const',
|
||||||
const=logging.DEBUG, dest='verbosity',
|
const=logging.DEBUG, dest='verbosity',
|
||||||
help='Show all message, including debug messages.')
|
help='Show all message, including debug messages.')
|
||||||
|
|
||||||
parser.add_argument('--version', action='version', version=__version__,
|
parser.add_argument('--version', action='version', version=__version__,
|
||||||
help='Print the pelican version and exit.')
|
help='Print the pelican version and exit.')
|
||||||
|
|
||||||
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()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -270,7 +262,7 @@ def get_config(args):
|
||||||
config['PATH'] = os.path.abspath(os.path.expanduser(args.path))
|
config['PATH'] = os.path.abspath(os.path.expanduser(args.path))
|
||||||
if args.output:
|
if args.output:
|
||||||
config['OUTPUT_PATH'] = \
|
config['OUTPUT_PATH'] = \
|
||||||
os.path.abspath(os.path.expanduser(args.output))
|
os.path.abspath(os.path.expanduser(args.output))
|
||||||
if args.theme:
|
if args.theme:
|
||||||
abstheme = os.path.abspath(os.path.expanduser(args.theme))
|
abstheme = os.path.abspath(os.path.expanduser(args.theme))
|
||||||
config['THEME'] = abstheme if os.path.exists(abstheme) else args.theme
|
config['THEME'] = abstheme if os.path.exists(abstheme) else args.theme
|
||||||
|
|
@ -335,17 +327,18 @@ def main():
|
||||||
modified = {k: next(v) for k, v in watchers.items()}
|
modified = {k: next(v) for k, v in watchers.items()}
|
||||||
|
|
||||||
if modified['settings']:
|
if modified['settings']:
|
||||||
pelican, settings = get_instance(args)
|
pelican, settings = get_instance(args)
|
||||||
|
|
||||||
if any(modified.values()):
|
if any(modified.values()):
|
||||||
print('\n-> Modified: {}. re-generating...'.format(
|
print('\n-> Modified: {}. re-generating...'.format(
|
||||||
', '.join(k for k, v in modified.items() if v)))
|
', '.join(k for k, v in modified.items() if v)))
|
||||||
|
|
||||||
if modified['content'] is None:
|
if modified['content'] is None:
|
||||||
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()
|
||||||
|
|
||||||
|
|
@ -358,7 +351,7 @@ def main():
|
||||||
logger.critical(e.args)
|
logger.critical(e.args)
|
||||||
raise
|
raise
|
||||||
logger.warning(
|
logger.warning(
|
||||||
'Caught exception "{0}". Reloading.'.format(e))
|
'Caught exception "{0}". Reloading.'.format(e))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
time.sleep(.5) # sleep to avoid cpu load
|
time.sleep(.5) # sleep to avoid cpu load
|
||||||
|
|
@ -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