2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-11 04:38:59 +01:00
waf/waflib/fixpy2.py

65 lines
1.4 KiB
Python
Raw Normal View History

2011-09-10 11:13:51 +02:00
#!/usr/bin/env python
# encoding: utf-8
2018-01-01 20:53:49 +01:00
# Thomas Nagy, 2010-2018 (ita)
2011-09-10 11:13:51 +02:00
from __future__ import with_statement
2014-10-04 13:49:28 +02:00
import os
2011-09-10 11:13:51 +02:00
all_modifs = {}
def fixdir(dir):
2016-06-25 02:38:26 +02:00
"""Call all substitution functions on Waf folders"""
2011-09-10 11:13:51 +02:00
for k in all_modifs:
for v in all_modifs[k]:
modif(os.path.join(dir, 'waflib'), k, v)
def modif(dir, name, fun):
2016-06-25 02:38:26 +02:00
"""Call a substitution function"""
2011-09-10 11:13:51 +02:00
if name == '*':
lst = []
for y in '. Tools extras'.split():
for x in os.listdir(os.path.join(dir, y)):
if x.endswith('.py'):
lst.append(y + os.sep + x)
for x in lst:
modif(dir, x, fun)
return
filename = os.path.join(dir, name)
with open(filename, 'r') as f:
2012-05-19 09:45:57 +02:00
txt = f.read()
2011-09-10 11:13:51 +02:00
txt = fun(txt)
with open(filename, 'w') as f:
2012-05-19 09:45:57 +02:00
f.write(txt)
2011-09-10 11:13:51 +02:00
def subst(*k):
"""register a substitution function"""
def do_subst(fun):
for x in k:
try:
all_modifs[x].append(fun)
except KeyError:
all_modifs[x] = [fun]
return fun
return do_subst
@subst('*')
def r1(code):
"utf-8 fixes for python < 2.6"
code = code.replace('as e:', ',e:')
2017-01-21 13:28:06 +01:00
code = code.replace(".decode(sys.stdout.encoding or'latin-1',errors='replace')", '')
2016-02-28 14:23:54 +01:00
return code.replace('.encode()', '')
2011-09-10 11:13:51 +02:00
@subst('Runner.py')
def r4(code):
"generator syntax"
2016-02-28 14:23:54 +01:00
return code.replace('next(self.biter)', 'self.biter.next()')
@subst('Context.py')
2016-06-05 00:23:57 +02:00
def r5(code):
2016-02-28 14:23:54 +01:00
return code.replace("('Execution failure: %s'%str(e),ex=e)", "('Execution failure: %s'%str(e),ex=e),None,sys.exc_info()[2]")
2011-09-10 11:13:51 +02:00