Description: Allow all data files to be moved to /usr/share/docutils/.
Author: Jakub Wilk <jwilk@debian.org>
Forwarded: not-needed
Last-Update: 2013-07-22

--- a/docutils/parsers/rst/directives/misc.py
+++ b/docutils/parsers/rst/directives/misc.py
@@ -10,6 +10,7 @@
 import os.path
 import re
 import time
+import docutils
 from docutils import io, nodes, statemachine, utils
 from docutils.utils.error_reporting import SafeString, ErrorString
 from docutils.utils.error_reporting import locale_encoding
@@ -47,7 +48,7 @@
                    'class': directives.class_option,
                    'name': directives.unchanged}
 
-    standard_include_path = os.path.join(os.path.dirname(states.__file__),
+    standard_include_path = os.path.join(docutils._datadir(states.__file__),
                                          'include')
 
     def run(self):
--- a/docutils/writers/html4css1/__init__.py
+++ b/docutils/writers/html4css1/__init__.py
@@ -44,13 +44,13 @@
 
     default_stylesheet = 'html4css1.css'
     default_stylesheet_dirs = ['.', utils.relative_path(
-        os.path.join(os.getcwd(), 'dummy'), os.path.dirname(__file__))]
+        os.path.join(os.getcwd(), 'dummy'), docutils._datadir(__file__))]
 
     default_template = 'template.txt'
 
     default_template_path = utils.relative_path(
         os.path.join(os.getcwd(), 'dummy'),
-        os.path.join(os.path.dirname(__file__), default_template))
+        os.path.join(docutils._datadir(__file__), default_template))
 
     settings_spec = (
         'HTML-Specific Options',
--- a/docutils/writers/latex2e/__init__.py
+++ b/docutils/writers/latex2e/__init__.py
@@ -23,6 +23,7 @@
     import roman
 except ImportError:
     import docutils.utils.roman as roman
+import docutils
 from docutils import frontend, nodes, languages, writers, utils, io
 from docutils.utils.error_reporting import SafeString
 from docutils.transforms import writer_aux
@@ -34,7 +35,7 @@
     """Formats this writer supports."""
 
     default_template = 'default.tex'
-    default_template_path = os.path.dirname(__file__)
+    default_template_path = docutils._datadir(__file__)
 
     default_preamble = '\n'.join([r'% PDF Standard Fonts',
                                   r'\usepackage{mathptmx} % Times',
--- a/docutils/writers/odf_odt/__init__.py
+++ b/docutils/writers/odf_odt/__init__.py
@@ -399,13 +399,13 @@
 
     default_stylesheet_path = utils.relative_path(
         os.path.join(os.getcwd(), 'dummy'),
-        os.path.join(os.path.dirname(__file__), default_stylesheet))
+        os.path.join(docutils._datadir(__file__), default_stylesheet))
 
     default_template = 'template.txt'
 
     default_template_path = utils.relative_path(
         os.path.join(os.getcwd(), 'dummy'),
-        os.path.join(os.path.dirname(__file__), default_template))
+        os.path.join(docutils._datadir(__file__), default_template))
 
     settings_spec = (
         'ODF-Specific Options',
--- a/docutils/writers/pep_html/__init__.py
+++ b/docutils/writers/pep_html/__init__.py
@@ -24,13 +24,13 @@
 
     default_stylesheet_path = utils.relative_path(
         os.path.join(os.getcwd(), 'dummy'),
-        os.path.join(os.path.dirname(__file__), default_stylesheet))
+        os.path.join(docutils._datadir(__file__), default_stylesheet))
 
     default_template = 'template.txt'
 
     default_template_path = utils.relative_path(
         os.path.join(os.getcwd(), 'dummy'),
-        os.path.join(os.path.dirname(__file__), default_template))
+        os.path.join(docutils._datadir(__file__), default_template))
 
     settings_spec = html4css1.Writer.settings_spec + (
         'PEP/HTML-Specific Options',
--- a/docutils/writers/s5_html/__init__.py
+++ b/docutils/writers/s5_html/__init__.py
@@ -21,7 +21,7 @@
 
 themes_dir_path = utils.relative_path(
     os.path.join(os.getcwd(), 'dummy'),
-    os.path.join(os.path.dirname(__file__), 'themes'))
+    os.path.join(docutils._datadir(__file__), 'themes'))
 
 def find_theme(name):
     # Where else to look for a theme?
--- a/docutils/__init__.py
+++ b/docutils/__init__.py
@@ -215,3 +215,18 @@
         a certain input context or output format.
         """
         return format in self.supported
+
+import os
+
+_debian_package = 0
+
+if _debian_package:
+    def _datadir(path):
+        dirname = os.path.dirname(path)
+        prefix = os.path.join(os.path.dirname(__file__), '') # _datadir
+        assert path.startswith(prefix), "%r doesn't start with %r" % (path, prefix)
+        suffix = dirname[len(prefix):]
+        return os.path.join('/usr/share/docutils/', suffix)
+else:
+    def _datadir(path):
+        return os.path.dirname(path)
--- a/test/test_parsers/test_rst/test_directives/test_include.py
+++ b/test/test_parsers/test_rst/test_directives/test_include.py
@@ -11,6 +11,7 @@
 import os.path
 import sys
 from __init__ import DocutilsTestSupport
+import docutils
 from docutils.parsers.rst import states
 from docutils._compat import b
 from docutils.utils.code_analyzer import with_pygments
@@ -45,7 +46,7 @@
     utf_16_error_str = ("UnicodeError: Unable to decode input data.  "
                         "Tried the following encodings: 'ascii'.\n"
                         "            (%s)" % utf_16_error_str)
-nonexistent = os.path.join(os.path.dirname(states.__file__),
+nonexistent = os.path.join(docutils._datadir(states.__file__),
                            'include', 'nonexistent')
 nonexistent_rel = DocutilsTestSupport.utils.relative_path(
     os.path.join(DocutilsTestSupport.testroot, 'dummy'), nonexistent)
