5050 pytransform_bootstrap , encrypt_script , search_plugins , \
5151 get_product_key , register_keyfile , query_keyinfo , \
5252 get_platform_list , download_pytransform , update_pytransform ,\
53- check_cross_platform , compatible_platform_names
53+ check_cross_platform , compatible_platform_names , \
54+ get_name_suffix
5455
5556import packer
5657
@@ -181,6 +182,8 @@ def _build(args):
181182 capsule = build_path (project .capsule , pro_path )
182183 logging .info ('Use capsule: %s' , capsule )
183184
185+ suffix = get_name_suffix () if args .enable_suffix else ''
186+
184187 output = build_path (project .output , pro_path ) \
185188 if args .output is None else os .path .normpath (args .output )
186189 logging .info ('Output path is: %s' , output )
@@ -271,7 +274,7 @@ def v(t):
271274 wrap_mode = wrap_mode , adv_mode = vmode ,
272275 rest_mode = restrict , protection = pcode ,
273276 platforms = platforms , plugins = plugins ,
274- rpath = project .runtime_path )
277+ rpath = project .runtime_path , suffix = suffix )
275278
276279 logging .info ('%d scripts has been obfuscated' , len (files ))
277280 project ['build_time' ] = time .time ()
@@ -285,7 +288,8 @@ def v(t):
285288 relative = True if x == 3 else \
286289 False if (x == 2 or args .no_runtime ) else None
287290 make_entry (project .entry , project .src , soutput ,
288- rpath = project .runtime_path , relative = relative )
291+ rpath = project .runtime_path , relative = relative ,
292+ suffix = suffix )
289293
290294 if not args .no_runtime :
291295 routput = output if args .output is not None and args .only_runtime \
@@ -297,7 +301,8 @@ def v(t):
297301
298302 package = project .get ('package_runtime' , 0 ) \
299303 if args .package_runtime is None else args .package_runtime
300- make_runtime (capsule , routput , platforms = platforms , package = package )
304+ make_runtime (capsule , routput , platforms = platforms , package = package ,
305+ suffix = suffix )
301306
302307 if not restrict :
303308 licode = '*FLAGS:%c*CODE:PyArmor-Project' % chr (1 )
@@ -465,6 +470,8 @@ def _obfuscate(args):
465470 if os .path .abspath (output ) == path :
466471 raise RuntimeError ('Output path can not be same as src' )
467472
473+ suffix = get_name_suffix () if args .enable_suffix else ''
474+
468475 if args .recursive :
469476 logging .info ('Recursive mode is on' )
470477 pats = ['global-include *.py' ]
@@ -531,25 +538,27 @@ def _obfuscate(args):
531538 vmode = advanced | (8 if is_entry else 0 )
532539 encrypt_script (prokey , a , b , adv_mode = vmode , rest_mode = restrict ,
533540 protection = protection , platforms = platforms ,
534- plugins = plugins )
541+ plugins = plugins , suffix = suffix )
535542 logging .info ('%d scripts have been obfuscated' , len (files ))
536543
537544 if (not args .no_bootstrap ) and entry and os .path .exists (entry ):
538545 x = args .package_runtime
539546 relative = True if x == 3 else False if x == 2 else None
540547 entryname = entry if args .src else os .path .basename (entry )
541548 if os .path .exists (os .path .join (output , entryname )):
542- make_entry (entryname , path , output , relative = relative )
549+ make_entry (entryname , path , output , relative = relative ,
550+ suffix = suffix )
543551 else :
544552 logging .info ('Use outer entry script "%s"' , entry )
545- make_entry (entry , path , output , relative = relative )
553+ make_entry (entry , path , output , relative = relative ,
554+ suffix = suffix )
546555
547556 if args .no_runtime :
548557 logging .info ('Obfuscate %d scripts OK.' , len (files ))
549558 return
550559
551560 make_runtime (capsule , output , platforms = platforms ,
552- package = args .package_runtime )
561+ package = args .package_runtime , suffix = suffix )
553562
554563 logging .info ('Obfuscate scripts with restrict mode %s' ,
555564 'on' if args .restrict else 'off' )
@@ -697,8 +706,9 @@ def _runtime(args):
697706 output = os .path .join (args .output , name ) if args .inside else args .output
698707 package = not args .no_package
699708 platforms = compatible_platform_names (args .platforms )
709+ suffix = get_name_suffix () if args .enable_suffix else ''
700710 make_runtime (capsule , output , licfile = args .with_license ,
701- platforms = platforms , package = package )
711+ platforms = platforms , package = package , suffix = suffix )
702712
703713 filename = os .path .join (output , '__init__.py' ) if args .inside else \
704714 os .path .join (args .output , name + '.py' )
@@ -805,6 +815,8 @@ def _parser():
805815 'and how to make bootstrap code' )
806816 cparser .add_argument ('-n' , '--no-runtime' , action = 'store_true' ,
807817 help = 'DO NOT generate runtime files' )
818+ cparser .add_argument ('--enable-suffix' , action = 'store_true' ,
819+ help = 'Generate runtime package with unique name' )
808820 cparser .set_defaults (func = _obfuscate )
809821
810822 #
@@ -932,6 +944,8 @@ def _parser():
932944 cparser .add_argument ('--package-runtime' , choices = (0 , 1 , 2 , 3 ), type = int ,
933945 help = 'Where to save runtime files, '
934946 'and how to make bootstrap code' )
947+ cparser .add_argument ('--enable-suffix' , type = int , choices = (0 , 1 ),
948+ help = 'Generate runtime package with unique name' )
935949 cparser .set_defaults (func = _config )
936950
937951 #
@@ -1093,6 +1107,8 @@ def _parser():
10931107 action = 'append' ,
10941108 help = 'Generate runtime package for this platform, '
10951109 'use this option multiple times for more platforms' )
1110+ cparser .add_argument ('--enable-suffix' , action = 'store_true' ,
1111+ help = 'Generate runtime package with unique name' )
10961112 cparser .add_argument ('pkgname' , nargs = '?' , default = 'pytransform' ,
10971113 help = argparse .SUPPRESS )
10981114 cparser .set_defaults (func = _runtime )
0 commit comments