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