[pygccxml-commit] source/pyplusplus/experimental pypp_api.py,1.9,1.10
Brought to you by:
mbaas,
roman_yakovenko
From: Matthias B. <mb...@us...> - 2006-03-20 14:21:36
|
Update of /cvsroot/pygccxml/source/pyplusplus/experimental In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13359 Modified Files: pypp_api.py Log Message: Added some more info messages (including timings) and added the arguments for buildCreators() and writeModule() also to the constructor. The args can now either be set in the constructor or, as before, when calling the methods. Index: pypp_api.py =================================================================== RCS file: /cvsroot/pygccxml/source/pyplusplus/experimental/pypp_api.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** pypp_api.py 20 Mar 2006 09:32:24 -0000 1.9 --- pypp_api.py 20 Mar 2006 14:21:32 -0000 1.10 *************** *** 28,32 **** """ ! import os, os.path, re # Bring in everything I need from pyplusplus and pygccxml --- 28,32 ---- """ ! import os, os.path, re, time # Bring in everything I need from pyplusplus and pygccxml *************** *** 65,87 **** class ModuleBuilder: ! """ Wrapper for a module (or part of a module). ! Captures handling of parsing and writing out bindings. ! Note: The public namespace '::' is the root decl for the Module. ! By default all declarations are ignored. ! """ ! def __init__(self, headerFiles, workingDir=None, ! includePaths=[], gccxmlPath = '', ! defines=[], undefines=[], ! cacheFile = None, verbose=True): """Initialize module. ! @param workingDir: directory to start processing. (default: current working dir) @param includePaths: List of paths to tell gccxml to search for header files. @param gccxmlPath: path to gccxml. If not set then attempt to find it in system path. @param defines: set of symbols to add as defined when compiling. @param undefines: set of symbols to add as undefined when compiling. ! @param cacheFile: name of file to use for caching parse data for this module. @param verbose: if true output status and command information as building the module. """ if not isinstance(headerFiles, list): --- 65,118 ---- class ModuleBuilder: ! """Wrapper for a module (or part of a module). ! ! Captures handling of parsing and writing out bindings. ! Note: The public namespace '::' is the root decl for the Module. ! By default all declarations are ignored. ! ! @group Control methods: parse, buildCreators, writeModule """ ! def __init__(self, ! headerFiles = [], ! workingDir = None, ! includePaths = [], ! gccxmlPath = '', ! defines = [], ! undefines = [], ! cacheFile = None, ! cacheDir = None, ! moduleName = None, ! output = "bindings", ! multiFile = False, ! useScope = False, ! verbose = True): """Initialize module. ! ! @param headerFiles: The header files to parse ! @type headerFiles: str or list of str @param workingDir: directory to start processing. (default: current working dir) + @type workingDir: str @param includePaths: List of paths to tell gccxml to search for header files. + @type includePaths: list of str @param gccxmlPath: path to gccxml. If not set then attempt to find it in system path. + @type gccxmlPath: str @param defines: set of symbols to add as defined when compiling. + @type defines: list of str @param undefines: set of symbols to add as undefined when compiling. ! @type undefines: list of str ! @param cacheFile: name of file to use for caching parse data for this module using the file cache. ! @type cacheFile: str ! @param cacheDir: The name of the directory to use for caching parse data using the directory cache. ! @type cacheDir: str ! @param moduleName: The name of the Python module to generate ! @type moduleName: str ! @param output: The output file name or directory ! @type output: str ! @param multiFile: Determines whether the output will be written in one single file or in several files ! @type multiFile: bool ! @param useScope: If true the creators all use scope in their code. ! @type useScope: bool @param verbose: if true output status and command information as building the module. + @type verbose: bool """ if not isinstance(headerFiles, list): *************** *** 96,99 **** --- 127,135 ---- self.mUndefines = undefines self.mCacheFile = cacheFile # File to use for caching gccxml output + self.mCacheDir = cacheDir # Directory to use for caching + self.mModuleName = moduleName # Name of the Python extension module + self.mOutput = output # Output file or directory name + self.mMultiFile = multiFile # Multi file flag + self.mUseScope = useScope # Use scope self.mVerbose = verbose # Should there be verbose output during processing self.mDeclRoot = None # Root of the parsed decls (as declaration_t object) *************** *** 108,111 **** --- 144,149 ---- self.mLicense = None # License to use self.mExtModule = None # Extension model being built (code creator tree) + self.mStartTime = None # Begin of the parsing step + self.mParseEndTime = None # The time when parsing was finished print "Initialized module." *************** *** 119,126 **** @returns: Returns the root of the declaration tree @postcondition: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored. ! """ if self.mVerbose: print "Parsing headers: ", self.mHeaderFiles # Create and initialize the config object parser_cfg = parser.config_t(self.mGccXmlPath, --- 157,170 ---- @returns: Returns the root of the declaration tree @postcondition: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored. ! """ ! if self.mHeaderFiles==[]: ! raise ValueError, "No header files specified" ! if self.mVerbose: print "Parsing headers: ", self.mHeaderFiles + # Record the time when parsing started... + self.mStartTime = time.time() + # Create and initialize the config object parser_cfg = parser.config_t(self.mGccXmlPath, *************** *** 146,152 **** full_header_list.append(temp_filename) # Create the parser object... the_parser = parser.project_reader_t(config=parser_cfg, ! cache=self.mCacheFile, decl_factory=decl_wrappers.dwfactory_t()) # ...and parse the headers --- 190,210 ---- full_header_list.append(temp_filename) + # Create the cache object... + if self.mCacheDir!=None: + if self.mVerbose: + print "Using directory cache in '%s'"%self.mCacheDir + cache = parser.directory_cache_t(self.mCacheDir) + elif self.mCacheFile!=None: + if self.mVerbose: + print "Using file cache '%s'"%self.mCacheFile + cache = parser.file_cache_t(self.mCacheFile) + else: + if self.mVerbose: + print "No cache in use" + cache = None + # Create the parser object... the_parser = parser.project_reader_t(config=parser_cfg, ! cache=cache, decl_factory=decl_wrappers.dwfactory_t()) # ...and parse the headers *************** *** 182,193 **** real_type_name = real_type_name[2:] self.mTypeDefMap[full_name] = real_type_name ! if self.mVerbose: ! print "completed parsing." return self.mDeclRootWrapper ! def buildCreators(self, moduleName, filename, useScope=False): """ Build creator tree and module from the current declarations. See writeModule for parameter documentation. --- 240,252 ---- real_type_name = real_type_name[2:] self.mTypeDefMap[full_name] = real_type_name ! ! self.mParseEndTime = time.time() if self.mVerbose: ! print "Completed parsing in %s."%self._time2str(self.mParseEndTime-self.mStartTime) return self.mDeclRootWrapper ! def buildCreators(self, moduleName=None, filename=None, useScope=None): """ Build creator tree and module from the current declarations. See writeModule for parameter documentation. *************** *** 200,203 **** --- 259,273 ---- self.parse() + if self.mVerbose: + print "Decoration time:",self._time2str(time.time()-self.mParseEndTime) + startTime = time.time() + + if moduleName==None: + moduleName = self.mModuleName + if moduleName==None: + raise ValueError, "No output module name given" + if useScope==None: + useScope = self.mUseScope + # Lock the decoration interface (an attempt to decorate after this # call will lead to an error) *************** *** 249,252 **** --- 319,325 ---- if self.mLicense: extmodule._set_license(self.mLicense) + + if self.mVerbose: + print "Code creator tree built in %s"%self._time2str(time.time()-startTime) self.mExtModule = extmodule *************** *** 254,259 **** ! def writeModule(self, moduleName, filename, useScope=False, ! multiFile=False, multiCreateMain=True): """ Create the module and write it out. Automatically calls createCreators() and filterExposed() if needed. --- 327,332 ---- ! def writeModule(self, moduleName=None, filename=None, useScope=None, ! multiFile=None, multiCreateMain=True): """ Create the module and write it out. Automatically calls createCreators() and filterExposed() if needed. *************** *** 270,275 **** assert extmodule # Check for missing policies... ! print "Checking policies..." creators = code_creators.make_flatten(self.mExtModule) fmfunctions = filter(lambda creator: isinstance(creator, code_creators.function_t), creators) --- 343,356 ---- assert extmodule + startTime = time.time() + + if filename==None: + filename = self.mOutput + if multiFile==None: + multiFile = self.mMultiFile + # Check for missing policies... ! if self.mVerbose: ! print "Checking policies..." creators = code_creators.make_flatten(self.mExtModule) fmfunctions = filter(lambda creator: isinstance(creator, code_creators.function_t), creators) *************** *** 284,288 **** if self.mVerbose: ! print "Writing out files..." # Write out the file(s) --- 365,369 ---- if self.mVerbose: ! print "Writing out files (%s)..."%filename # Write out the file(s) *************** *** 296,300 **** --- 377,383 ---- if self.mVerbose: + print "Module written in %s"%self._time2str(time.time()-startTime) print "Module generation complete." + print "Total time: %s"%self._time2str(time.time()-self.mStartTime) *************** *** 378,382 **** return content ! class DeclWrapper: --- 461,486 ---- return content ! ! # _time2str ! def _time2str(self, t): ! """Helper method to convert a time value to a readable string. ! ! @param t: Time value in seconds ! @type t: float ! @returns: The time as a string ! @rtype: str ! """ ! if t<60: ! return "%1.0fs"%t ! else: ! min = int(t/60) ! sec = int(t%60) ! if min<60: ! return "%dmin %ds"%(min,sec) ! else: ! h = int(min/60) ! min = int(min%60) ! return "%dh %dmin %ds"%(h,min,sec) ! class DeclWrapper: |