From: Radek Czajka Date: Thu, 2 Aug 2012 11:53:27 +0000 (+0200) Subject: fix for running from bad dir X-Git-Tag: 1.7~152 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/d183a3c15dee46ea00ac15c77e72903adfce8d1a?ds=sidebyside fix for running from bad dir --- 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')