systemd/wscript: Adding wscript for systemd (detection of systemd user unit dir and...
[jack2.git] / waflib / fixpy2.py
blob24176e066455dda44ce77cac802182bdca4aa8b7
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Thomas Nagy, 2010-2018 (ita)
5 from __future__ import with_statement
7 import os
9 all_modifs = {}
11 def fixdir(dir):
12 """Call all substitution functions on Waf folders"""
13 for k in all_modifs:
14 for v in all_modifs[k]:
15 modif(os.path.join(dir, 'waflib'), k, v)
17 def modif(dir, name, fun):
18 """Call a substitution function"""
19 if name == '*':
20 lst = []
21 for y in '. Tools extras'.split():
22 for x in os.listdir(os.path.join(dir, y)):
23 if x.endswith('.py'):
24 lst.append(y + os.sep + x)
25 for x in lst:
26 modif(dir, x, fun)
27 return
29 filename = os.path.join(dir, name)
30 with open(filename, 'r') as f:
31 txt = f.read()
33 txt = fun(txt)
35 with open(filename, 'w') as f:
36 f.write(txt)
38 def subst(*k):
39 """register a substitution function"""
40 def do_subst(fun):
41 for x in k:
42 try:
43 all_modifs[x].append(fun)
44 except KeyError:
45 all_modifs[x] = [fun]
46 return fun
47 return do_subst
49 @subst('*')
50 def r1(code):
51 "utf-8 fixes for python < 2.6"
52 code = code.replace('as e:', ',e:')
53 code = code.replace(".decode(sys.stdout.encoding or'latin-1',errors='replace')", '')
54 return code.replace('.encode()', '')
56 @subst('Runner.py')
57 def r4(code):
58 "generator syntax"
59 return code.replace('next(self.biter)', 'self.biter.next()')
61 @subst('Context.py')
62 def r5(code):
63 return code.replace("('Execution failure: %s'%str(e),ex=e)", "('Execution failure: %s'%str(e),ex=e),None,sys.exc_info()[2]")