forked from github/pelican
Calls to «print» replaced by the «pelican.log» module.
This commit is contained in:
parent
834c952f20
commit
3166e6dfe3
6 changed files with 33 additions and 13 deletions
|
|
@ -7,6 +7,7 @@ from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
|||
from pelican.settings import read_settings
|
||||
from pelican.utils import clean_output_dir, files_changed
|
||||
from pelican.writers import Writer
|
||||
from pelican import log
|
||||
|
||||
VERSION = "2.6.0"
|
||||
|
||||
|
|
@ -103,6 +104,12 @@ def main():
|
|||
action='store_true',
|
||||
help='Keep the output directory and just update all the generated files.'
|
||||
'Default is to 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',
|
||||
|
|
@ -110,6 +117,7 @@ def main():
|
|||
"files")
|
||||
args = parser.parse_args()
|
||||
|
||||
log.init(args.verbosity)
|
||||
# Split the markup languages only if some have been given. Otherwise, populate
|
||||
# the variable with None.
|
||||
markup = [a.strip().lower() for a in args.markup.split(',')] if args.markup else None
|
||||
|
|
@ -134,7 +142,10 @@ def main():
|
|||
except KeyboardInterrupt:
|
||||
break
|
||||
else:
|
||||
pelican.run()
|
||||
try:
|
||||
pelican.run()
|
||||
except Exception, e:
|
||||
log.critical(str(e))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from pelican.utils import slugify, truncate_html_words
|
||||
|
||||
from pelican.log import *
|
||||
|
||||
class Page(object):
|
||||
"""Represents a page
|
||||
|
|
@ -91,5 +91,5 @@ def is_valid_content(content, f):
|
|||
content.check_properties()
|
||||
return True
|
||||
except NameError as e:
|
||||
print u" [info] Skipping %s: impossible to find informations about '%s'" % (f, e)
|
||||
error(u"Skipping %s: impossible to find informations about '%s'" % (f, e))
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from jinja2.exceptions import TemplateNotFound
|
|||
from pelican.utils import copytree, get_relative_path, process_translations, open
|
||||
from pelican.contents import Article, Page, is_valid_content
|
||||
from pelican.readers import read_file
|
||||
from pelican.log import *
|
||||
|
||||
|
||||
class Generator(object):
|
||||
|
|
@ -321,7 +322,7 @@ class PdfGenerator(Generator):
|
|||
output_pdf=os.path.join(output_path, filename)
|
||||
# print "Generating pdf for", obj.filename, " in ", output_pdf
|
||||
self.pdfcreator.createPdf(text=open(obj.filename), output=output_pdf)
|
||||
print u' [ok] writing %s' % output_pdf
|
||||
info(u' [ok] writing %s' % output_pdf)
|
||||
|
||||
def generate_context(self):
|
||||
pass
|
||||
|
|
@ -329,12 +330,12 @@ class PdfGenerator(Generator):
|
|||
def generate_output(self, writer=None):
|
||||
# we don't use the writer passed as argument here
|
||||
# since we write our own files
|
||||
print u' Generating PDF files...'
|
||||
info(u' Generating PDF files...')
|
||||
pdf_path = os.path.join(self.output_path, 'pdf')
|
||||
try:
|
||||
os.mkdir(pdf_path)
|
||||
except OSError:
|
||||
print "Couldn't create the pdf output folder in ", pdf_path
|
||||
error("Couldn't create the pdf output folder in " + pdf_path)
|
||||
pass
|
||||
|
||||
for article in self.context['articles']:
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ANSIFormatter(logging.Formatter):
|
|||
|
||||
def format(self, record):
|
||||
if not record.levelname or record.levelname is 'INFO':
|
||||
return ANSI['cyan'](record.msg)
|
||||
return ANSI['white'](record.msg)
|
||||
elif record.levelname is 'WARNING':
|
||||
return ANSI['yellow'](record.levelname) + ': ' + record.msg
|
||||
elif record.levelname is 'ERROR':
|
||||
|
|
@ -72,16 +72,22 @@ debug, info, warn, error, critical = (logging.debug,
|
|||
logging.warn,
|
||||
logging.error,
|
||||
logging.critical)
|
||||
DEBUG, INFO, WARN, ERROR, CRITICAL = (logging.DEBUG,
|
||||
logging.INFO,
|
||||
logging.WARN,
|
||||
logging.ERROR,
|
||||
logging.CRITICAL)
|
||||
|
||||
|
||||
def init(logger=logging.getLogger(), handler=logging.StreamHandler()):
|
||||
def init(level=None, logger=logging.getLogger(), handler=logging.StreamHandler()):
|
||||
fmt = Formatter()
|
||||
handler.setFormatter(fmt)
|
||||
logger.addHandler(handler)
|
||||
if level: logger.setLevel(level)
|
||||
|
||||
init()
|
||||
|
||||
if __name__ == '__main__':
|
||||
init()
|
||||
logging.basicConfig(filename='example.log',level=logging.DEBUG)
|
||||
logging.debug('Logging test')
|
||||
logging.info('info')
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from datetime import datetime
|
|||
from codecs import open as _open
|
||||
from itertools import groupby
|
||||
from operator import attrgetter
|
||||
from pelican.log import *
|
||||
|
||||
|
||||
def get_date(string):
|
||||
|
|
@ -50,7 +51,7 @@ def copytree(path, origin, destination, topath=None):
|
|||
fromp = os.path.expanduser(os.path.join(origin, path))
|
||||
to = os.path.expanduser(os.path.join(destination, topath))
|
||||
shutil.copytree(fromp, to)
|
||||
print u' [ok] copying %s to %s' % (fromp, to)
|
||||
info('copying %s to %s' % (fromp, to))
|
||||
|
||||
except OSError:
|
||||
pass
|
||||
|
|
@ -162,7 +163,7 @@ def process_translations(content_list):
|
|||
)
|
||||
len_ = len(default_lang_items)
|
||||
if len_ > 1:
|
||||
print u' [warning] there are %s variants of "%s"' % (len_, slug)
|
||||
warning(u'there are %s variants of "%s"' % (len_, slug))
|
||||
elif len_ == 0:
|
||||
default_lang_items = items[:1]
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import locale
|
|||
from feedgenerator import Atom1Feed, Rss201rev2Feed
|
||||
from pelican.utils import get_relative_path
|
||||
from pelican.paginator import Paginator
|
||||
from pelican.log import *
|
||||
|
||||
|
||||
class Writer(object):
|
||||
|
|
@ -68,7 +69,7 @@ class Writer(object):
|
|||
pass
|
||||
fp = open(complete_path, 'w')
|
||||
feed.write(fp, 'utf-8')
|
||||
print u' [ok] writing %s' % complete_path
|
||||
info('writing %s' % complete_path)
|
||||
|
||||
fp.close()
|
||||
return feed
|
||||
|
|
@ -103,7 +104,7 @@ class Writer(object):
|
|||
pass
|
||||
with open(filename, 'w', encoding='utf-8') as f:
|
||||
f.write(output)
|
||||
print u' [ok] writing %s' % filename
|
||||
info(u'writing %s' % filename)
|
||||
|
||||
localcontext = context.copy()
|
||||
if relative_urls:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue