#Stefan Seefeld has trouble with the docbook stylesheets import os, re from Xml.Xslt import test_harness from Ft.Lib.Uri import OsPathToUri # The name of the environment variable that will indicate # the location of DocBook XSL docbook-xsl-#.#.# directory KEYNAME = 'DOCBOOK_HOME' source_1 = """\ Chapter Sect1 Sect2 """ MIN_VERSION = '1.64.0' # NOTE: there is a '%s' for the actual version of docbook used # # docbook-xsl-1.68.0 and up expected_1_1680 = """\

Table of Contents

1. Chapter
Sect1
Sect2

Chapter 1. Chapter

Table of Contents

Sect1
Sect2

Sect1

Sect2

""" # docbook-xsl-1.64.0(?) and up; expected_1 = """\

Table of Contents

1. Chapter
Sect1
Sect2

Chapter 1. Chapter

Table of Contents

Sect1
Sect2

Sect1

Sect2

""" def Test(tester): tester.startTest('Check for DocBook XSL stylesheets') dirs = ["/usr/share/sgml/docbook/xsl-stylesheets", #default for docbook-style-xsl RPM "/usr/local/share/xsl/docbook", #default for FreeBSD textproc/docbook-xsl port ] DOCBOOK_DIR = None for dir in dirs: if os.path.isdir(dir): DOCBOOK_DIR = dir break DOCBOOK_DIR = os.environ.get(KEYNAME, DOCBOOK_DIR) if not DOCBOOK_DIR: tester.warning( "You need Norm Walsh's DocBook XSL stylesheet package for this test.\n" "You can either ignore this, or you can install the DocBook XSL\n" "stylesheets and re-run this test. Get the docbook-xsl package from\n" "http://sourceforge.net/project/showfiles.php?group_id=21935\n" "Install it in anywhere, and then before running this test, set\n" "the environment variable %r to the absolute path\n" "of the docbook-xsl-#.#.# directory on your filesystem.\n" % KEYNAME) tester.testDone() return if not os.path.isdir(DOCBOOK_DIR): tester.warning("Unable to find DocBook stylesheet directory %r" % DOCBOOK_DIR) tester.testDone() return VERSION_FILE = os.path.join(DOCBOOK_DIR, 'VERSION') if os.path.isfile(VERSION_FILE): VERSION = open(VERSION_FILE).read() match = re.search(r'>\s*(\d[.0-9]+)\s*<', VERSION) if not match: tester.warning("Unable to determine version of DocBook stylesheets\n" "Format of %r unrecognized." % VERSION_FILE) tester.testDone() return version = match.group(1) if version <= MIN_VERSION: tester.warning("DocBook XSL version %s or higher needed;" " version %s found." % (MIN_VERSION, version)) tester.testDone() return else: tester.warning("Unable to determine version of DocBook stylesheets\n" "Was looking for file %r." % VERSION_FILE) tester.testDone() return STYLESHEET = os.path.join(DOCBOOK_DIR, 'html', 'docbook.xsl') if not os.path.isfile(STYLESHEET): tester.warning("Unable to find DocBook stylesheet %r" % STYLESHEET) tester.testDone() return STYLESHEET_URI = OsPathToUri(STYLESHEET) tester.testDone() source = test_harness.FileInfo(string=source_1) if version >= '1.68': expected = expected_1_1680 % version else: expected = expected_1 % version sheet = test_harness.FileInfo(uri=STYLESHEET_URI) test_harness.XsltTest(tester, source, [sheet], expected, title="Basic DocBook XSL processing") return