summaryrefslogtreecommitdiff
path: root/test/Docbook/basic/slideshtml/image/xsltver.py
blob: c8453249edfcf0f038a77f40874037642442c81c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
import re

def detectXsltVersion(fpath):
    """ Return a tuple with the version of the Docbook XSLT stylesheets,
        or (0, 0, 0) if no stylesheets are installed or the VERSION
        file couldn't be found/parsed correctly.
    """
    with open(os.path.join(fpath, 'VERSION'), 'rb') as fin:
        re_version = re.compile("<fm:Version>([^<]+)</fm:Version>".encode('utf-8'))
        m = re_version.search(fin.read())
        if m:
            try:
                return tuple(map(int, m.group(1).split(b'.')))
            except Exception:
                return (0, 0, 0)
            
        return (0, 0, 0)
        
    return (0, 0, 0)