1   
 2   
 3   
 4   
 5   
 6   
 7   
 8  """this module contains "freeze" functionality. 
 9   
10  It allows to create and distribute Py++ GUI as executable, that could be  
11  run without installing Python, pygccxml and Py++. 
12  """ 
13   
14  import os 
15  import sys 
16  import shutil 
17   
18 -def freeze_gui(source_dir, packages_dir, freeze_executable, target_dir):       
 19      target_name = 'demo' 
20      target_dir = os.path.join( target_dir, target_name, sys.platform ) 
21      if not os.path.exists( target_dir ): 
22          os.makedirs( target_dir ) 
23      if 'win32' == sys.platform: 
24          target_name = target_name + '.exe' 
25   
26      cmd = [ freeze_executable ] 
27      cmd.append( '--install-dir=%s' % target_dir ) 
28      cmd.append( '--target-name=%s' % target_name ) 
29      cmd.append( '--include-path=%s' % packages_dir ) 
30      cmd.append( os.path.join( source_dir, 'ui.py' ) ) 
31      cmd = ' '.join( cmd ) 
32   
33      input, output = os.popen4( cmd ) 
34      input.close() 
35      reports = [] 
36      while True: 
37          data = output.readline() 
38          reports.append( data ) 
39          if not data: 
40              break 
41      exit_status = output.close() 
42      msg = ''.join(reports) 
43      if exit_status: 
44          raise RuntimeError('unable to create executable. error: %s' % msg ) 
45   
46      if sys.platform == 'win32': 
47          dlls = os.path.join( os.path.split( sys.executable )[0], 'dlls' )         
48          files_to_copy = [ 'tk84.dll', 'tcl84.dll' ] 
49          for f in files_to_copy: 
50              shutil.copyfile( os.path.join( dlls, f ) 
51                               , os.path.join( target_dir, f ) ) 
52