11#!/usr/bin/env python
22
3- ##Copyright 2008-2011 Thomas Paviot (tpaviot@gmail.com)
3+ ##Copyright 2008-2013 Thomas Paviot (tpaviot@gmail.com)
44##
55##This file is part of pythonOCC.
66##
2020import sys
2121import os
2222import glob
23- # add the ./src directory to the sys.path list
24- sys .path .append (os .path .join (os .getcwd (),'wrapper' ))
23+
24+ sys .path .append (os .path .join (os .getcwd (), 'wrapper' ))
2525import SWIG_generator
2626import Modules
2727import environment
3737 MULTI_PROCESS_GENERATION = False
3838import time
3939
40+
4041def check_paths ():
4142 #
42- # Under WNT, modify Standard_Real.hxx so that it can be parsed by GCCXML without issue
43+ # Under WNT, modify Standard_Real.hxx so that it can be parsed by
44+ # GCCXML without issue
4345 #
4446 if sys .platform == 'win32' :
45- standard_real_header = os .path .join (environment .OCC_INC ,"Standard_Real.hxx" )
47+ standard_real_header = os .path .join (environment .OCC_INC , "Standard_Real.hxx" )
4648 if not os .path .isfile (standard_real_header ):
47- print "%s not found." % standard_real_header
49+ print "%s not found." % standard_real_header
4850 sys .exit (0 )
49- # else:
50- # import shutil
51- # fp = open(standard_real_header,"r")
52- # file_content = fp.read()
53- # fp.close()
54- # if not '__SWIG_GENERATION__' in file_content:#need rewriting
55- # key = raw_input("Original Standard_Real.hxx header file needs to be modified. Original file will be available with the name Standard_Real_Original.hxx.\nEnter 'y' or 'Y' if you whish to continue.'n' otherwise:")# first mode Standard_Real.hxx to Standard_Real_Original.hxx
56- # if key.lower()=='y':
57- # shutil.copy(standard_real_header, os.path.join(environment.OCC_INC,"Standard_Real_Original.hxx"))
58- # #replacing string
59- # file_content = file_content.replace("#if defined(WNT)","#if defined(WNT) && !defined(__SWIG_GENERATION__)")
60- # fp = open(standard_real_header,"w")
61- # fp.write(file_content)
62- # fp.close()
63- # else:
64- # sys.exit(0)
65- # else:
66- # print "Found modified Standard_Real.hxx header file."
67- #
68- # Remove all files from OCC folder
69- #
70- #files_to_remove = glob.glob(os.path.join(os.getcwd(),'OCC','*'))
71- #for file_to_remove in files_to_remove:
72- # os.remove(file_to_remove)
7351 #
7452 # Create paths
7553 #
7654 if not os .path .isdir (environment .SWIG_FILES_PATH_MODULAR ):
7755 os .mkdir (environment .SWIG_FILES_PATH_MODULAR )
7856
57+
7958def generate_SWIG_file_for_module (module ):
8059 ''' For each module, create the siwg .i file to be processed
8160 '''
8261 if module in Modules .SALOME_GEOM_MODULES :
83- SWIG_generator .ModularBuilder (module ,environment .SALOME_GEOM_INC )
62+ SWIG_generator .ModularBuilder (module , environment .SALOME_GEOM_INC )
8463 elif module in Modules .SALOME_SMESH_MODULES :
85- SWIG_generator .ModularBuilder (module ,environment .SALOME_SMESH_INC )
64+ SWIG_generator .ModularBuilder (module , environment .SALOME_SMESH_INC )
8665 else :
8766 SWIG_generator .ModularBuilder (module )
8867
68+
8969def generate_swig_multiprocess (module_list ):
9070 ''' Generate swig files with parallel support
9171 '''
92- #raw_input('Enter something')
9372 init_time = time .time ()
9473 P = processing .Pool (nprocs )
95- P .map (generate_SWIG_file_for_module ,module_list )
74+ P .map (generate_SWIG_file_for_module , module_list )
9675 final_time = time .time ()
97- #print "%i exported classes"%SWIG_generator.nb_exported_classes
9876 print final_time - init_time
9977
78+
10079def generate_swig_single_process (module_list ):
10180 ''' Generate swig files in single process mode (multiprocessing not found)
10281 '''
10382 init_time = time .time ()
10483 for module in module_list :
10584 generate_SWIG_file_for_module (module )
10685 final_time = time .time ()
107- print "%i exported classes" % SWIG_generator .nb_exported_classes
86+ print "%i exported classes" % SWIG_generator .nb_exported_classes
10887 print final_time - init_time
10988
11089if __name__ == '__main__' :
11190 check_paths ()
11291 # Check if a module name is passed to the command line
113- if len (sys .argv )> 1 :
92+ if len (sys .argv ) > 1 :
11493 module_name_to_wrap = sys .argv [1 ]
11594 if module_name_to_wrap == 'GEOM' :
11695 print "Generating swig files for the GEOM library"
@@ -126,14 +105,13 @@ def generate_swig_single_process(module_list):
126105 modules_to_wrap = [module ]
127106 break
128107 #print modules_to_wrap
129- if modules_to_wrap == None :
130- raise NameError , "Unknown module"
108+ if modules_to_wrap is None :
109+ raise NameError ( "Unknown module" )
131110 else :
132111 if sys .platform == 'win32' :
133112 modules_to_wrap = Modules .COMMON_MODULES + Modules .WIN_MODULES
134113 else :
135114 modules_to_wrap = Modules .COMMON_MODULES + Modules .UNIX_MODULES
136-
137115 if MULTI_PROCESS_GENERATION :
138116 print "Generating pythonOCC SWIG files (MultiProcess mode)."
139117 generate_swig_multiprocess (modules_to_wrap )
0 commit comments