|
Packit |
c749ee |
#!/usr/bin/env python
|
|
Packit |
c749ee |
# -*- coding: ISO-8859-1 -*-
|
|
Packit |
c749ee |
#
|
|
Packit |
c749ee |
# dblatex python setup script - See the COPYRIGHT
|
|
Packit |
c749ee |
#
|
|
Packit |
c749ee |
from __future__ import print_function
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
import os
|
|
Packit |
c749ee |
import sys
|
|
Packit |
c749ee |
import re
|
|
Packit |
c749ee |
import glob
|
|
Packit |
c749ee |
import subprocess
|
|
Packit |
c749ee |
from io import open
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
try:
|
|
Packit |
c749ee |
from setuptools import setup
|
|
Packit |
c749ee |
from setuptools.command.install import install
|
|
Packit |
c749ee |
except ImportError:
|
|
Packit |
c749ee |
from distutils.core import setup
|
|
Packit |
c749ee |
from distutils.command.install import install
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
from distutils.command.build import build
|
|
Packit |
c749ee |
from distutils.command.build_scripts import build_scripts
|
|
Packit |
c749ee |
from distutils.command.install_data import install_data
|
|
Packit |
c749ee |
from distutils.command.sdist import sdist
|
|
Packit |
c749ee |
from distutils import log
|
|
Packit |
c749ee |
from subprocess import Popen, PIPE
|
|
Packit |
c749ee |
sys.path.append("lib")
|
|
Packit |
c749ee |
#from contrib.debian.installer import DebianInstaller
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
#
|
|
Packit |
c749ee |
# Build the command line script
|
|
Packit |
c749ee |
#
|
|
Packit |
c749ee |
class BuildScripts(build_scripts):
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
SHELL_SCRIPT = """#!%(env_executable)s%(env_args)s%(py_executable)s
|
|
Packit |
c749ee |
import sys
|
|
Packit |
c749ee |
import os
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
package_base = %(package_base)s
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
%(lib_path)s
|
|
Packit |
c749ee |
%(catalogs)s
|
|
Packit |
c749ee |
%(style_set)s
|
|
Packit |
c749ee |
from %(package_path)s import %(package)s
|
|
Packit |
c749ee |
%(package)s.main(base=package_base)
|
|
Packit |
c749ee |
"""
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
CATALOGS = """cat = os.environ.get("SGML_CATALOG_FILES")
|
|
Packit |
c749ee |
if cat:
|
|
Packit |
c749ee |
cat += ":%s"
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
cat = "%s"
|
|
Packit |
c749ee |
os.environ["SGML_CATALOG_FILES"] = cat
|
|
Packit |
c749ee |
"""
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def run(self):
|
|
Packit |
c749ee |
"""
|
|
Packit |
c749ee |
Create the proper script for the current platform.
|
|
Packit |
c749ee |
"""
|
|
Packit |
c749ee |
if not self.scripts:
|
|
Packit |
c749ee |
return
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# The script can only work with package data
|
|
Packit |
c749ee |
self.data_files = self.distribution.data_files
|
|
Packit |
c749ee |
if not(self.data_files):
|
|
Packit |
c749ee |
return
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if self.dry_run:
|
|
Packit |
c749ee |
return
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Ensure the destination directory exists
|
|
Packit |
c749ee |
self.mkpath(self.build_dir)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Data useful for building the script
|
|
Packit |
c749ee |
install = self.distribution.get_command_obj("install")
|
|
Packit |
c749ee |
if not(install.install_data):
|
|
Packit |
c749ee |
return
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
self._install_lib = os.path.normpath(install.install_lib)
|
|
Packit |
c749ee |
self._root = install.root
|
|
Packit |
c749ee |
if self._root:
|
|
Packit |
c749ee |
self._root = os.path.normpath(self._root)
|
|
Packit |
c749ee |
self._package_base = os.path.join(install.install_data,
|
|
Packit |
c749ee |
self.data_files[0][0])
|
|
Packit |
c749ee |
self._catalogs = install.catalogs
|
|
Packit |
c749ee |
self._style = install.style
|
|
Packit |
c749ee |
self._use_py_path = install.use_python_path
|
|
Packit |
c749ee |
print(self._package_base)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Build the command line script
|
|
Packit |
c749ee |
self.build_script()
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def _strip_root(self, *paths):
|
|
Packit |
c749ee |
if not(self._root):
|
|
Packit |
c749ee |
return paths
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
newpaths = []
|
|
Packit |
c749ee |
for path in paths:
|
|
Packit |
c749ee |
if path.startswith(self._root):
|
|
Packit |
c749ee |
newpaths.append(path[len(self._root):])
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
newpaths.append(path)
|
|
Packit |
c749ee |
return newpaths
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def build_script(self):
|
|
Packit |
c749ee |
script_name = self.scripts[0]
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# prepare args for the bang path at the top of the script
|
|
Packit |
c749ee |
ENV_BIN = '/usr/bin/env'
|
|
Packit |
c749ee |
env_args = ''
|
|
Packit |
c749ee |
if self._use_py_path:
|
|
Packit |
c749ee |
env_exec = ''
|
|
Packit |
c749ee |
py_exec = sys.executable
|
|
Packit |
c749ee |
elif os.name == 'posix':
|
|
Packit |
c749ee |
# Some Solaris platforms may not have an 'env' binary.
|
|
Packit |
c749ee |
# If /usr/bin/env exists, use '#!/usr/bin/env python'
|
|
Packit |
c749ee |
# otherwise, use '#!' + sys.executable
|
|
Packit |
c749ee |
env_exec = os.path.isfile(ENV_BIN) and \
|
|
Packit |
c749ee |
os.access(ENV_BIN, os.X_OK) and ENV_BIN or ''
|
|
Packit |
c749ee |
py_exec = env_exec and 'python' or sys.executable
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
# shouldn't matter on non-POSIX; we'll just use defaults
|
|
Packit |
c749ee |
env_exec = ENV_BIN
|
|
Packit |
c749ee |
py_exec = 'python'
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Retrieve actual installation paths
|
|
Packit |
c749ee |
lib_path, package_base = self._strip_root(self._install_lib,
|
|
Packit |
c749ee |
self._package_base)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Just help for non standard installation paths
|
|
Packit |
c749ee |
if lib_path in sys.path:
|
|
Packit |
c749ee |
lib_path = ""
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
lib_path = "sys.path.append(r\"%s\")" % lib_path
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Things to adapt when building an egg
|
|
Packit |
c749ee |
if "/egg" in lib_path:
|
|
Packit |
c749ee |
lib_path = ""
|
|
Packit |
c749ee |
package_base = 'os.path.abspath(os.path.join(os.path.dirname('\
|
|
Packit |
c749ee |
'__file__), "..", "..", "share", "dblatex"))'
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
package_base = 'r"%s"' % (package_base)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if self._catalogs:
|
|
Packit |
c749ee |
catalogs = self.CATALOGS % (self._catalogs, self._catalogs)
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
catalogs = ""
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if self._style:
|
|
Packit |
c749ee |
style_set = "sys.argv.insert(1, '-T%s')" % self._style
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
style_set = ""
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
script_args = { 'env_executable': env_exec,
|
|
Packit |
c749ee |
'env_args': env_exec and (' %s' % env_args) or '',
|
|
Packit |
c749ee |
'py_executable': py_exec,
|
|
Packit |
c749ee |
'lib_path': lib_path,
|
|
Packit |
c749ee |
'style_set': style_set,
|
|
Packit |
c749ee |
'package': "dblatex",
|
|
Packit |
c749ee |
'package_path': "dbtexmf.dblatex",
|
|
Packit |
c749ee |
'catalogs': catalogs,
|
|
Packit |
c749ee |
'package_base': package_base }
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
script = self.SHELL_SCRIPT % script_args
|
|
Packit |
c749ee |
script_name = os.path.basename(script_name)
|
|
Packit |
c749ee |
outfile = os.path.join(self.build_dir, script_name)
|
|
Packit |
c749ee |
fd = os.open(outfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0o755)
|
|
Packit |
c749ee |
os.write(fd, script.encode('ascii'))
|
|
Packit |
c749ee |
os.close(fd)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
class Build(build):
|
|
Packit |
c749ee |
"""
|
|
Packit |
c749ee |
Build the documentation if missing or required to rebuild
|
|
Packit |
c749ee |
"""
|
|
Packit |
c749ee |
user_options = build.user_options + \
|
|
Packit |
c749ee |
[('docbook-xsl=', None,
|
|
Packit |
c749ee |
'DocBook Project Stylesheet base directory (build_doc)')]
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def initialize_options(self):
|
|
Packit |
c749ee |
build.initialize_options(self)
|
|
Packit |
c749ee |
self.docbook_xsl = None
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def run(self):
|
|
Packit |
c749ee |
# Do the default tasks
|
|
Packit |
c749ee |
build.run(self)
|
|
Packit |
c749ee |
# And build the doc
|
|
Packit |
c749ee |
self.build_doc()
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def build_doc(self):
|
|
Packit |
c749ee |
log.info("running build_doc")
|
|
Packit |
c749ee |
htmldir = os.path.join("docs", "xhtml")
|
|
Packit |
c749ee |
pdfdocs = glob.glob(os.path.join("docs", "[mr]*.pdf"))
|
|
Packit |
c749ee |
manpage = os.path.join("docs", "manpage", "dblatex.1.gz")
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Lazy check to avoid a rebuild for nothing
|
|
Packit |
c749ee |
if (not(self.force) and os.path.exists(htmldir) and len(pdfdocs) >= 2
|
|
Packit |
c749ee |
and os.path.exists(manpage)):
|
|
Packit |
c749ee |
return
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Assumes that make is the GNU make
|
|
Packit |
c749ee |
cmd = ["make", "-C", "docs", "VERSION=%s" % (get_version())]
|
|
Packit |
c749ee |
if self.docbook_xsl:
|
|
Packit |
c749ee |
cmd.append("XSLDBK=%s" % os.path.abspath(self.docbook_xsl))
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
subprocess.call(cmd)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def find_programs(utils):
|
|
Packit |
c749ee |
sys.path.append("lib")
|
|
Packit |
c749ee |
from contrib.which import which
|
|
Packit |
c749ee |
util_paths = {}
|
|
Packit |
c749ee |
missed = []
|
|
Packit |
c749ee |
for util in utils:
|
|
Packit |
c749ee |
try:
|
|
Packit |
c749ee |
path = which.which(util)
|
|
Packit |
c749ee |
util_paths[util] = path
|
|
Packit |
c749ee |
except which.WhichError:
|
|
Packit |
c749ee |
missed.append(util)
|
|
Packit |
c749ee |
sys.path.remove("lib")
|
|
Packit |
c749ee |
return (util_paths, missed)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def kpsewhich(tex_file):
|
|
Packit |
c749ee |
if os.name == "nt":
|
|
Packit |
c749ee |
close_fds = False
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
close_fds = True
|
|
Packit |
c749ee |
p = Popen("kpsewhich %s" % tex_file, shell=True,
|
|
Packit |
c749ee |
stdin=PIPE, stdout=PIPE, close_fds=close_fds)
|
|
Packit |
c749ee |
data = p.communicate()[0]
|
|
Packit |
c749ee |
if isinstance(data, bytes):
|
|
Packit |
c749ee |
data = data.decode(sys.getdefaultencoding())
|
|
Packit |
c749ee |
return data.strip()
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
class Sdist(sdist):
|
|
Packit |
c749ee |
"""
|
|
Packit |
c749ee |
Make the source package, and remove the .pyc files
|
|
Packit |
c749ee |
"""
|
|
Packit |
c749ee |
def prune_file_list(self):
|
|
Packit |
c749ee |
sdist.prune_file_list(self)
|
|
Packit |
c749ee |
self.filelist.exclude_pattern(r'.*.pyc', is_regex=1)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
class Install(install):
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
user_options = install.user_options + \
|
|
Packit |
c749ee |
[('catalogs=', None, 'default SGML catalogs'),
|
|
Packit |
c749ee |
('nodeps', None, 'don\'t check the dependencies'),
|
|
Packit |
c749ee |
('style=', None, 'default style to use'),
|
|
Packit |
c749ee |
('use-python-path', None, 'don\'t use env to locate python')]
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def initialize_options(self):
|
|
Packit |
c749ee |
install.initialize_options(self)
|
|
Packit |
c749ee |
self.catalogs = None
|
|
Packit |
c749ee |
self.nodeps = None
|
|
Packit |
c749ee |
self.style = None
|
|
Packit |
c749ee |
self.use_python_path = None
|
|
Packit |
c749ee |
# Prevents from undefined 'install_layout' attribute
|
|
Packit |
c749ee |
if not(getattr(self, "install_layout", None)):
|
|
Packit |
c749ee |
self.install_layout = None
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def check_util_dependencies(self):
|
|
Packit |
c749ee |
# First, check non critical graphic tools
|
|
Packit |
c749ee |
found, missed = find_programs(("epstopdf", "convert", "fig2dev"))
|
|
Packit |
c749ee |
for util in found:
|
|
Packit |
c749ee |
print("+checking %s... yes" % util)
|
|
Packit |
c749ee |
for util in missed:
|
|
Packit |
c749ee |
print("+checking %s... no" % util)
|
|
Packit |
c749ee |
if missed:
|
|
Packit |
c749ee |
print(("warning: not found: %s" % ", ".join(missed)))
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Now, be serious
|
|
Packit |
c749ee |
found, missed = find_programs(("latex", "makeindex",
|
|
Packit |
c749ee |
"pdflatex", "kpsewhich"))
|
|
Packit |
c749ee |
for util in found:
|
|
Packit |
c749ee |
print("+checking %s... yes" % util)
|
|
Packit |
c749ee |
for util in missed:
|
|
Packit |
c749ee |
print("+checking %s... no" % util)
|
|
Packit |
c749ee |
if missed:
|
|
Packit |
c749ee |
raise OSError("not found: %s" % ", ".join(missed))
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def check_xslt_dependencies(self):
|
|
Packit |
c749ee |
sys.path.insert(0, "lib")
|
|
Packit |
c749ee |
from dbtexmf.xslt import xslt
|
|
Packit |
c749ee |
sys.path.remove("lib")
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# At least one XSLT must be available
|
|
Packit |
c749ee |
deplists = xslt.get_deplists()
|
|
Packit |
c749ee |
if not(deplists):
|
|
Packit |
c749ee |
raise OSError("no XSLT available")
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# For each XSLT check the programs they depend on
|
|
Packit |
c749ee |
xslt_found = []
|
|
Packit |
c749ee |
xslt_missed = []
|
|
Packit |
c749ee |
for (mod, deplist) in deplists:
|
|
Packit |
c749ee |
if not(deplist):
|
|
Packit |
c749ee |
xslt_found.append(mod)
|
|
Packit |
c749ee |
print("+checking XSLT %s... yes" % mod)
|
|
Packit |
c749ee |
continue
|
|
Packit |
c749ee |
found, missed = find_programs(deplist)
|
|
Packit |
c749ee |
if missed:
|
|
Packit |
c749ee |
xslt_missed.append(mod)
|
|
Packit |
c749ee |
print("+checking XSLT %s... no (missing %s)" % \
|
|
Packit |
c749ee |
(mod, ", ".join(missed)))
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
xslt_found.append(mod)
|
|
Packit |
c749ee |
print("+checking XSLT %s... yes" % mod)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if not(xslt_found):
|
|
Packit |
c749ee |
raise OSError("XSLT not installed: %s" % ", ".join(xslt_missed))
|
|
Packit |
c749ee |
elif xslt_missed:
|
|
Packit |
c749ee |
print("warning: XSLT not found: %s" % ", ".join(xslt_missed))
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def check_latex_dependencies(self):
|
|
Packit |
c749ee |
# Find the Latex files from the package
|
|
Packit |
c749ee |
stys = []
|
|
Packit |
c749ee |
for root, dirs, files in os.walk('latex/'):
|
|
Packit |
c749ee |
stys += glob.glob(os.path.join(root, "*.sty"))
|
|
Packit |
c749ee |
if stys:
|
|
Packit |
c749ee |
own_stys = [os.path.basename(s)[:-4] for s in stys]
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
own_stys = []
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Find the used packages
|
|
Packit |
c749ee |
used_stys = []
|
|
Packit |
c749ee |
re_sty = re.compile(r"\\usepackage\s*\[?.*\]?{(\w+)}")
|
|
Packit |
c749ee |
for sty in stys:
|
|
Packit |
c749ee |
f = open(sty, "rt", encoding="latin-1")
|
|
Packit |
c749ee |
for line in f:
|
|
Packit |
c749ee |
line = line.split("%")[0]
|
|
Packit |
c749ee |
m = re_sty.search(line)
|
|
Packit |
c749ee |
if m:
|
|
Packit |
c749ee |
p = m.group(1)
|
|
Packit |
c749ee |
try:
|
|
Packit |
c749ee |
used_stys.index(p)
|
|
Packit |
c749ee |
except:
|
|
Packit |
c749ee |
used_stys.append(p)
|
|
Packit |
c749ee |
f.close()
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Now look if they are found
|
|
Packit |
c749ee |
found_stys = []
|
|
Packit |
c749ee |
mis_stys = []
|
|
Packit |
c749ee |
used_stys.sort()
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Dirty...
|
|
Packit |
c749ee |
for f in ("truncate", "elfonts", "CJKutf8", "pinyin", "ifxetex"):
|
|
Packit |
c749ee |
try:
|
|
Packit |
c749ee |
used_stys.remove(f)
|
|
Packit |
c749ee |
except:
|
|
Packit |
c749ee |
pass
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
for sty in used_stys:
|
|
Packit |
c749ee |
if sty in found_stys:
|
|
Packit |
c749ee |
continue
|
|
Packit |
c749ee |
status = "+checking %s... " % sty
|
|
Packit |
c749ee |
if sty in own_stys:
|
|
Packit |
c749ee |
status += "found in package"
|
|
Packit |
c749ee |
found_stys.append(sty)
|
|
Packit |
c749ee |
print(status)
|
|
Packit |
c749ee |
continue
|
|
Packit |
c749ee |
stypath = kpsewhich("%s.sty" % sty)
|
|
Packit |
c749ee |
if stypath:
|
|
Packit |
c749ee |
status += "yes"
|
|
Packit |
c749ee |
found_stys.append(sty)
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
status += "no"
|
|
Packit |
c749ee |
mis_stys.append(sty)
|
|
Packit |
c749ee |
print(status)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if mis_stys:
|
|
Packit |
c749ee |
raise OSError("not found: %s" % ", ".join(mis_stys))
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def run(self):
|
|
Packit |
c749ee |
# if self.install_layout == "deb":
|
|
Packit |
c749ee |
# db = DebianInstaller(self)
|
|
Packit |
c749ee |
# else:
|
|
Packit |
c749ee |
db = None
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if not(db) and not(self.nodeps):
|
|
Packit |
c749ee |
try:
|
|
Packit |
c749ee |
self.check_xslt_dependencies()
|
|
Packit |
c749ee |
self.check_util_dependencies()
|
|
Packit |
c749ee |
self.check_latex_dependencies()
|
|
Packit |
c749ee |
except Exception as e:
|
|
Packit |
c749ee |
print("Error: %s" % e, file=sys.stderr)
|
|
Packit |
c749ee |
sys.exit(1)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if db: db.adapt_paths()
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# If no build is required, at least build the script
|
|
Packit |
c749ee |
if self.skip_build:
|
|
Packit |
c749ee |
self.run_command('build_scripts')
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
install.run(self)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if db: db.finalize()
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
class InstallData(install_data):
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def run(self):
|
|
Packit |
c749ee |
ignore_pattern = os.path.sep + r"(CVS|RCS)" + os.path.sep
|
|
Packit |
c749ee |
# literal backslash must be doubled in regular expressions
|
|
Packit |
c749ee |
ignore_pattern = ignore_pattern.replace('\\', r'\\')
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Walk through sub-dirs, specified in data_files and build the
|
|
Packit |
c749ee |
# full data files list accordingly
|
|
Packit |
c749ee |
full_data_files = []
|
|
Packit |
c749ee |
for install_base, paths in self.data_files:
|
|
Packit |
c749ee |
base_files = []
|
|
Packit |
c749ee |
for path in paths:
|
|
Packit |
c749ee |
if os.path.isdir(path):
|
|
Packit |
c749ee |
pref = os.path.dirname(path)
|
|
Packit |
c749ee |
for root, dirs, files in os.walk(path):
|
|
Packit |
c749ee |
if re.search(ignore_pattern, root + os.sep):
|
|
Packit |
c749ee |
continue
|
|
Packit |
c749ee |
# Only the last directory is copied, not the full path
|
|
Packit |
c749ee |
if not(pref):
|
|
Packit |
c749ee |
iroot = root
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
iroot = root.split(pref + os.path.sep, 1)[1]
|
|
Packit |
c749ee |
idir = os.path.join(install_base, iroot)
|
|
Packit |
c749ee |
files = [os.path.join(root, i) for i in files]
|
|
Packit |
c749ee |
if files:
|
|
Packit |
c749ee |
full_data_files += [(idir, files)]
|
|
Packit |
c749ee |
else:
|
|
Packit |
c749ee |
base_files.append(path)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if base_files:
|
|
Packit |
c749ee |
full_data_files += [(install_base, base_files)]
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Replace synthetic data_files by the full one, and do the actual job
|
|
Packit |
c749ee |
self.data_files = full_data_files
|
|
Packit |
c749ee |
rc = install_data.run(self)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if self.distribution.get_command_obj("install").install_layout != "deb":
|
|
Packit |
c749ee |
self.adapt_installed_data()
|
|
Packit |
c749ee |
return rc
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def adapt_installed_data(self):
|
|
Packit |
c749ee |
installed = self.get_outputs()
|
|
Packit |
c749ee |
for data_file in installed:
|
|
Packit |
c749ee |
if os.path.basename(data_file) == "param.xsl":
|
|
Packit |
c749ee |
self._set_texlive_version(data_file)
|
|
Packit |
c749ee |
break
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def _set_texlive_version(self, param_file):
|
|
Packit |
c749ee |
"""Detect the installed Texlive version from hyperref.sty version, and
|
|
Packit |
c749ee |
override the texlive.version param accordingly."""
|
|
Packit |
c749ee |
hyper_sty = kpsewhich("hyperref.sty")
|
|
Packit |
c749ee |
if not(hyper_sty):
|
|
Packit |
c749ee |
# Cannot do anything, give up
|
|
Packit |
c749ee |
return
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Grab the value from package version
|
|
Packit |
c749ee |
d = open(hyper_sty, "rt", encoding="latin-1").read()
|
|
Packit |
c749ee |
m = re.search(r"\\ProvidesPackage{hyperref}\s+\[(\d+)", d, re.M)
|
|
Packit |
c749ee |
if not(m):
|
|
Packit |
c749ee |
return
|
|
Packit |
c749ee |
year = m.group(1)
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
# Patch the parameter with the found value
|
|
Packit |
c749ee |
p = open(param_file, "rt", encoding="latin-1").read()
|
|
Packit |
c749ee |
p2 = re.sub('name="texlive.version">.*<',
|
|
Packit |
c749ee |
'name="texlive.version">%s<' % year, p)
|
|
Packit |
c749ee |
f = open(param_file, "wt", encoding="latin-1")
|
|
Packit |
c749ee |
f.write(p2)
|
|
Packit |
c749ee |
f.close()
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
def get_version():
|
|
Packit |
c749ee |
sys.path.insert(0, "lib")
|
|
Packit |
c749ee |
from dbtexmf.dblatex import dblatex
|
|
Packit |
c749ee |
d = dblatex.DbLatex(base=os.getcwd())
|
|
Packit |
c749ee |
sys.path.remove("lib")
|
|
Packit |
c749ee |
return d.get_version()
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
if __name__ == "__main__":
|
|
Packit |
c749ee |
pdfdocs = glob.glob(os.path.join("docs", "[mr]*.pdf"))
|
|
Packit |
c749ee |
htmldoc = [os.path.join("docs", "xhtml")]
|
|
Packit |
c749ee |
classifiers = [
|
|
Packit |
c749ee |
"Operating System :: OS Independent",
|
|
Packit |
c749ee |
"Topic :: Text Processing :: Markup :: XML",
|
|
Packit |
c749ee |
"License :: OSI Approved :: GNU General Public License (GPL)"
|
|
Packit |
c749ee |
]
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
description = """
|
|
Packit |
c749ee |
dblatex is a program that transforms your SGML/XML DocBook documents to
|
|
Packit |
c749ee |
DVI, PostScript or PDF by translating them into pure LaTeX as a first
|
|
Packit |
c749ee |
process. MathML 2.0 markups are supported, too. It started as a clone
|
|
Packit |
c749ee |
of DB2LaTeX.
|
|
Packit |
c749ee |
"""
|
|
Packit |
c749ee |
|
|
Packit |
c749ee |
setup(name="dblatex",
|
|
Packit |
c749ee |
version=get_version(),
|
|
Packit |
c749ee |
description='DocBook to LaTeX/ConTeXt Publishing',
|
|
Packit |
c749ee |
author='Benoit Guillon',
|
|
Packit |
c749ee |
author_email='marsgui@users.sourceforge.net',
|
|
Packit |
c749ee |
url='http://dblatex.sf.net',
|
|
Packit |
c749ee |
license='GPL Version 2 or later',
|
|
Packit |
c749ee |
long_description=description,
|
|
Packit |
c749ee |
classifiers=classifiers,
|
|
Packit |
c749ee |
packages=['dbtexmf',
|
|
Packit |
c749ee |
'dbtexmf.core',
|
|
Packit |
c749ee |
'dbtexmf.xslt',
|
|
Packit |
c749ee |
'dbtexmf.dblatex',
|
|
Packit |
c749ee |
'dbtexmf.dblatex.xetex',
|
|
Packit |
c749ee |
'dbtexmf.dblatex.grubber'],
|
|
Packit |
c749ee |
package_dir={'dbtexmf':'lib/dbtexmf'},
|
|
Packit |
c749ee |
package_data={'dbtexmf.core':['sgmlent.txt'],
|
|
Packit |
c749ee |
'dbtexmf.dblatex.grubber':['xindylang.xml']},
|
|
Packit |
c749ee |
data_files=[('share/dblatex', ['xsl', 'latex', 'etc/schema']),
|
|
Packit |
c749ee |
('share/doc/dblatex', pdfdocs),
|
|
Packit |
c749ee |
('share/doc/dblatex', htmldoc),
|
|
Packit |
c749ee |
('share/man/man1', ['docs/manpage/dblatex.1.gz'])],
|
|
Packit |
c749ee |
scripts=['scripts/dblatex'],
|
|
Packit |
c749ee |
cmdclass={'build': Build,
|
|
Packit |
c749ee |
'build_scripts': BuildScripts,
|
|
Packit |
c749ee |
'install': Install,
|
|
Packit |
c749ee |
'install_data': InstallData,
|
|
Packit |
c749ee |
'sdist': Sdist}
|
|
Packit |
c749ee |
)
|
|
Packit |
c749ee |
|