9 quoted_string_re = re.compile(r"'([^']*)'", re.M)
11 def gnuplot_scan(node, env, path, arg=None):
13 >>> this_dir = os.path.dirname(__file__)
14 >>> src_dir = os.path.join(this_dir, '..', '..', 'src')
15 >>> class node (object):
16 ... def __init__(self, path):
18 ... self.abspath = os.path.abspath(self.path)
19 ... if os.path.isfile(self.path):
20 ... self.dir = node(os.path.dirname(path))
21 ... def get_text_contents(self):
22 ... return open(self.path, 'r').read()
23 ... def get_contents(self):
24 ... return self.get_text_contents()
25 ... def srcnode(self):
27 >>> for p in gnuplot_scan(
28 ... node(os.path.join(src_dir, 'figures', 'order-dep', 'fig.gp')),
29 ... None, None, None):
40 contents = node.get_text_contents()
41 except AttributeError:
42 contents = node.get_contents() # for older versions of SCons, fall back on binary read
44 for string in quoted_string_re.findall(contents):
45 p = os.path.join(node.dir.srcnode().abspath, string)
46 if len(string) > 0 and \
47 ((string not in ret and os.path.exists(p))
48 or string.endswith('.dat')):
55 """Add Builders and construction variables for Gnuplot to an Environment."""
57 if GnuplotAction is None:
58 GnuplotAction = SCons.Action.Action('$GNUPLOTCOM', '$GNUPLOTCOMSTR')
63 env['BUILDERS']['Gnuplot'] = SCons.Script.Builder(
64 action=GnuplotAction, suffix='.pdf', src_suffix = '.gp')
65 env['GNUPLOT'] = 'gnuplot'
66 env['GNUPLOTFLAGS'] = '' #SCons.Util.CLVar('')
67 env['GNUPLOTCOM'] = 'cd ${TARGET.dir} && $GNUPLOT $GNUPLOTFLAGS ${SOURCE.file}'
68 env.Append(SCANNERS=SCons.Scanner.Base(
69 function=gnuplot_scan,
74 return env.Detect('gnuplot')
76 if __name__ == '__main__':