diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2019-07-24 09:57:09 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2019-07-24 09:57:09 +0200 |
commit | c7665433b2004d2b404d6fb9d6fd064998486f63 (patch) | |
tree | 8525ef6d24f7c6ceb238945ebb2cc997c7afc905 /site_scons/soe_utils.py | |
parent | e48d2727885efda8369c7edbc2e3929a59532adc (diff) | |
parent | 6e228c305122f0564eda1e67d56651f8386d24d7 (diff) |
Merge branch 'release/debian/3.1.0+repack-1'debian/3.1.0+repack-1
Diffstat (limited to 'site_scons/soe_utils.py')
-rw-r--r-- | site_scons/soe_utils.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/site_scons/soe_utils.py b/site_scons/soe_utils.py new file mode 100644 index 0000000..3b87dee --- /dev/null +++ b/site_scons/soe_utils.py @@ -0,0 +1,34 @@ +import os.path +import re + +from SCons.Script import Builder, Action, Scanner + +def soelim(target, source, env): + """ + Interpolate files included in [gnt]roff source files using the + .so directive. + + This behaves somewhat like the soelim(1) wrapper around groff, but + makes us independent of whether the actual underlying implementation + includes an soelim() command or the corresponding command-line option + to groff(1). The key behavioral difference is that this doesn't + recursively include .so files from the include file. Not yet, anyway. + """ + t = str(target[0]) + s = str(source[0]) + dir, f = os.path.split(s) + with open(t, 'w') as tfp, open(s, 'r') as sfp: + for line in sfp.readlines(): + if line[:4] in ['.so ', "'so "]: + sofile = os.path.join(dir, line[4:-1]) + with open(sofile, 'r') as f: + tfp.write(f.read()) + else: + tfp.write(line) + +def soscan(node, env, path): + c = node.get_text_contents() + return re.compile(r"^[\.']so\s+(\S+)", re.M).findall(c) + +soelimbuilder = Builder(action = Action(soelim), + source_scanner = Scanner(soscan)) |