From f5c1682d0da0aee458474ef5a9000dd3d62171f4 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Thu, 15 Mar 2018 16:06:46 +0100 Subject: [PATCH] eliminate weasy references in code (mostly) --- librarian/parser.py | 4 -- .../activity-kind.svg | 0 .../activity-time.svg | 0 .../activity-tools.svg | 0 librarian/{weasy => pdf-from-html}/bullet.svg | 0 .../weasy.css => pdf-from-html/pdf-style.css} | 0 librarian/{weasy.py => pdf_from_html.py} | 38 +++++++------------ 7 files changed, 13 insertions(+), 29 deletions(-) rename librarian/{weasy => pdf-from-html}/activity-kind.svg (100%) rename librarian/{weasy => pdf-from-html}/activity-time.svg (100%) rename librarian/{weasy => pdf-from-html}/activity-tools.svg (100%) rename librarian/{weasy => pdf-from-html}/bullet.svg (100%) rename librarian/{weasy/weasy.css => pdf-from-html/pdf-style.css} (100%) rename librarian/{weasy.py => pdf_from_html.py} (95%) diff --git a/librarian/parser.py b/librarian/parser.py index d515954..12fffb3 100644 --- a/librarian/parser.py +++ b/librarian/parser.py @@ -171,10 +171,6 @@ class WLDocument(object): from librarian import pyhtml as html return html.transform(self, *args, **kwargs) - def as_weasy(self, *args, **kwargs): - from librarian import weasy - return weasy.transform(self, *args, **kwargs) - def as_text(self, *args, **kwargs): from librarian import text return text.transform(self, *args, **kwargs) diff --git a/librarian/weasy/activity-kind.svg b/librarian/pdf-from-html/activity-kind.svg similarity index 100% rename from librarian/weasy/activity-kind.svg rename to librarian/pdf-from-html/activity-kind.svg diff --git a/librarian/weasy/activity-time.svg b/librarian/pdf-from-html/activity-time.svg similarity index 100% rename from librarian/weasy/activity-time.svg rename to librarian/pdf-from-html/activity-time.svg diff --git a/librarian/weasy/activity-tools.svg b/librarian/pdf-from-html/activity-tools.svg similarity index 100% rename from librarian/weasy/activity-tools.svg rename to librarian/pdf-from-html/activity-tools.svg diff --git a/librarian/weasy/bullet.svg b/librarian/pdf-from-html/bullet.svg similarity index 100% rename from librarian/weasy/bullet.svg rename to librarian/pdf-from-html/bullet.svg diff --git a/librarian/weasy/weasy.css b/librarian/pdf-from-html/pdf-style.css similarity index 100% rename from librarian/weasy/weasy.css rename to librarian/pdf-from-html/pdf-style.css diff --git a/librarian/weasy.py b/librarian/pdf_from_html.py similarity index 95% rename from librarian/weasy.py rename to librarian/pdf_from_html.py index c924a8e..b299abf 100644 --- a/librarian/weasy.py +++ b/librarian/pdf_from_html.py @@ -46,7 +46,7 @@ class EduModule(Xmill): Edukacja medialna - + @@ -617,17 +617,18 @@ class PrawdaFalsz(Exercise): return super(PrawdaFalsz, self).handle_punkt(element) -class EduModuleWeasyFormat(Format): +class EduModulePdfFromHtmlFormat(Format): PRIMARY_MATERIAL_FORMATS = ('pdf', 'odt') class MaterialNotFound(BaseException): pass - def __init__(self, wldoc, media_root='', save_html_to=None, **kwargs): - super(EduModuleWeasyFormat, self).__init__(wldoc, **kwargs) + def __init__(self, wldoc, media_root='', html_to_pdf_command=None, save_html_to=None, **kwargs): + super(EduModulePdfFromHtmlFormat, self).__init__(wldoc, **kwargs) self.media_root = media_root self.materials_by_slug = None self.attachments = {} + self.html_to_pdf_command = html_to_pdf_command self.save_html_to = save_html_to def get_html(self): @@ -640,25 +641,25 @@ class EduModuleWeasyFormat(Format): }) return edumod.generate(self.wldoc.edoc.getroot()) - def get_weasy_dir(self): + def get_html_dir(self): html = self.get_html() - temp = mkdtemp('-weasy') + temp = mkdtemp('-pdf-from-html') # Save TeX file html_path = os.path.join(temp, 'doc.html') with open(html_path, 'w') as fout: fout.write(html.encode('utf-8')) # Copy style - weasy_dir = os.path.join(os.path.dirname(__file__), 'weasy') - for filename in os.listdir(weasy_dir): - shutil.copy(get_resource('weasy/%s' % filename), temp) + html_dir = os.path.join(os.path.dirname(__file__), 'pdf-from-html') + for filename in os.listdir(html_dir): + shutil.copy(get_resource('pdf-from-html/%s' % filename), temp) for name, path in self.attachments.items(): shutil.copy(path, os.path.join(temp, name)) return temp def get_pdf(self): - temp = self.get_weasy_dir() + temp = self.get_html_dir() if self.save_html_to: - save_path = os.path.join(self.save_html_to, 'weasy-html') + save_path = os.path.join(self.save_html_to, 'doc-html') shutil.rmtree(save_path, ignore_errors=True) shutil.copytree(temp, save_path) html_path = os.path.join(temp, 'doc.html') @@ -669,9 +670,7 @@ class EduModuleWeasyFormat(Format): cwd = None os.chdir(temp) - WEASY_COMMAND = '/home/janek/Desktop/weasy-test/bin/weasyprint' - - p = call([WEASY_COMMAND, html_path, pdf_path]) + p = call([self.html_to_pdf_command, html_path, pdf_path]) if p: raise ParseError("Error parsing .html file: %s" % html_path) @@ -721,14 +720,3 @@ class EduModuleWeasyFormat(Format): def get_help_url(self, naglowek): return None - - -def transform(wldoc, stylesheet='edumed', options=None, flags=None, verbose=None): - """Transforms the WL document to XHTML. - - If output_filename is None, returns an XML, - otherwise returns True if file has been written,False if it hasn't. - File won't be written if it has no content. - """ - edumodfor = EduModuleWeasyFormat(wldoc) - return edumodfor.build() -- 2.20.1