3 # Thomas Nagy, 2009 (ita)
13 def modif(dir, name
, fun
):
16 for y
in '. Tools 3rdparty'.split():
17 for x
in os
.listdir(os
.path
.join(dir, y
)):
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')]
25 filename
= os
.path
.join(dir, name
)
26 f
= open(filename
, 'r')
32 f
= open(filename
, 'w')
40 all_modifs
[filename
] += fun
42 all_modifs
[filename
] = [fun
]
46 @subst('Constants.py')
48 code
= code
.replace("'iluvcuteoverload'", "b'iluvcuteoverload'")
49 code
= code
.replace("ABI=7", "ABI=37")
52 @subst('Tools/ccroot.py')
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")')
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")')
66 code
= code
.replace('unicode', 'str')
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())")
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()):')
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:')
99 code
= code
.replace('class task_gen(object):\n\t__metaclass__=register_obj', 'class task_gen(object, metaclass=register_obj):')
102 @subst('Tools/python.py')
104 code
= code
.replace('proc.communicate()[0]', 'proc.communicate()[0].decode("utf-8")')
107 @subst('Tools/glib2.py')
109 code
= code
.replace('f.write(c)', 'f.write(c.encode("utf-8"))')
112 @subst('Tools/config_c.py')
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")')
121 code
= code
.replace('ret.strip()', 'ret.strip().decode("utf-8")')
127 for v
in all_modifs
[k
]:
128 modif(os
.path
.join(dir, 'wafadmin'), k
, v
)
129 #print('substitutions finished')