tg2env-patch 2.6KB

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