mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Put deprecation code in a separate place
This commit is contained in:
parent
1c219d14bb
commit
d6be2fb44c
2 changed files with 39 additions and 30 deletions
|
|
@ -6,7 +6,7 @@ import time
|
|||
|
||||
from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
||||
StaticGenerator, PdfGenerator)
|
||||
from pelican.settings import read_settings
|
||||
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
||||
from pelican.utils import clean_output_dir, files_changed
|
||||
from pelican.writers import Writer
|
||||
from pelican import log
|
||||
|
|
@ -20,6 +20,9 @@ class Pelican(object):
|
|||
"""Read the settings, and performs some checks on the environment
|
||||
before doing anything else.
|
||||
"""
|
||||
if settings is None:
|
||||
settings = _DEFAULT_CONFIG
|
||||
|
||||
self.path = path or settings['PATH']
|
||||
if not self.path:
|
||||
raise Exception('you need to specify a path containing the content'
|
||||
|
|
@ -28,44 +31,11 @@ class Pelican(object):
|
|||
if self.path.endswith('/'):
|
||||
self.path = self.path[:-1]
|
||||
|
||||
if settings.get('CLEAN_URLS', False):
|
||||
log.warning('Found deprecated `CLEAN_URLS` in settings. Modifing'
|
||||
' the following settings for the same behaviour.')
|
||||
|
||||
settings['ARTICLE_URL'] = '{slug}/'
|
||||
settings['ARTICLE_LANG_URL'] = '{slug}-{lang}/'
|
||||
settings['PAGE_URL'] = 'pages/{slug}/'
|
||||
settings['PAGE_LANG_URL'] = 'pages/{slug}-{lang}/'
|
||||
|
||||
for setting in ('ARTICLE_URL', 'ARTICLE_LANG_URL', 'PAGE_URL',
|
||||
'PAGE_LANG_URL'):
|
||||
log.warning("%s = '%s'" % (setting, settings[setting]))
|
||||
|
||||
if settings.get('ARTICLE_PERMALINK_STRUCTURE', False):
|
||||
log.warning('Found deprecated `ARTICLE_PERMALINK_STRUCTURE` in'
|
||||
' settings. Modifing the following settings for'
|
||||
' the same behaviour.')
|
||||
|
||||
structure = settings['ARTICLE_PERMALINK_STRUCTURE']
|
||||
|
||||
# Convert %(variable) into {variable}.
|
||||
structure = re.sub('%\((\w+)\)s', '{\g<1>}', structure)
|
||||
|
||||
# Convert %x into {date:%x} for strftime
|
||||
structure = re.sub('(%[A-z])', '{date:\g<1>}', structure)
|
||||
|
||||
# Strip a / prefix
|
||||
structure = re.sub('^/', '', structure)
|
||||
|
||||
for setting in ('ARTICLE_URL', 'ARTICLE_LANG_URL', 'PAGE_URL',
|
||||
'PAGE_LANG_URL', 'ARTICLE_SAVE_AS',
|
||||
'ARTICLE_LANG_SAVE_AS', 'PAGE_SAVE_AS',
|
||||
'PAGE_LANG_SAVE_AS'):
|
||||
settings[setting] = os.path.join(structure, settings[setting])
|
||||
log.warning("%s = '%s'" % (setting, settings[setting]))
|
||||
|
||||
# define the default settings
|
||||
self.settings = settings
|
||||
|
||||
self._handle_deprecation()
|
||||
|
||||
self.theme = theme or settings['THEME']
|
||||
output_path = output_path or settings['OUTPUT_PATH']
|
||||
self.output_path = os.path.realpath(output_path)
|
||||
|
|
@ -82,6 +52,45 @@ class Pelican(object):
|
|||
else:
|
||||
raise Exception("Impossible to find the theme %s" % theme)
|
||||
|
||||
def _handle_deprecation(self):
|
||||
|
||||
if self.settings.get('CLEAN_URLS', False):
|
||||
log.warning('Found deprecated `CLEAN_URLS` in settings. Modifing'
|
||||
' the following settings for the same behaviour.')
|
||||
|
||||
self.settings['ARTICLE_URL'] = '{slug}/'
|
||||
self.settings['ARTICLE_LANG_URL'] = '{slug}-{lang}/'
|
||||
self.settings['PAGE_URL'] = 'pages/{slug}/'
|
||||
self.settings['PAGE_LANG_URL'] = 'pages/{slug}-{lang}/'
|
||||
|
||||
for setting in ('ARTICLE_URL', 'ARTICLE_LANG_URL', 'PAGE_URL',
|
||||
'PAGE_LANG_URL'):
|
||||
log.warning("%s = '%s'" % (setting, self.settings[setting]))
|
||||
|
||||
if self.settings.get('ARTICLE_PERMALINK_STRUCTURE', False):
|
||||
log.warning('Found deprecated `ARTICLE_PERMALINK_STRUCTURE` in'
|
||||
' settings. Modifing the following settings for'
|
||||
' the same behaviour.')
|
||||
|
||||
structure = self.settings['ARTICLE_PERMALINK_STRUCTURE']
|
||||
|
||||
# Convert %(variable) into {variable}.
|
||||
structure = re.sub('%\((\w+)\)s', '{\g<1>}', structure)
|
||||
|
||||
# Convert %x into {date:%x} for strftime
|
||||
structure = re.sub('(%[A-z])', '{date:\g<1>}', structure)
|
||||
|
||||
# Strip a / prefix
|
||||
structure = re.sub('^/', '', structure)
|
||||
|
||||
for setting in ('ARTICLE_URL', 'ARTICLE_LANG_URL', 'PAGE_URL',
|
||||
'PAGE_LANG_URL', 'ARTICLE_SAVE_AS',
|
||||
'ARTICLE_LANG_SAVE_AS', 'PAGE_SAVE_AS',
|
||||
'PAGE_LANG_SAVE_AS'):
|
||||
self.settings[setting] = os.path.join(structure,
|
||||
self.settings[setting])
|
||||
log.warning("%s = '%s'" % (setting, self.settings[setting]))
|
||||
|
||||
def run(self):
|
||||
"""Run the generators and return"""
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ _DEFAULT_CONFIG = {'PATH': None,
|
|||
}
|
||||
|
||||
|
||||
def read_settings(filename):
|
||||
def read_settings(filename=None):
|
||||
"""Load a Python file into a dictionary.
|
||||
"""
|
||||
context = _DEFAULT_CONFIG.copy()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue