diff options
author | David Robillard <d@drobilla.net> | 2018-09-15 14:51:03 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-15 14:51:03 +0200 |
commit | b7a468132b987899b45ae6812e900f1eb11b056e (patch) | |
tree | dbaaa6ccea4d9663e64a605f3b6da4b83afc6177 /waflib/fixpy2.py | |
parent | 19bdb28bf8c8081bb47a41fc7c9e936434cc49d2 (diff) | |
parent | c2b0355b0de23f6ec83b5fa5be038bcce208e26f (diff) | |
download | sord-b7a468132b987899b45ae6812e900f1eb11b056e.tar.gz sord-b7a468132b987899b45ae6812e900f1eb11b056e.tar.bz2 sord-b7a468132b987899b45ae6812e900f1eb11b056e.zip |
Merge commit 'c2b0355b0de23f6ec83b5fa5be038bcce208e26f' as 'waflib'
Diffstat (limited to 'waflib/fixpy2.py')
-rw-r--r-- | waflib/fixpy2.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/waflib/fixpy2.py b/waflib/fixpy2.py new file mode 100644 index 0000000..24176e0 --- /dev/null +++ b/waflib/fixpy2.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# encoding: utf-8 +# Thomas Nagy, 2010-2018 (ita) + +from __future__ import with_statement + +import os + +all_modifs = {} + +def fixdir(dir): + """Call all substitution functions on Waf folders""" + for k in all_modifs: + for v in all_modifs[k]: + modif(os.path.join(dir, 'waflib'), k, v) + +def modif(dir, name, fun): + """Call a substitution function""" + 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: + txt = f.read() + + txt = fun(txt) + + with open(filename, 'w') as f: + f.write(txt) + +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:') + code = code.replace(".decode(sys.stdout.encoding or'latin-1',errors='replace')", '') + return code.replace('.encode()', '') + +@subst('Runner.py') +def r4(code): + "generator syntax" + return code.replace('next(self.biter)', 'self.biter.next()') + +@subst('Context.py') +def r5(code): + return code.replace("('Execution failure: %s'%str(e),ex=e)", "('Execution failure: %s'%str(e),ex=e),None,sys.exc_info()[2]") + |