xpcom/analysis/fix-srcrefs.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/analysis/fix-srcrefs.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,41 @@
     1.4 +#!/usr/bin/env python
     1.5 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +
     1.9 +
    1.10 +"""
    1.11 +Fix references to source files of the form [LOCpath]
    1.12 +so that they are relative to a given source directory.
    1.13 +
    1.14 +Substitute the DOT-generated image map into the document.
    1.15 +"""
    1.16 +
    1.17 +import os, sys, re
    1.18 +
    1.19 +(srcdir, ) = sys.argv[1:]
    1.20 +srcdir = os.path.realpath(srcdir)
    1.21 +
    1.22 +f = re.compile(r'\[LOC(.*?)\]')
    1.23 +
    1.24 +def replacer(m):
    1.25 +    file = m.group(1)
    1.26 +    file = os.path.realpath(file)
    1.27 +    if not file.startswith(srcdir):
    1.28 +        raise Exception("File %s doesn't start with %s" % (file, srcdir))
    1.29 +
    1.30 +    file = file[len(srcdir) + 1:]
    1.31 +    return file
    1.32 +
    1.33 +s = re.compile(r'\[MAP(.*?)\]')
    1.34 +
    1.35 +def mapreplace(m):
    1.36 +    file = m.group(1)
    1.37 +    c = open(file).read()
    1.38 +    return c
    1.39 +
    1.40 +for line in sys.stdin:
    1.41 +    line = f.sub(replacer, line)
    1.42 +    line = s.sub(mapreplace, line)
    1.43 +
    1.44 +    sys.stdout.write(line)

mercurial