From d183a3c15dee46ea00ac15c77e72903adfce8d1a Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 2 Aug 2012 13:53:27 +0200 Subject: [PATCH] fix for running from bad dir --- librarian/epub.py | 8 ++++++-- librarian/pdf.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/librarian/epub.py b/librarian/epub.py index f34bb86..469ff40 100644 --- a/librarian/epub.py +++ b/librarian/epub.py @@ -471,7 +471,10 @@ def transform(wldoc, verbose=False, if not flags or not 'without-fonts' in flags: # strip fonts tmpdir = mkdtemp('-librarian-epub') - cwd = os.getcwd() + try: + cwd = os.getcwd() + except OSError: + cwd = None os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'font-optimizer')) for fname in 'DejaVuSerif.ttf', 'DejaVuSerif-Bold.ttf', 'DejaVuSerif-Italic.ttf', 'DejaVuSerif-BoldItalic.ttf': @@ -486,7 +489,8 @@ def transform(wldoc, verbose=False, manifest.append(etree.fromstring( '' % (fname, fname))) rmtree(tmpdir) - os.chdir(cwd) + if cwd is not None: + os.chdir(cwd) zip.writestr('OPS/content.opf', etree.tostring(opf, pretty_print=True)) title = document.book_info.title diff --git a/librarian/pdf.py b/librarian/pdf.py index 7bba9d2..3c83cad 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -250,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) - cwd = os.getcwd() + try: + cwd = os.getcwd() + except OSError: + cwd = None os.chdir(temp) if verbose: @@ -260,7 +263,8 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, 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') -- 2.20.1