s3: smbd: SMB2 close. If a file has delete on close, store the return info before...
[Samba.git] / buildtools / wafsamba / configure_file.py
blob8e2ba3bc23f1495efbfa1b18ddc9170729db9898
1 # handle substitution of variables in .in files
3 import Build, sys, Logs
4 from samba_utils import *
6 def subst_at_vars(task):
7 '''substiture @VAR@ style variables in a file'''
9 env = task.env
10 src = task.inputs[0].srcpath(env)
11 tgt = task.outputs[0].bldpath(env)
13 f = open(src, 'r')
14 s = f.read()
15 f.close()
16 # split on the vars
17 a = re.split('(@\w+@)', s)
18 out = []
19 for v in a:
20 if re.match('@\w+@', v):
21 vname = v[1:-1]
22 if not vname in task.env and vname.upper() in task.env:
23 vname = vname.upper()
24 if not vname in task.env:
25 Logs.error("Unknown substitution %s in %s" % (v, task.name))
26 sys.exit(1)
27 v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
28 out.append(v)
29 contents = ''.join(out)
30 f = open(tgt, 'w')
31 s = f.write(contents)
32 f.close()
33 return 0
35 def CONFIGURE_FILE(bld, in_file, **kwargs):
36 '''configure file'''
38 base=os.path.basename(in_file)
39 t = bld.SAMBA_GENERATOR('INFILE_%s' % base,
40 rule = subst_at_vars,
41 source = in_file + '.in',
42 target = in_file,
43 vars = kwargs)
44 Build.BuildContext.CONFIGURE_FILE = CONFIGURE_FILE