PEP 8 fixes

This commit is contained in:
Alexis Metaireau 2011-02-15 13:48:57 +00:00
commit e0e4155e89
2 changed files with 23 additions and 16 deletions

View file

@ -36,7 +36,8 @@ class Generator(object):
templates ready to use with Jinja2. templates ready to use with Jinja2.
""" """
path = os.path.expanduser(os.path.join(self.theme, 'templates')) path = os.path.expanduser(os.path.join(self.theme, 'templates'))
env = Environment(loader=FileSystemLoader(path),extensions=self.settings.get('JINJA_EXTENSIONS', [])) env = Environment(loader=FileSystemLoader(path),
extensions=self.settings.get('JINJA_EXTENSIONS', []))
templates = {} templates = {}
for template in _TEMPLATES: for template in _TEMPLATES:
try: try:
@ -135,7 +136,8 @@ class ArticlesGenerator(Generator):
writer.write_file, writer.write_file,
relative_urls = self.settings.get('RELATIVE_URLS') relative_urls = self.settings.get('RELATIVE_URLS')
) )
# to minimize the number of relative path stuff modification in writer, articles pass first # to minimize the number of relative path stuff modification
# in writer, articles pass first
for article in chain(self.translations, self.articles): for article in chain(self.translations, self.articles):
write('%s' % article.save_as, write('%s' % article.save_as,
templates['article'], self.context, article=article, templates['article'], self.context, article=article,
@ -291,7 +293,8 @@ class PdfGenerator(Generator):
pass pass
def generate_output(self, writer=None): def generate_output(self, writer=None):
# we don't use the writer passed as argument here, since we write our own files # we don't use the writer passed as argument here
# since we write our own files
print u' Generating PDF files...' print u' Generating PDF files...'
pdf_path = os.path.join(self.output_path, 'pdf') pdf_path = os.path.join(self.output_path, 'pdf')
try: try:

View file

@ -83,7 +83,8 @@ class Writer(object):
:param template: template to use to generate the content :param template: template to use to generate the content
:param context: dict to pass to the templates. :param context: dict to pass to the templates.
:param relative_urls: use relative urls or absolutes ones :param relative_urls: use relative urls or absolutes ones
:param paginated: dict of article list to paginate - must have the same length (same list in different orders) :param paginated: dict of article list to paginate - must have the
same length (same list in different orders)
:param **kwargs: additional variables to pass to the templates :param **kwargs: additional variables to pass to the templates
""" """
@ -114,8 +115,8 @@ class Writer(object):
for key in paginated.iterkeys(): for key in paginated.iterkeys():
object_list = paginated[key] object_list = paginated[key]
paginators[key] = Paginator(object_list, paginators[key] = Paginator(object_list,
self.settings.get('DEFAULT_PAGINATION'), self.settings.get('DEFAULT_PAGINATION'),
self.settings.get('DEFAULT_ORPHANS')) self.settings.get('DEFAULT_ORPHANS'))
# generated pages, and write # generated pages, and write
for page_num in range(paginators.values()[0].num_pages): for page_num in range(paginators.values()[0].num_pages):
paginated_localcontext = localcontext.copy() paginated_localcontext = localcontext.copy()
@ -127,19 +128,22 @@ class Writer(object):
'%s_page' % key: page}) '%s_page' % key: page})
if page_num > 0: if page_num > 0:
# FIXME file extension # FIXME file extension
paginated_name = paginated_name.replace('.html', '%s.html' % (page_num+1)) paginated_name = paginated_name.replace('.html',
'%s.html' % (page_num+1))
_write_file(template, paginated_localcontext, self.output_path, paginated_name) _write_file(template, paginated_localcontext, self.output_path,
paginated_name)
else: else:
# no pagination # no pagination
_write_file(template, localcontext, self.output_path, name) _write_file(template, localcontext, self.output_path, name)
def update_context_contents(self, name, context): def update_context_contents(self, name, context):
"""Recursively run the context to find elements (articles, pages, etc) whose content getter needs to """Recursively run the context to find elements (articles, pages, etc)
be modified in order to deal with relative paths. whose content getter needs to
be modified in order to deal with relative paths.
:param name: name of the file to output. :param name: name of the file to output.
:param context: dict that will be passed to the templates. :param context: dict that will be passed to the templates.
""" """
if context is None: if context is None:
return None return None
@ -173,13 +177,13 @@ class Writer(object):
return context return context
def inject_update_method(self, name, item): def inject_update_method(self, name, item):
"""Replace the content attribute getter of an element by a function that will deals with its """Replace the content attribute getter of an element by a function
relatives paths. that will deals with its relatives paths.
""" """
def _update_object_content(name, input): def _update_object_content(name, input):
"""Change all the relatives paths of the input content to relatives paths """Change all the relatives paths of the input content to relatives
suitable fot the ouput content paths suitable fot the ouput content
:param name: path of the output. :param name: path of the output.
:param input: input resource that will be passed to the templates. :param input: input resource that will be passed to the templates.