michael@0: #!/usr/bin/env python michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: michael@0: """ michael@0: Fix references to source files of the form [LOCpath] michael@0: so that they are relative to a given source directory. michael@0: michael@0: Substitute the DOT-generated image map into the document. michael@0: """ michael@0: michael@0: import os, sys, re michael@0: michael@0: (srcdir, ) = sys.argv[1:] michael@0: srcdir = os.path.realpath(srcdir) michael@0: michael@0: f = re.compile(r'\[LOC(.*?)\]') michael@0: michael@0: def replacer(m): michael@0: file = m.group(1) michael@0: file = os.path.realpath(file) michael@0: if not file.startswith(srcdir): michael@0: raise Exception("File %s doesn't start with %s" % (file, srcdir)) michael@0: michael@0: file = file[len(srcdir) + 1:] michael@0: return file michael@0: michael@0: s = re.compile(r'\[MAP(.*?)\]') michael@0: michael@0: def mapreplace(m): michael@0: file = m.group(1) michael@0: c = open(file).read() michael@0: return c michael@0: michael@0: for line in sys.stdin: michael@0: line = f.sub(replacer, line) michael@0: line = s.sub(mapreplace, line) michael@0: michael@0: sys.stdout.write(line)