Calls to «print» replaced by the «pelican.log» module.

This commit is contained in:
Skami18 2011-04-19 14:49:46 +02:00
commit 3166e6dfe3
6 changed files with 33 additions and 13 deletions

View file

@ -7,6 +7,7 @@ from pelican.generators import (ArticlesGenerator, PagesGenerator,
from pelican.settings import read_settings from pelican.settings import read_settings
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
VERSION = "2.6.0" VERSION = "2.6.0"
@ -103,6 +104,12 @@ def main():
action='store_true', action='store_true',
help='Keep the output directory and just update all the generated files.' help='Keep the output directory and just update all the generated files.'
'Default is to delete the output directory.') '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, 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', action='store_true', parser.add_argument('-r', '--autoreload', dest='autoreload', action='store_true',
@ -110,6 +117,7 @@ def main():
"files") "files")
args = parser.parse_args() args = parser.parse_args()
log.init(args.verbosity)
# Split the markup languages only if some have been given. Otherwise, populate # Split the markup languages only if some have been given. Otherwise, populate
# the variable with None. # the variable with None.
markup = [a.strip().lower() for a in args.markup.split(',')] if args.markup else None markup = [a.strip().lower() for a in args.markup.split(',')] if args.markup else None
@ -134,7 +142,10 @@ def main():
except KeyboardInterrupt: except KeyboardInterrupt:
break break
else: else:
pelican.run() try:
pelican.run()
except Exception, e:
log.critical(str(e))
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from pelican.utils import slugify, truncate_html_words from pelican.utils import slugify, truncate_html_words
from pelican.log import *
class Page(object): class Page(object):
"""Represents a page """Represents a page
@ -91,5 +91,5 @@ def is_valid_content(content, f):
content.check_properties() content.check_properties()
return True return True
except NameError as e: 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 return False

View file

@ -14,6 +14,7 @@ from jinja2.exceptions import TemplateNotFound
from pelican.utils import copytree, get_relative_path, process_translations, open from pelican.utils import copytree, get_relative_path, process_translations, open
from pelican.contents import Article, Page, is_valid_content from pelican.contents import Article, Page, is_valid_content
from pelican.readers import read_file from pelican.readers import read_file
from pelican.log import *
class Generator(object): class Generator(object):
@ -321,7 +322,7 @@ class PdfGenerator(Generator):
output_pdf=os.path.join(output_path, filename) output_pdf=os.path.join(output_path, filename)
# print "Generating pdf for", obj.filename, " in ", output_pdf # print "Generating pdf for", obj.filename, " in ", output_pdf
self.pdfcreator.createPdf(text=open(obj.filename), output=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): def generate_context(self):
pass pass
@ -329,12 +330,12 @@ 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
print u' Generating PDF files...' info(u' Generating PDF files...')
pdf_path = os.path.join(self.output_path, 'pdf') pdf_path = os.path.join(self.output_path, 'pdf')
try: try:
os.mkdir(pdf_path) os.mkdir(pdf_path)
except OSError: 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 pass
for article in self.context['articles']: for article in self.context['articles']:

View file

@ -31,7 +31,7 @@ class ANSIFormatter(logging.Formatter):
def format(self, record): def format(self, record):
if not record.levelname or record.levelname is 'INFO': if not record.levelname or record.levelname is 'INFO':
return ANSI['cyan'](record.msg) return ANSI['white'](record.msg)
elif record.levelname is 'WARNING': elif record.levelname is 'WARNING':
return ANSI['yellow'](record.levelname) + ': ' + record.msg return ANSI['yellow'](record.levelname) + ': ' + record.msg
elif record.levelname is 'ERROR': elif record.levelname is 'ERROR':
@ -72,16 +72,22 @@ debug, info, warn, error, critical = (logging.debug,
logging.warn, logging.warn,
logging.error, logging.error,
logging.critical) 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() fmt = Formatter()
handler.setFormatter(fmt) handler.setFormatter(fmt)
logger.addHandler(handler) logger.addHandler(handler)
if level: logger.setLevel(level)
init()
if __name__ == '__main__': if __name__ == '__main__':
init()
logging.basicConfig(filename='example.log',level=logging.DEBUG) logging.basicConfig(filename='example.log',level=logging.DEBUG)
logging.debug('Logging test') logging.debug('Logging test')
logging.info('info') logging.info('info')

View file

@ -6,6 +6,7 @@ from datetime import datetime
from codecs import open as _open from codecs import open as _open
from itertools import groupby from itertools import groupby
from operator import attrgetter from operator import attrgetter
from pelican.log import *
def get_date(string): def get_date(string):
@ -50,7 +51,7 @@ def copytree(path, origin, destination, topath=None):
fromp = os.path.expanduser(os.path.join(origin, path)) fromp = os.path.expanduser(os.path.join(origin, path))
to = os.path.expanduser(os.path.join(destination, topath)) to = os.path.expanduser(os.path.join(destination, topath))
shutil.copytree(fromp, to) shutil.copytree(fromp, to)
print u' [ok] copying %s to %s' % (fromp, to) info('copying %s to %s' % (fromp, to))
except OSError: except OSError:
pass pass
@ -162,7 +163,7 @@ def process_translations(content_list):
) )
len_ = len(default_lang_items) len_ = len(default_lang_items)
if len_ > 1: 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: elif len_ == 0:
default_lang_items = items[:1] default_lang_items = items[:1]

View file

@ -8,6 +8,7 @@ import locale
from feedgenerator import Atom1Feed, Rss201rev2Feed from feedgenerator import Atom1Feed, Rss201rev2Feed
from pelican.utils import get_relative_path from pelican.utils import get_relative_path
from pelican.paginator import Paginator from pelican.paginator import Paginator
from pelican.log import *
class Writer(object): class Writer(object):
@ -68,7 +69,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')
print u' [ok] writing %s' % complete_path info('writing %s' % complete_path)
fp.close() fp.close()
return feed return feed
@ -103,7 +104,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)
print u' [ok] writing %s' % filename info(u'writing %s' % filename)
localcontext = context.copy() localcontext = context.copy()
if relative_urls: if relative_urls: