mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge branch 'master' into feeddomain
Conflicts: pelican/settings.py tests/test_settings.py
This commit is contained in:
commit
6e467172e5
17 changed files with 135 additions and 109 deletions
|
|
@ -86,7 +86,7 @@ Setting name (default value) What does it do?
|
||||||
.. [#] Default is the system locale.
|
.. [#] Default is the system locale.
|
||||||
|
|
||||||
|
|
||||||
URL Settings
|
URL settings
|
||||||
------------
|
------------
|
||||||
|
|
||||||
You can customize the URLs and locations where files will be saved. The URLs and
|
You can customize the URLs and locations where files will be saved. The URLs and
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,25 @@
|
||||||
import argparse
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import logging
|
||||||
|
import argparse
|
||||||
|
|
||||||
from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
||||||
StaticGenerator, PdfGenerator)
|
StaticGenerator, PdfGenerator)
|
||||||
|
from pelican.log import init
|
||||||
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
from pelican.settings import read_settings, _DEFAULT_CONFIG
|
||||||
from pelican.utils import clean_output_dir, files_changed
|
from pelican.utils import clean_output_dir, files_changed
|
||||||
from pelican.writers import Writer
|
from pelican.writers import Writer
|
||||||
from pelican import log
|
|
||||||
|
|
||||||
__major__ = 3
|
__major__ = 3
|
||||||
__minor__ = 0
|
__minor__ = 0
|
||||||
__version__ = "{0}.{1}".format(__major__, __minor__)
|
__version__ = "{0}.{1}".format(__major__, __minor__)
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Pelican(object):
|
class Pelican(object):
|
||||||
def __init__(self, settings=None, path=None, theme=None, output_path=None,
|
def __init__(self, settings=None, path=None, theme=None, output_path=None,
|
||||||
markup=None, delete_outputdir=False):
|
markup=None, delete_outputdir=False):
|
||||||
|
|
@ -57,7 +61,7 @@ class Pelican(object):
|
||||||
def _handle_deprecation(self):
|
def _handle_deprecation(self):
|
||||||
|
|
||||||
if self.settings.get('CLEAN_URLS', False):
|
if self.settings.get('CLEAN_URLS', False):
|
||||||
log.warning('Found deprecated `CLEAN_URLS` in settings. Modifing'
|
logger.warning('Found deprecated `CLEAN_URLS` in settings. Modifing'
|
||||||
' the following settings for the same behaviour.')
|
' the following settings for the same behaviour.')
|
||||||
|
|
||||||
self.settings['ARTICLE_URL'] = '{slug}/'
|
self.settings['ARTICLE_URL'] = '{slug}/'
|
||||||
|
|
@ -67,10 +71,10 @@ class Pelican(object):
|
||||||
|
|
||||||
for setting in ('ARTICLE_URL', 'ARTICLE_LANG_URL', 'PAGE_URL',
|
for setting in ('ARTICLE_URL', 'ARTICLE_LANG_URL', 'PAGE_URL',
|
||||||
'PAGE_LANG_URL'):
|
'PAGE_LANG_URL'):
|
||||||
log.warning("%s = '%s'" % (setting, self.settings[setting]))
|
logger.warning("%s = '%s'" % (setting, self.settings[setting]))
|
||||||
|
|
||||||
if self.settings.get('ARTICLE_PERMALINK_STRUCTURE', False):
|
if self.settings.get('ARTICLE_PERMALINK_STRUCTURE', False):
|
||||||
log.warning('Found deprecated `ARTICLE_PERMALINK_STRUCTURE` in'
|
logger.warning('Found deprecated `ARTICLE_PERMALINK_STRUCTURE` in'
|
||||||
' settings. Modifing the following settings for'
|
' settings. Modifing the following settings for'
|
||||||
' the same behaviour.')
|
' the same behaviour.')
|
||||||
|
|
||||||
|
|
@ -91,7 +95,7 @@ class Pelican(object):
|
||||||
'PAGE_LANG_SAVE_AS'):
|
'PAGE_LANG_SAVE_AS'):
|
||||||
self.settings[setting] = os.path.join(structure,
|
self.settings[setting] = os.path.join(structure,
|
||||||
self.settings[setting])
|
self.settings[setting])
|
||||||
log.warning("%s = '%s'" % (setting, self.settings[setting]))
|
logger.warning("%s = '%s'" % (setting, self.settings[setting]))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Run the generators and return"""
|
"""Run the generators and return"""
|
||||||
|
|
@ -135,45 +139,59 @@ class Pelican(object):
|
||||||
return Writer(self.output_path, settings=self.settings)
|
return Writer(self.output_path, settings=self.settings)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def parse_arguments():
|
||||||
parser = argparse.ArgumentParser(description="""A tool to generate a
|
parser = argparse.ArgumentParser(description="""A tool to generate a
|
||||||
static blog, with restructured text input files.""",
|
static blog, with restructured text input files.""",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
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='.')
|
||||||
|
|
||||||
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 specified, it'
|
||||||
'will use the default one included with pelican.')
|
'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 specified, a '
|
||||||
'directory will be created, named "output" in the current path.')
|
'directory will be created, named "output" in the current path.')
|
||||||
|
|
||||||
parser.add_argument('-m', '--markup', dest='markup',
|
parser.add_argument('-m', '--markup', dest='markup',
|
||||||
help='The list of markup language to use (rst or md). Please indicate '
|
help='The list of markup language to use (rst or md). Please indicate '
|
||||||
'them separated by commas.')
|
'them separated by commas.')
|
||||||
|
|
||||||
parser.add_argument('-s', '--settings', dest='settings',
|
parser.add_argument('-s', '--settings', dest='settings',
|
||||||
help='The settings of the application.')
|
help='The settings of the application.')
|
||||||
parser.add_argument('-d', '--delete-output-directory',
|
|
||||||
dest='delete_outputdir',
|
|
||||||
action='store_true', help='Delete the output directory.')
|
|
||||||
parser.add_argument('-v', '--verbose', action='store_const',
|
|
||||||
const=log.INFO, dest='verbosity',
|
|
||||||
help='Show all messages.')
|
|
||||||
parser.add_argument('-q', '--quiet', action='store_const',
|
|
||||||
const=log.CRITICAL, dest='verbosity',
|
|
||||||
help='Show only critical errors.')
|
|
||||||
parser.add_argument('-D', '--debug', action='store_const',
|
|
||||||
const=log.DEBUG, dest='verbosity',
|
|
||||||
help='Show all message, including debug messages.')
|
|
||||||
parser.add_argument('--version', action='version', version=__version__,
|
|
||||||
help='Print the pelican version and exit.')
|
|
||||||
parser.add_argument('-r', '--autoreload', dest='autoreload',
|
|
||||||
action='store_true',
|
|
||||||
help="Relaunch pelican each time a modification occurs"
|
|
||||||
" on the content files.")
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
log.init(args.verbosity)
|
parser.add_argument('-d', '--delete-output-directory',
|
||||||
|
dest='delete_outputdir',
|
||||||
|
action='store_true', help='Delete the output directory.')
|
||||||
|
|
||||||
|
parser.add_argument('-v', '--verbose', action='store_const',
|
||||||
|
const=logging.INFO, dest='verbosity',
|
||||||
|
help='Show all messages.')
|
||||||
|
|
||||||
|
parser.add_argument('-q', '--quiet', action='store_const',
|
||||||
|
const=logging.CRITICAL, dest='verbosity',
|
||||||
|
help='Show only critical errors.')
|
||||||
|
|
||||||
|
parser.add_argument('-D', '--debug', action='store_const',
|
||||||
|
const=logging.DEBUG, dest='verbosity',
|
||||||
|
help='Show all message, including debug messages.')
|
||||||
|
|
||||||
|
parser.add_argument('--version', action='version', version=__version__,
|
||||||
|
help='Print the pelican version and exit.')
|
||||||
|
|
||||||
|
parser.add_argument('-r', '--autoreload', dest='autoreload',
|
||||||
|
action='store_true',
|
||||||
|
help="Relaunch pelican each time a modification occurs"
|
||||||
|
" on the content files.")
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = parse_arguments()
|
||||||
|
init(args.verbosity)
|
||||||
# Split the markup languages only if some have been given. Otherwise,
|
# Split the markup languages only if some have been given. Otherwise,
|
||||||
# populate the variable with None.
|
# populate the variable with None.
|
||||||
markup = [a.strip().lower() for a in args.markup.split(',')]\
|
markup = [a.strip().lower() for a in args.markup.split(',')]\
|
||||||
|
|
@ -207,9 +225,9 @@ def main():
|
||||||
else:
|
else:
|
||||||
pelican.run()
|
pelican.run()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.critical(unicode(e))
|
logger.critical(unicode(e))
|
||||||
|
|
||||||
if (args.verbosity == log.DEBUG):
|
if (args.verbosity == logging.DEBUG):
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
sys.exit(getattr(e, 'exitcode', 1))
|
sys.exit(getattr(e, 'exitcode', 1))
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,19 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import locale
|
||||||
|
import logging
|
||||||
|
import functools
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from os import getenv
|
from os import getenv
|
||||||
from sys import platform, stdin
|
from sys import platform, stdin
|
||||||
import functools
|
|
||||||
import locale
|
|
||||||
|
|
||||||
from pelican.log import warning, error
|
|
||||||
from pelican.settings import _DEFAULT_CONFIG
|
from pelican.settings import _DEFAULT_CONFIG
|
||||||
from pelican.utils import slugify, truncate_html_words
|
from pelican.utils import slugify, truncate_html_words
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Page(object):
|
class Page(object):
|
||||||
"""Represents a page
|
"""Represents a page
|
||||||
Given a content, and metadata, create an adequate object.
|
Given a content, and metadata, create an adequate object.
|
||||||
|
|
@ -44,7 +48,7 @@ class Page(object):
|
||||||
else:
|
else:
|
||||||
title = filename.decode('utf-8') if filename else self.title
|
title = filename.decode('utf-8') if filename else self.title
|
||||||
self.author = Author(getenv('USER', 'John Doe'), settings)
|
self.author = Author(getenv('USER', 'John Doe'), settings)
|
||||||
warning(u"Author of `{0}' unknown, assuming that his name is "
|
logger.warning(u"Author of `{0}' unknown, assuming that his name is "
|
||||||
"`{1}'".format(title, self.author))
|
"`{1}'".format(title, self.author))
|
||||||
|
|
||||||
# manage languages
|
# manage languages
|
||||||
|
|
@ -200,6 +204,6 @@ def is_valid_content(content, f):
|
||||||
content.check_properties()
|
content.check_properties()
|
||||||
return True
|
return True
|
||||||
except NameError, e:
|
except NameError, e:
|
||||||
error(u"Skipping %s: impossible to find informations about '%s'"\
|
logger.error(u"Skipping %s: impossible to find informations about '%s'"\
|
||||||
% (f, e))
|
% (f, e))
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import datetime
|
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
|
import logging
|
||||||
|
import datetime
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
@ -13,11 +14,13 @@ from jinja2 import Environment, FileSystemLoader, PrefixLoader, ChoiceLoader
|
||||||
from jinja2.exceptions import TemplateNotFound
|
from jinja2.exceptions import TemplateNotFound
|
||||||
|
|
||||||
from pelican.contents import Article, Page, Category, is_valid_content
|
from pelican.contents import Article, Page, Category, is_valid_content
|
||||||
from pelican.log import warning, error, debug, info
|
|
||||||
from pelican.readers import read_file
|
from pelican.readers import read_file
|
||||||
from pelican.utils import copy, process_translations, open
|
from pelican.utils import copy, process_translations, open
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Generator(object):
|
class Generator(object):
|
||||||
"""Baseclass generator"""
|
"""Baseclass generator"""
|
||||||
|
|
||||||
|
|
@ -47,7 +50,7 @@ class Generator(object):
|
||||||
extensions=self.settings.get('JINJA_EXTENSIONS', []),
|
extensions=self.settings.get('JINJA_EXTENSIONS', []),
|
||||||
)
|
)
|
||||||
|
|
||||||
debug('template list: {0}'.format(self._env.list_templates()))
|
logger.debug('template list: {0}'.format(self._env.list_templates()))
|
||||||
|
|
||||||
# get custom Jinja filters from user settings
|
# get custom Jinja filters from user settings
|
||||||
custom_filters = self.settings.get('JINJA_FILTERS', {})
|
custom_filters = self.settings.get('JINJA_FILTERS', {})
|
||||||
|
|
@ -223,7 +226,7 @@ class ArticlesGenerator(Generator):
|
||||||
try:
|
try:
|
||||||
content, metadata = read_file(f, settings=self.settings)
|
content, metadata = read_file(f, settings=self.settings)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
warning(u'Could not process %s\n%s' % (f, str(e)))
|
logger.warning(u'Could not process %s\n%s' % (f, str(e)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# if no category is set, use the name of the path as a category
|
# if no category is set, use the name of the path as a category
|
||||||
|
|
@ -326,7 +329,7 @@ class PagesGenerator(Generator):
|
||||||
try:
|
try:
|
||||||
content, metadata = read_file(f)
|
content, metadata = read_file(f)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
error(u'Could not process %s\n%s' % (f, str(e)))
|
logger.error(u'Could not process %s\n%s' % (f, str(e)))
|
||||||
continue
|
continue
|
||||||
page = Page(content, metadata, settings=self.settings,
|
page = Page(content, metadata, settings=self.settings,
|
||||||
filename=f)
|
filename=f)
|
||||||
|
|
@ -388,7 +391,7 @@ class PdfGenerator(Generator):
|
||||||
# print "Generating pdf for", obj.filename, " in ", output_pdf
|
# print "Generating pdf for", obj.filename, " in ", output_pdf
|
||||||
with open(obj.filename) as f:
|
with open(obj.filename) as f:
|
||||||
self.pdfcreator.createPdf(text=f, output=output_pdf)
|
self.pdfcreator.createPdf(text=f, output=output_pdf)
|
||||||
info(u' [ok] writing %s' % output_pdf)
|
logger.info(u' [ok] writing %s' % output_pdf)
|
||||||
|
|
||||||
def generate_context(self):
|
def generate_context(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -396,13 +399,13 @@ class PdfGenerator(Generator):
|
||||||
def generate_output(self, writer=None):
|
def generate_output(self, writer=None):
|
||||||
# we don't use the writer passed as argument here
|
# we don't use the writer passed as argument here
|
||||||
# since we write our own files
|
# since we write our own files
|
||||||
info(u' Generating PDF files...')
|
logger.info(u' Generating PDF files...')
|
||||||
pdf_path = os.path.join(self.output_path, 'pdf')
|
pdf_path = os.path.join(self.output_path, 'pdf')
|
||||||
if not os.path.exists(pdf_path):
|
if not os.path.exists(pdf_path):
|
||||||
try:
|
try:
|
||||||
os.mkdir(pdf_path)
|
os.mkdir(pdf_path)
|
||||||
except OSError:
|
except OSError:
|
||||||
error("Couldn't create the pdf output folder in " + pdf_path)
|
logger.error("Couldn't create the pdf output folder in " + pdf_path)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for article in self.context['articles']:
|
for article in self.context['articles']:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
|
__all__ = [
|
||||||
|
'init'
|
||||||
|
]
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from logging import CRITICAL, ERROR, WARN, INFO, DEBUG
|
import logging
|
||||||
from logging import critical, error, info, warning, warn, debug
|
|
||||||
from logging import Formatter, getLogger, StreamHandler
|
from logging import Formatter, getLogger, StreamHandler, DEBUG
|
||||||
|
|
||||||
|
|
||||||
RESET_TERM = u'\033[0;m'
|
RESET_TERM = u'\033[0;m'
|
||||||
|
|
@ -78,32 +82,21 @@ class DummyFormatter(object):
|
||||||
|
|
||||||
|
|
||||||
def init(level=None, logger=getLogger(), handler=StreamHandler()):
|
def init(level=None, logger=getLogger(), handler=StreamHandler()):
|
||||||
|
logger = logging.getLogger()
|
||||||
fmt = DummyFormatter()
|
fmt = DummyFormatter()
|
||||||
handler.setFormatter(fmt)
|
handler.setFormatter(fmt)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
if level:
|
if level:
|
||||||
logger.setLevel(level)
|
logger.setLevel(level)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
init(level=DEBUG)
|
init(level=DEBUG)
|
||||||
debug('debug')
|
|
||||||
info('info')
|
|
||||||
warning('warning')
|
|
||||||
error('error')
|
|
||||||
critical('critical')
|
|
||||||
|
|
||||||
|
root_logger = logging.getLogger()
|
||||||
__all__ = [
|
root_logger.debug('debug')
|
||||||
"debug",
|
root_logger.info('info')
|
||||||
"info",
|
root_logger.warning('warning')
|
||||||
"warn",
|
root_logger.error('error')
|
||||||
"warning",
|
root_logger.critical('critical')
|
||||||
"error",
|
|
||||||
"critical",
|
|
||||||
"DEBUG",
|
|
||||||
"INFO",
|
|
||||||
"WARN",
|
|
||||||
"ERROR",
|
|
||||||
"CRITICAL"
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,10 @@ class RstReader(Reader):
|
||||||
if element.tagname == 'field': # custom fields (e.g. summary)
|
if element.tagname == 'field': # custom fields (e.g. summary)
|
||||||
name_elem, body_elem = element.children
|
name_elem, body_elem = element.children
|
||||||
name = name_elem.astext()
|
name = name_elem.astext()
|
||||||
value = render_node_to_html(document, body_elem)
|
if name == 'summary':
|
||||||
|
value = render_node_to_html(document, body_elem)
|
||||||
|
else:
|
||||||
|
value = body_elem.astext()
|
||||||
else: # standard fields (e.g. address)
|
else: # standard fields (e.g. address)
|
||||||
name = element.tagname
|
name = element.tagname
|
||||||
value = element.astext()
|
value = element.astext()
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
from os.path import isabs
|
|
||||||
import locale
|
import locale
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from os.path import isabs
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
from pelican import log
|
|
||||||
|
|
||||||
DEFAULT_THEME = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
|
DEFAULT_THEME = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
|
||||||
"themes/notmyidea"])
|
"themes/notmyidea"])
|
||||||
|
|
@ -122,7 +126,7 @@ def configure_settings(settings, default_settings=None, filename=None):
|
||||||
except locale.Error:
|
except locale.Error:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
log.warn("LOCALE option doesn't contain a correct value")
|
logger.warn("LOCALE option doesn't contain a correct value")
|
||||||
|
|
||||||
# If SITEURL is defined but FEED_DOMAIN isn't, set FEED_DOMAIN = SITEURL
|
# If SITEURL is defined but FEED_DOMAIN isn't, set FEED_DOMAIN = SITEURL
|
||||||
if ('SITEURL' in settings) and (not 'FEED_DOMAIN' in settings):
|
if ('SITEURL' in settings) and (not 'FEED_DOMAIN' in settings):
|
||||||
|
|
@ -130,12 +134,12 @@ def configure_settings(settings, default_settings=None, filename=None):
|
||||||
|
|
||||||
# Warn if feeds are generated with both SITEURL & FEED_DOMAIN undefined
|
# 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):
|
if (('FEED' in settings) or ('FEED_RSS' in settings)) and (not 'FEED_DOMAIN' in settings):
|
||||||
log.warn("Since feed URLs should always be absolute, you should specify "
|
logger.warn("Since feed URLs should always be absolute, you should specify "
|
||||||
"FEED_DOMAIN in your settings. (e.g., 'FEED_DOMAIN = "
|
"FEED_DOMAIN in your settings. (e.g., 'FEED_DOMAIN = "
|
||||||
"http://www.example.com')")
|
"http://www.example.com')")
|
||||||
|
|
||||||
if not 'TIMEZONE' in settings:
|
if not 'TIMEZONE' in settings:
|
||||||
log.warn("No timezone information specified in the settings. Assuming"
|
logger.warn("No timezone information specified in the settings. Assuming"
|
||||||
" your timezone is UTC for feed generation. Check "
|
" your timezone is UTC for feed generation. Check "
|
||||||
"http://docs.notmyidea.org/alexis/pelican/settings.html#timezone "
|
"http://docs.notmyidea.org/alexis/pelican/settings.html#timezone "
|
||||||
"for more information")
|
"for more information")
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import pytz
|
|
||||||
import re
|
import re
|
||||||
|
import pytz
|
||||||
import shutil
|
import shutil
|
||||||
|
import logging
|
||||||
|
|
||||||
from codecs import open as _open
|
from codecs import open as _open
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from pelican.log import warning, info
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_date(string):
|
def get_date(string):
|
||||||
|
|
@ -71,16 +73,16 @@ def copy(path, source, destination, destination_path=None, overwrite=False):
|
||||||
if os.path.isdir(source_):
|
if os.path.isdir(source_):
|
||||||
try:
|
try:
|
||||||
shutil.copytree(source_, destination_)
|
shutil.copytree(source_, destination_)
|
||||||
info('copying %s to %s' % (source_, destination_))
|
logger.info('copying %s to %s' % (source_, destination_))
|
||||||
except OSError:
|
except OSError:
|
||||||
if overwrite:
|
if overwrite:
|
||||||
shutil.rmtree(destination_)
|
shutil.rmtree(destination_)
|
||||||
shutil.copytree(source_, destination_)
|
shutil.copytree(source_, destination_)
|
||||||
info('replacement of %s with %s' % (source_, destination_))
|
logger.info('replacement of %s with %s' % (source_, destination_))
|
||||||
|
|
||||||
elif os.path.isfile(source_):
|
elif os.path.isfile(source_):
|
||||||
shutil.copy(source_, destination_)
|
shutil.copy(source_, destination_)
|
||||||
info('copying %s to %s' % (source_, destination_))
|
logger.info('copying %s to %s' % (source_, destination_))
|
||||||
|
|
||||||
|
|
||||||
def clean_output_dir(path):
|
def clean_output_dir(path):
|
||||||
|
|
@ -186,14 +188,14 @@ def process_translations(content_list):
|
||||||
default_lang_items = filter(attrgetter('in_default_lang'), items)
|
default_lang_items = filter(attrgetter('in_default_lang'), items)
|
||||||
len_ = len(default_lang_items)
|
len_ = len(default_lang_items)
|
||||||
if len_ > 1:
|
if len_ > 1:
|
||||||
warning(u'there are %s variants of "%s"' % (len_, slug))
|
logger.warning(u'there are %s variants of "%s"' % (len_, slug))
|
||||||
for x in default_lang_items:
|
for x in default_lang_items:
|
||||||
warning(' %s' % x.filename)
|
logger.warning(' %s' % x.filename)
|
||||||
elif len_ == 0:
|
elif len_ == 0:
|
||||||
default_lang_items = items[:1]
|
default_lang_items = items[:1]
|
||||||
|
|
||||||
if not slug:
|
if not slug:
|
||||||
warning('empty slug for %r' % (default_lang_items[0].filename,))
|
logger.warning('empty slug for %r' % (default_lang_items[0].filename,))
|
||||||
index.extend(default_lang_items)
|
index.extend(default_lang_items)
|
||||||
translations.extend(filter(
|
translations.extend(filter(
|
||||||
lambda x: x not in default_lang_items,
|
lambda x: x not in default_lang_items,
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,20 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
import locale
|
||||||
|
import logging
|
||||||
|
|
||||||
from codecs import open
|
from codecs import open
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import locale
|
|
||||||
import re
|
|
||||||
|
|
||||||
from feedgenerator import Atom1Feed, Rss201rev2Feed
|
from feedgenerator import Atom1Feed, Rss201rev2Feed
|
||||||
from pelican.paginator import Paginator
|
from pelican.paginator import Paginator
|
||||||
from pelican.log import info
|
|
||||||
from pelican.utils import get_relative_path, set_date_tzinfo
|
from pelican.utils import get_relative_path, set_date_tzinfo
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Writer(object):
|
class Writer(object):
|
||||||
|
|
||||||
|
|
@ -73,7 +77,7 @@ class Writer(object):
|
||||||
pass
|
pass
|
||||||
fp = open(complete_path, 'w')
|
fp = open(complete_path, 'w')
|
||||||
feed.write(fp, 'utf-8')
|
feed.write(fp, 'utf-8')
|
||||||
info('writing %s' % complete_path)
|
logger.info('writing %s' % complete_path)
|
||||||
|
|
||||||
fp.close()
|
fp.close()
|
||||||
return feed
|
return feed
|
||||||
|
|
@ -108,7 +112,7 @@ class Writer(object):
|
||||||
pass
|
pass
|
||||||
with open(filename, 'w', encoding='utf-8') as f:
|
with open(filename, 'w', encoding='utf-8') as f:
|
||||||
f.write(output)
|
f.write(output)
|
||||||
info(u'writing %s' % filename)
|
logger.info(u'writing %s' % filename)
|
||||||
|
|
||||||
localcontext = context.copy()
|
localcontext = context.copy()
|
||||||
if relative_urls:
|
if relative_urls:
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,4 @@ This is a super article !
|
||||||
:summary:
|
:summary:
|
||||||
Multi-line metadata should be supported
|
Multi-line metadata should be supported
|
||||||
as well as **inline markup**.
|
as well as **inline markup**.
|
||||||
|
:custom_field: http://notmyidea.org
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,20 @@
|
||||||
|
__all__ = [
|
||||||
|
'temporary_folder',
|
||||||
|
'get_article',
|
||||||
|
'unittest',
|
||||||
|
]
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
|
||||||
from pelican.contents import Article
|
from pelican.contents import Article
|
||||||
|
|
||||||
|
try:
|
||||||
|
import unittest2 as unittest
|
||||||
|
except ImportError:
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def temporary_folder():
|
def temporary_folder():
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import with_statement
|
|
||||||
try:
|
from .support import unittest
|
||||||
from unittest2 import TestCase, skip
|
|
||||||
except ImportError, e:
|
|
||||||
from unittest import TestCase, skip # NOQA
|
|
||||||
|
|
||||||
from pelican.contents import Page
|
from pelican.contents import Page
|
||||||
from pelican.settings import _DEFAULT_CONFIG
|
from pelican.settings import _DEFAULT_CONFIG
|
||||||
|
|
@ -14,7 +11,8 @@ from jinja2.utils import generate_lorem_ipsum
|
||||||
TEST_CONTENT = str(generate_lorem_ipsum(n=1))
|
TEST_CONTENT = str(generate_lorem_ipsum(n=1))
|
||||||
TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
|
TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
|
||||||
|
|
||||||
class TestPage(TestCase):
|
|
||||||
|
class TestPage(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPage, self).setUp()
|
super(TestPage, self).setUp()
|
||||||
|
|
@ -117,7 +115,6 @@ class TestPage(TestCase):
|
||||||
try:
|
try:
|
||||||
page = Page(**page_kwargs)
|
page = Page(**page_kwargs)
|
||||||
self.assertEqual(page.locale_date, u'2015-09-13(\u65e5)')
|
self.assertEqual(page.locale_date, u'2015-09-13(\u65e5)')
|
||||||
# above is unicode in Japanese: 2015-09-13(“ú)
|
|
||||||
except locale_module.Error:
|
except locale_module.Error:
|
||||||
# The constructor of ``Page`` will try to set the locale to
|
# The constructor of ``Page`` will try to set the locale to
|
||||||
# ``ja_JP.utf8``. But this attempt will failed when there is no
|
# ``ja_JP.utf8``. But this attempt will failed when there is no
|
||||||
|
|
@ -126,4 +123,4 @@ class TestPage(TestCase):
|
||||||
#
|
#
|
||||||
# Until we find some other method to test this functionality, we
|
# Until we find some other method to test this functionality, we
|
||||||
# will simply skip this test.
|
# will simply skip this test.
|
||||||
skip("There is no locale %s in this system." % locale)
|
unittest.skip("There is no locale %s in this system." % locale)
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
try:
|
|
||||||
import unittest2 as unittest
|
from mock import MagicMock
|
||||||
except ImportError, e:
|
|
||||||
import unittest # NOQA
|
|
||||||
|
|
||||||
from pelican.generators import ArticlesGenerator
|
from pelican.generators import ArticlesGenerator
|
||||||
from pelican.settings import _DEFAULT_CONFIG
|
from pelican.settings import _DEFAULT_CONFIG
|
||||||
|
from .support import unittest
|
||||||
from mock import MagicMock
|
|
||||||
|
|
||||||
|
|
||||||
class TestArticlesGenerator(unittest.TestCase):
|
class TestArticlesGenerator(unittest.TestCase):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from support import temporary_folder
|
from .support import temporary_folder
|
||||||
|
|
||||||
from pelican import Pelican
|
from pelican import Pelican
|
||||||
from pelican.settings import read_settings
|
from pelican.settings import read_settings
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
try:
|
|
||||||
import unittest2 as unittest
|
|
||||||
except ImportError, e:
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from pelican import readers
|
from pelican import readers
|
||||||
|
from .support import unittest
|
||||||
|
|
||||||
CUR_DIR = os.path.dirname(__file__)
|
CUR_DIR = os.path.dirname(__file__)
|
||||||
CONTENT_PATH = os.path.join(CUR_DIR, 'content')
|
CONTENT_PATH = os.path.join(CUR_DIR, 'content')
|
||||||
|
|
@ -30,6 +27,7 @@ class RstReaderTest(unittest.TestCase):
|
||||||
' <strong>inline markup</strong>.',
|
' <strong>inline markup</strong>.',
|
||||||
'date': datetime.datetime(2010, 12, 2, 10, 14),
|
'date': datetime.datetime(2010, 12, 2, 10, 14),
|
||||||
'tags': ['foo', 'bar', 'foobar'],
|
'tags': ['foo', 'bar', 'foobar'],
|
||||||
|
'custom_field': 'http://notmyidea.org',
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value in expected.items():
|
for key, value in expected.items():
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
try:
|
|
||||||
import unittest2
|
|
||||||
except ImportError, e:
|
|
||||||
import unittest as unittest2
|
|
||||||
|
|
||||||
from os.path import dirname, abspath, join
|
from os.path import dirname, abspath, join
|
||||||
|
|
||||||
from pelican.settings import read_settings, configure_settings, _DEFAULT_CONFIG
|
from pelican.settings import read_settings, configure_settings, _DEFAULT_CONFIG
|
||||||
|
from .support import unittest
|
||||||
|
|
||||||
|
|
||||||
class TestSettingsConfiguration(unittest2.TestCase):
|
class TestSettingsConfiguration(unittest.TestCase):
|
||||||
"""Provided a file, it should read it, replace the default values,
|
"""Provided a file, it should read it, replace the default values,
|
||||||
append new values to the settings (if any), and apply basic settings
|
append new values to the settings (if any), and apply basic settings
|
||||||
optimizations.
|
optimizations.
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,10 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
try:
|
|
||||||
import unittest2 as unittest
|
|
||||||
except ImportError:
|
|
||||||
import unittest # NOQA
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from pelican import utils
|
from pelican import utils
|
||||||
from support import get_article
|
from .support import get_article, unittest
|
||||||
|
|
||||||
|
|
||||||
class TestUtils(unittest.TestCase):
|
class TestUtils(unittest.TestCase):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue