1
0
Fork 0
forked from github/pelican
pelican-theme/pelican/settings.py

164 lines
6.5 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
import os
import locale
import logging
from os.path import isabs
logger = logging.getLogger(__name__)
2011-05-31 12:44:40 +02:00
2011-01-13 00:46:10 +01:00
DEFAULT_THEME = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
Put the notmyidea theme by default. --HG-- rename : samples/themes/notmyidea/css/main.css => pelican/themes/notmyidea/css/main.css rename : samples/themes/notmyidea/css/pygment.css => pelican/themes/notmyidea/css/pygment.css rename : samples/themes/notmyidea/css/reset.css => pelican/themes/notmyidea/css/reset.css rename : samples/themes/notmyidea/images/icons/delicious.png => pelican/themes/notmyidea/images/icons/delicious.png rename : samples/themes/notmyidea/images/icons/lastfm.png => pelican/themes/notmyidea/images/icons/lastfm.png rename : samples/themes/notmyidea/images/icons/rss.png => pelican/themes/notmyidea/images/icons/rss.png rename : samples/themes/notmyidea/images/icons/twitter.png => pelican/themes/notmyidea/images/icons/twitter.png rename : samples/themes/notmyidea/templates/archives.html => pelican/themes/notmyidea/templates/archives.html rename : samples/themes/notmyidea/templates/article.html => pelican/themes/notmyidea/templates/article.html rename : samples/themes/notmyidea/templates/base.html => pelican/themes/notmyidea/templates/base.html rename : samples/themes/notmyidea/templates/categories.html => pelican/themes/notmyidea/templates/categories.html rename : samples/themes/notmyidea/templates/category.html => pelican/themes/notmyidea/templates/category.html rename : samples/themes/notmyidea/templates/index.html => pelican/themes/notmyidea/templates/index.html rename : samples/themes/notmyidea/templates/tag.html => pelican/themes/notmyidea/templates/tag.html rename : samples/themes/notmyidea/templates/tags.html => pelican/themes/notmyidea/templates/tags.html rename : pelican/themes/templates/archives.html => pelican/themes/simple/templates/archives.html rename : pelican/themes/templates/article.html => pelican/themes/simple/templates/article.html rename : pelican/themes/templates/base.html => pelican/themes/simple/templates/base.html rename : pelican/themes/templates/categories.html => pelican/themes/simple/templates/categories.html rename : pelican/themes/templates/category.html => pelican/themes/simple/templates/category.html rename : pelican/themes/templates/index.html => pelican/themes/simple/templates/index.html rename : pelican/themes/templates/tag.html => pelican/themes/simple/templates/tag.html rename : pelican/themes/templates/tags.html => pelican/themes/simple/templates/tags.html
2010-10-30 16:47:59 +01:00
"themes/notmyidea"])
2012-03-23 09:04:57 +00:00
_DEFAULT_CONFIG = {'PATH': '.',
'ARTICLE_DIR': '',
'ARTICLE_EXCLUDES': ('pages',),
'PAGE_DIR': 'pages',
'PAGE_EXCLUDES': (),
'THEME': DEFAULT_THEME,
'OUTPUT_PATH': 'output/',
'MARKUP': ('rst', 'md'),
'STATIC_PATHS': ['images', ],
'THEME_STATIC_PATHS': ['static', ],
'FEED': 'feeds/all.atom.xml',
'CATEGORY_FEED': 'feeds/%s.atom.xml',
'TRANSLATION_FEED': 'feeds/all-%s.atom.xml',
'FEED_MAX_ITEMS': '',
'SITENAME': 'A Pelican Blog',
2010-11-05 02:05:00 +00:00
'DISPLAY_PAGES_ON_MENU': True,
'PDF_GENERATOR': False,
'DEFAULT_CATEGORY': 'misc',
'DEFAULT_DATE': 'fs',
'WITH_FUTURE_DATES': True,
'CSS_FILE': 'main.css',
'REVERSE_ARCHIVE_ORDER': False,
'REVERSE_CATEGORY_ORDER': False,
'DELETE_OUTPUT_DIRECTORY': False,
'ARTICLE_URL': '{slug}.html',
'ARTICLE_SAVE_AS': '{slug}.html',
'ARTICLE_LANG_URL': '{slug}-{lang}.html',
'ARTICLE_LANG_SAVE_AS': '{slug}-{lang}.html',
'PAGE_URL': 'pages/{slug}.html',
'PAGE_SAVE_AS': 'pages/{slug}.html',
'PAGE_LANG_URL': 'pages/{slug}-{lang}.html',
'PAGE_LANG_SAVE_AS': 'pages/{slug}-{lang}.html',
'CATEGORY_URL': 'category/{slug}.html',
'CATEGORY_SAVE_AS': 'category/{slug}.html',
'TAG_URL': 'tag/{slug}.html',
'TAG_SAVE_AS': 'tag/{slug}.html',
'AUTHOR_URL': u'author/{slug}.html',
'AUTHOR_SAVE_AS': u'author/{slug}.html',
'RELATIVE_URLS': True,
'DEFAULT_LANG': 'en',
'TAG_CLOUD_STEPS': 4,
'TAG_CLOUD_MAX_ITEMS': 100,
'DIRECT_TEMPLATES': ('index', 'tags', 'categories', 'archives'),
'PAGINATED_DIRECT_TEMPLATES': ('index', ),
'PELICAN_CLASS': 'pelican.Pelican',
'DEFAULT_DATE_FORMAT': '%a %d %B %Y',
'DATE_FORMATS': {},
'JINJA_EXTENSIONS': [],
'LOCALE': '', # default to user locale
'DEFAULT_PAGINATION': False,
'DEFAULT_ORPHANS': 0,
'DEFAULT_METADATA': (),
'FILES_TO_COPY': (),
'DEFAULT_STATUS': 'published',
'ARTICLE_PERMALINK_STRUCTURE': '',
'TYPOGRIFY': False,
2012-04-15 02:20:20 +03:00
'LESS_GENERATOR': False,
'SUMMARY_MAX_LENGTH': 50,
2012-05-07 17:11:57 +02:00
'WEBASSETS': False,
2011-06-18 01:03:53 +02:00
'PLUGINS': [],
}
def read_settings(filename=None):
2012-03-22 07:58:04 -07:00
if filename:
local_settings = get_settings_from_file(filename)
else:
local_settings = _DEFAULT_CONFIG
configured_settings = configure_settings(local_settings, None, filename)
return configured_settings
def get_settings_from_file(filename, default_settings=None):
"""Load a Python file into a dictionary.
"""
2012-03-22 07:58:04 -07:00
if default_settings == None:
default_settings = _DEFAULT_CONFIG
context = default_settings.copy()
if filename:
tempdict = {}
execfile(filename, tempdict)
for key in tempdict:
if key.isupper():
context[key] = tempdict[key]
2012-03-22 07:58:04 -07:00
return context
2012-03-22 07:58:04 -07:00
def configure_settings(settings, default_settings=None, filename=None):
"""Provide optimizations, error checking, and warnings for loaded settings"""
if default_settings is None:
default_settings = _DEFAULT_CONFIG
# Make the paths relative to the settings file
if filename:
2011-07-02 15:15:21 -05:00
for path in ['PATH', 'OUTPUT_PATH']:
2012-03-22 07:58:04 -07:00
if path in settings:
if settings[path] is not None and not isabs(settings[path]):
settings[path] = os.path.abspath(os.path.normpath(
os.path.join(os.path.dirname(filename), settings[path]))
)
2011-07-02 15:15:21 -05:00
# if locales is not a list, make it one
2012-03-22 07:58:04 -07:00
locales = settings['LOCALE']
2011-05-19 18:00:17 +01:00
if isinstance(locales, basestring):
locales = [locales]
# try to set the different locales, fallback on the default.
2011-05-31 12:44:40 +02:00
if not locales:
locales = _DEFAULT_CONFIG['LOCALE']
for locale_ in locales:
try:
locale.setlocale(locale.LC_ALL, locale_)
break # break if it is successfull
except locale.Error:
pass
else:
logger.warn("LOCALE option doesn't contain a correct value")
if ('SITEURL' in settings):
# If SITEURL has a trailing slash, remove it and provide a warning
siteurl = settings['SITEURL']
if (siteurl.endswith('/')):
settings['SITEURL'] = siteurl[:-1]
logger.warn("Removed extraneous trailing slash from SITEURL.")
# If SITEURL is defined but FEED_DOMAIN isn't, set FEED_DOMAIN = SITEURL
if not 'FEED_DOMAIN' in settings:
settings['FEED_DOMAIN'] = settings['SITEURL']
2012-03-22 07:58:04 -07:00
# Warn if feeds are generated with both SITEURL & FEED_DOMAIN undefined
if (('FEED' in settings) or ('FEED_RSS' in settings)) and (not 'FEED_DOMAIN' in settings):
logger.warn("Since feed URLs should always be absolute, you should specify "
2012-03-22 07:58:04 -07:00
"FEED_DOMAIN in your settings. (e.g., 'FEED_DOMAIN = "
"http://www.example.com')")
if not 'TIMEZONE' in settings:
logger.warn("No timezone information specified in the settings. Assuming"
" your timezone is UTC for feed generation. Check "
"http://docs.notmyidea.org/alexis/pelican/settings.html#timezone "
"for more information")
if 'WEBASSETS' in settings and settings['WEBASSETS'] is not False:
2012-05-07 17:11:57 +02:00
try:
from webassets.ext.jinja2 import AssetsExtension
settings['JINJA_EXTENSIONS'].append(AssetsExtension)
except ImportError:
logger.warn("You must install the webassets module to use WEBASSETS.")
settings['WEBASSETS'] = False
2012-03-22 07:58:04 -07:00
return settings