wintest: set recursive queries for internal dns
[Samba.git] / buildtools / wafadmin / py3kfixes.py
blob2f3c9c29776548171dd2eae6a16ffb0e6a79e0e8
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Thomas Nagy, 2009 (ita)
5 """
6 Fixes for py3k go here
7 """
9 import os
11 all_modifs = {}
13 def modif(dir, name, fun):
14 if name == '*':
15 lst = []
16 for y in '. Tools 3rdparty'.split():
17 for x in os.listdir(os.path.join(dir, y)):
18 if x.endswith('.py'):
19 lst.append(y + os.sep + x)
20 #lst = [y + os.sep + x for x in os.listdir(os.path.join(dir, y)) for y in '. Tools 3rdparty'.split() if x.endswith('.py')]
21 for x in lst:
22 modif(dir, x, fun)
23 return
25 filename = os.path.join(dir, name)
26 f = open(filename, 'r')
27 txt = f.read()
28 f.close()
30 txt = fun(txt)
32 f = open(filename, 'w')
33 f.write(txt)
34 f.close()
36 def subst(filename):
37 def do_subst(fun):
38 global all_modifs
39 try:
40 all_modifs[filename] += fun
41 except KeyError:
42 all_modifs[filename] = [fun]
43 return fun
44 return do_subst
46 @subst('Constants.py')
47 def r1(code):
48 code = code.replace("'iluvcuteoverload'", "b'iluvcuteoverload'")
49 code = code.replace("ABI=7", "ABI=37")
50 return code
52 @subst('Tools/ccroot.py')
53 def r2(code):
54 code = code.replace("p.stdin.write('\\n')", "p.stdin.write(b'\\n')")
55 code = code.replace('p.communicate()[0]', 'p.communicate()[0].decode("utf-8")')
56 return code
58 @subst('Utils.py')
59 def r3(code):
60 code = code.replace("m.update(str(lst))", "m.update(str(lst).encode())")
61 code = code.replace('p.communicate()[0]', 'p.communicate()[0].decode("utf-8")')
62 return code
64 @subst('ansiterm.py')
65 def r33(code):
66 code = code.replace('unicode', 'str')
67 return code
69 @subst('Task.py')
70 def r4(code):
71 code = code.replace("up(self.__class__.__name__)", "up(self.__class__.__name__.encode())")
72 code = code.replace("up(self.env.variant())", "up(self.env.variant().encode())")
73 code = code.replace("up(x.parent.abspath())", "up(x.parent.abspath().encode())")
74 code = code.replace("up(x.name)", "up(x.name.encode())")
75 code = code.replace('class TaskBase(object):\n\t__metaclass__=store_task_type', 'import binascii\n\nclass TaskBase(object, metaclass=store_task_type):')
76 code = code.replace('keys=self.cstr_groups.keys()', 'keys=list(self.cstr_groups.keys())')
77 code = code.replace("sig.encode('hex')", 'binascii.hexlify(sig)')
78 code = code.replace("os.path.join(Options.cache_global,ssig)", "os.path.join(Options.cache_global,ssig.decode())")
79 return code
81 @subst('Build.py')
82 def r5(code):
83 code = code.replace("cPickle.dump(data,file,-1)", "cPickle.dump(data,file)")
84 code = code.replace('for node in src_dir_node.childs.values():', 'for node in list(src_dir_node.childs.values()):')
85 return code
87 @subst('*')
88 def r6(code):
89 code = code.replace('xrange', 'range')
90 code = code.replace('iteritems', 'items')
91 code = code.replace('maxint', 'maxsize')
92 code = code.replace('iterkeys', 'keys')
93 code = code.replace('Error,e:', 'Error as e:')
94 code = code.replace('Exception,e:', 'Exception as e:')
95 return code
97 @subst('TaskGen.py')
98 def r7(code):
99 code = code.replace('class task_gen(object):\n\t__metaclass__=register_obj', 'class task_gen(object, metaclass=register_obj):')
100 return code
102 @subst('Tools/python.py')
103 def r8(code):
104 code = code.replace('proc.communicate()[0]', 'proc.communicate()[0].decode("utf-8")')
105 return code
107 @subst('Tools/glib2.py')
108 def r9(code):
109 code = code.replace('f.write(c)', 'f.write(c.encode("utf-8"))')
110 return code
112 @subst('Tools/config_c.py')
113 def r10(code):
114 code = code.replace("key=kw['success']", "key=kw['success']\n\t\t\t\ttry:\n\t\t\t\t\tkey=key.decode('utf-8')\n\t\t\t\texcept:\n\t\t\t\t\tpass")
115 code = code.replace('out=str(out)','out=out.decode("utf-8")')
116 code = code.replace('err=str(err)','err=err.decode("utf-8")')
117 return code
119 @subst('Tools/d.py')
120 def r11(code):
121 code = code.replace('ret.strip()', 'ret.strip().decode("utf-8")')
122 return code
124 def fixdir(dir):
125 global all_modifs
126 for k in all_modifs:
127 for v in all_modifs[k]:
128 modif(os.path.join(dir, 'wafadmin'), k, v)
129 #print('substitutions finished')