fix for running from bad dir
[librarian.git] / librarian / pdf.py
index bcf8d9a..3c83cad 100644 (file)
@@ -34,13 +34,14 @@ STYLESHEETS = {
     'wl2tex': 'pdf/wl2tex.xslt',
 }
 
     'wl2tex': 'pdf/wl2tex.xslt',
 }
 
-CUSTOMIZATIONS = [
-    'nofootnotes',
-    'nothemes',
-    'onehalfleading',
-    'doubleleading',
-    'nowlfont',
-    ]
+#CUSTOMIZATIONS = [
+#    'nofootnotes',
+#    'nothemes',
+#    'defaultleading',
+#    'onehalfleading',
+#    'doubleleading',
+#    'nowlfont',
+#    ]
 
 def insert_tags(doc, split_re, tagname, exclude=None):
     """ inserts <tagname> for every occurence of `split_re' in text nodes in the `doc' tree
 
 def insert_tags(doc, split_re, tagname, exclude=None):
     """ inserts <tagname> for every occurence of `split_re' in text nodes in the `doc' tree
@@ -180,7 +181,7 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None,
     verbose: prints all output from LaTeX
     save_tex: path to save the intermediary LaTeX file to
     morefloats (old/new/none): force specific morefloats
     verbose: prints all output from LaTeX
     save_tex: path to save the intermediary LaTeX file to
     morefloats (old/new/none): force specific morefloats
-    cover: a cover.Cover object
+    cover: a cover.Cover factory or True for default
     flags: less-advertising,
     customizations: user requested customizations regarding various formatting parameters (passed to wl LaTeX class)
     """
     flags: less-advertising,
     customizations: user requested customizations regarding various formatting parameters (passed to wl LaTeX class)
     """
@@ -192,9 +193,10 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None,
         if cover:
             if cover is True:
                 cover = WLCover
         if cover:
             if cover is True:
                 cover = WLCover
-            document.edoc.getroot().set('data-cover-width', str(cover.width))
-            document.edoc.getroot().set('data-cover-height', str(cover.height))
-            if cover.uses_dc_cover:
+            bound_cover = cover(document.book_info)
+            document.edoc.getroot().set('data-cover-width', str(bound_cover.width))
+            document.edoc.getroot().set('data-cover-height', str(bound_cover.height))
+            if bound_cover.uses_dc_cover:
                 if document.book_info.cover_by:
                     document.edoc.getroot().set('data-cover-by', document.book_info.cover_by)
                 if document.book_info.cover_source:
                 if document.book_info.cover_by:
                     document.edoc.getroot().set('data-cover-by', document.book_info.cover_by)
                 if document.book_info.cover_source:
@@ -230,9 +232,8 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None,
         temp = mkdtemp('-wl2pdf')
 
         if cover:
         temp = mkdtemp('-wl2pdf')
 
         if cover:
-            c = cover(document.book_info)
             with open(os.path.join(temp, 'cover.png'), 'w') as f:
             with open(os.path.join(temp, 'cover.png'), 'w') as f:
-                c.save(f)
+                bound_cover.save(f)
 
         del document # no longer needed large object :)
 
 
         del document # no longer needed large object :)
 
@@ -249,7 +250,10 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None,
         shutil.copy(get_resource('pdf/wl.cls'), temp)
         shutil.copy(get_resource('res/wl-logo.png'), temp)
 
         shutil.copy(get_resource('pdf/wl.cls'), temp)
         shutil.copy(get_resource('res/wl-logo.png'), temp)
 
-        cwd = os.getcwd()
+        try:
+            cwd = os.getcwd()
+        except OSError:
+            cwd = None
         os.chdir(temp)
 
         if verbose:
         os.chdir(temp)
 
         if verbose:
@@ -259,7 +263,8 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None,
         if p:
             raise ParseError("Error parsing .tex file")
 
         if p:
             raise ParseError("Error parsing .tex file")
 
-        os.chdir(cwd)
+        if cwd is not None:
+            os.chdir(cwd)
 
         output_file = NamedTemporaryFile(prefix='librarian', suffix='.pdf', delete=False)
         pdf_path = os.path.join(temp, 'doc.pdf')
 
         output_file = NamedTemporaryFile(prefix='librarian', suffix='.pdf', delete=False)
         pdf_path = os.path.join(temp, 'doc.pdf')