jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.3KB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2010-2015 (ita)
  4. """
  5. burn a book, save a tree
  6. """
  7. import os
  8. all_modifs = {}
  9. def fixdir(dir):
  10. """call all the substitution functions on the waf folders"""
  11. global all_modifs
  12. for k in all_modifs:
  13. for v in all_modifs[k]:
  14. modif(os.path.join(dir, 'waflib'), k, v)
  15. def modif(dir, name, fun):
  16. """execute a substitution function"""
  17. if name == '*':
  18. lst = []
  19. for y in '. Tools extras'.split():
  20. for x in os.listdir(os.path.join(dir, y)):
  21. if x.endswith('.py'):
  22. lst.append(y + os.sep + x)
  23. for x in lst:
  24. modif(dir, x, fun)
  25. return
  26. filename = os.path.join(dir, name)
  27. f = open(filename, 'r')
  28. try:
  29. txt = f.read()
  30. finally:
  31. f.close()
  32. txt = fun(txt)
  33. f = open(filename, 'w')
  34. try:
  35. f.write(txt)
  36. finally:
  37. f.close()
  38. def subst(*k):
  39. """register a substitution function"""
  40. def do_subst(fun):
  41. global all_modifs
  42. for x in k:
  43. try:
  44. all_modifs[x].append(fun)
  45. except KeyError:
  46. all_modifs[x] = [fun]
  47. return fun
  48. 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 'iso8859-1')", '')
  54. code = code.replace('.encode()', '')
  55. return code
  56. @subst('Runner.py')
  57. def r4(code):
  58. "generator syntax"
  59. code = code.replace('next(self.biter)', 'self.biter.next()')
  60. return code