tg2env-patch 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/python
  2. import os
  3. import sys
  4. # Go to parent folder
  5. def usage():
  6. print('')
  7. print('USAGE: '+__file__+' <virtualenv_folder_path>')
  8. print('')
  9. print('')
  10. def show_help_and_exit():
  11. usage()
  12. exit()
  13. def on_result_and_exit(error_code):
  14. if error_code==0:
  15. print('')
  16. print('')
  17. exit(0)
  18. print('ERRROR')
  19. print('')
  20. print('')
  21. exit(error_code)
  22. #######
  23. if len(sys.argv)<=1:
  24. show_help_and_exit()
  25. ########################################
  26. #
  27. # BELOW ARE STANDARD ACTIONS
  28. #
  29. ########################################
  30. tg2env_path = sys.argv[1]
  31. print('PATCHING PYTHON CODE')
  32. print('--------------------')
  33. print('tg2env path: %s'%(tg2env_path))
  34. print('')
  35. patchable_paths = [
  36. tg2env_path+'/lib/python3*/site-packages/tgext/pluggable',
  37. tg2env_path+'/lib/python3*/site-packages/resetpassword',
  38. tg2env_path+'/lib/python3*/site-packages/babel'
  39. ]
  40. for patchable_path in patchable_paths:
  41. print('2to3 conversion for %s...' % (patchable_path))
  42. os.system('2to3 -w %s'%(patchable_path))
  43. print('-> done')
  44. babel_source_code_patch_content = """--- tg2env/lib/python3.2/site-packages/babel/messages/pofile.py 2014-11-07 15:35:14.039913184 +0100
  45. +++ tg2env/lib/python3.2/site-packages/babel/messages/pofile.py 2014-10-30 17:37:36.295091573 +0100
  46. @@ -384,8 +384,13 @@
  47. def _write(text):
  48. if isinstance(text, text_type):
  49. - text = text.encode(catalog.charset, 'backslashreplace')
  50. - fileobj.write(text)
  51. + pass
  52. + # text = text.encode(catalog.charset, 'backslashreplace')
  53. + try:
  54. + fileobj.write(text.encode('UTF-8'))
  55. + except Exception as e:
  56. + fileobj.write(text)
  57. +
  58. def _write_comment(comment, prefix=''):
  59. # xgettext always wraps comments even if --no-wrap is passed;
  60. """
  61. babel_patchable_file_path = tg2env_path+'/lib/python*/site-packages/babel/messages/pofile.py'
  62. print('Patching code in file %s...'%(babel_patchable_file_path))
  63. os.system('echo "%s"|patch -p1 %s'%(babel_source_code_patch_content, babel_patchable_file_path))
  64. print('-> done')
  65. resetpassword_patchable_file_path = tg2env_path+'/lib/python*/site-packages/resetpassword/lib/__init__.py'
  66. print('Patching code in file %s...'%(resetpassword_patchable_file_path))
  67. os.system("sed -i 's/body\.encode/body/g' %s" % (resetpassword_patchable_file_path))
  68. print('-> done')
  69. print('')
  70. print('')