mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fix a bug with the optional dependency to rst2pdf.
This commit is contained in:
parent
9756739386
commit
b391defeb6
2 changed files with 11 additions and 9 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from rst2pdf.createpdf import RstToPdf
|
|
||||||
|
|
||||||
from pelican.utils import update_dict, copytree
|
from pelican.utils import update_dict, copytree
|
||||||
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
|
||||||
|
|
@ -136,10 +134,16 @@ class StaticProcessor(Processor):
|
||||||
class PdfProcessor(Processor):
|
class PdfProcessor(Processor):
|
||||||
"""Generate PDFs on the output dir, for all articles and pages coming from
|
"""Generate PDFs on the output dir, for all articles and pages coming from
|
||||||
rst"""
|
rst"""
|
||||||
|
def __init__(self):
|
||||||
|
try:
|
||||||
|
from rst2pdf.createpdf import RstToPdf
|
||||||
|
self.pdfcreator = RstToPdf(breakside=0, stylesheets=['twelvepoint'])
|
||||||
|
except ImportError:
|
||||||
|
raise Exception("unable to find rst2pdf")
|
||||||
|
|
||||||
def _create_pdf(self, creator, obj, output_path):
|
def _create_pdf(self, obj, output_path):
|
||||||
if obj.filename.endswith(".rst"):
|
if obj.filename.endswith(".rst"):
|
||||||
creator.createPdf(text=open(obj.filename).read(),
|
self.pdfcreator.createPdf(text=open(obj.filename).read(),
|
||||||
output=os.path.join(output_path, "%s.pdf" % obj.slug))
|
output=os.path.join(output_path, "%s.pdf" % obj.slug))
|
||||||
|
|
||||||
def process(self, context, generator):
|
def process(self, context, generator):
|
||||||
|
|
@ -149,10 +153,8 @@ class PdfProcessor(Processor):
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
pdfcreator = RstToPdf(breakside=0, stylesheets=['twelvepoint'])
|
|
||||||
|
|
||||||
for article in context['articles']:
|
for article in context['articles']:
|
||||||
self._create_pdf(pdfcreator, article, pdf_path)
|
self._create_pdf(article, pdf_path)
|
||||||
|
|
||||||
for page in context['pages']:
|
for page in context['pages']:
|
||||||
self._create_pdf(pdfcreator, page, pdf_path)
|
self._create_pdf(page, pdf_path)
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -7,7 +7,7 @@ if sys.version_info < (2,7):
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = "pelican",
|
name = "pelican",
|
||||||
version = '2.4.4',
|
version = '2.4.5',
|
||||||
url = 'http://alexis.notmyidea.org/pelican/',
|
url = 'http://alexis.notmyidea.org/pelican/',
|
||||||
author = 'Alexis Metaireau',
|
author = 'Alexis Metaireau',
|
||||||
author_email = 'alexis@notmyidea.org',
|
author_email = 'alexis@notmyidea.org',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue