From 21b058258962cd2d6d742f1c79b948ba9395a528 Mon Sep 17 00:00:00 2001 From: milde Date: Mon, 15 Nov 2021 17:55:57 +0000 Subject: [PATCH] odt writer: Fix spurious output with Windows (bug #350). git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8888 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/HISTORY.txt | 4 ++++ docutils/docutils/writers/odf_odt/__init__.py | 15 +++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index a43313cf3..e9976097b 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -29,6 +29,10 @@ Changes Since 0.18 - Fix typo (bug #432). +* docutils/writers/odf_odt/__init__.py: + + - Fix spurious output with Windows (bug #350). + Release 0.18 (2021-10-26) ========================= diff --git a/docutils/docutils/writers/odf_odt/__init__.py b/docutils/docutils/writers/odf_odt/__init__.py index eca31dc20..dfbc71577 100644 --- a/docutils/docutils/writers/odf_odt/__init__.py +++ b/docutils/docutils/writers/odf_odt/__init__.py @@ -16,6 +16,7 @@ import itertools import os import os.path import re +import subprocess import sys import tempfile import time @@ -45,6 +46,8 @@ else: from StringIO import StringIO from urllib2 import HTTPError from urllib2 import urlopen + FileNotFoundError = OSError + # Import pygments and odtwriter pygments formatters if possible. try: @@ -1087,13 +1090,13 @@ class ODFTranslator(nodes.GenericNodeVisitor): def setup_paper(self, root_el): try: - fin = os.popen("paperconf -s 2> /dev/null") - dimensions = fin.read().split() - w, h = (float(s) for s in dimensions) - except (IOError, ValueError): + dimensions = subprocess.check_output(('paperconf', '-s'), + stderr=subprocess.STDOUT) + w, h = (float(s) for s in dimensions.split()) + except (subprocess.CalledProcessError, FileNotFoundError, ValueError): + self.document.reporter.info( + 'Cannot use `paperconf`, defaulting to Letter.') w, h = 612, 792 # default to Letter - finally: - fin.close() def walk(el): if el.tag == "{%s}page-layout-properties" % SNSD["style"] and \ -- 2.11.4.GIT