コード例 #1
0
 def write_module( self, file_name ):
     """
     Writes module to single file
     @param file_name: file name
     @type file_name: string
     """
     self.__merge_user_code()
     file_writers.write_file( self.code_creator, file_name, encoding=self.encoding )
コード例 #2
0
ファイル: create_tnfox.py プロジェクト: ned14/tnfox
def write_module( mb ):
    print 'writing module to files'
    assert isinstance( mb, module_builder.module_builder_t )
    if not os.path.exists( settings.generated_files_dir ):
        os.mkdir( settings.generated_files_dir )
    start_time = time.clock()      
    file_writers.write_file( os.path.join( settings.generated_files_dir, color_array.file_name )
                             , color_array.create_file_content())
    mb.split_module( settings.generated_files_dir )
    print 'time taken : ', time.clock() - start_time, ' seconds'
    print 'writing module to files - done'
コード例 #3
0
 def FinalOutput(self, mb_client, mb_server):
     # Set pydocstring options
     mb_client.add_registration_code('bp::docstring_options doc_options( true, true, false );', tail=False)
     mb_server.add_registration_code('bp::docstring_options doc_options( true, true, false );', tail=False)
     
     # Generate code
     mb_client.build_code_creator(module_name=self.module_name)
     self.PostCodeCreation(mb_client)
     mb_server.build_code_creator(module_name=self.module_name)
     self.PostCodeCreation(mb_server)
     
     # Misc
     self.isclient = True
     self.isserver = False
     self.AddAdditionalCode(mb_client)   
     self.isclient = False
     self.isserver = True
     self.AddAdditionalCode(mb_server)   
     
     if not self.split:
         content_client = self.GenerateContent(mb_client)
         content_server = self.GenerateContent(mb_server)
         
         
         content = tmpl_content_semishared % {
             'content_client' : content_client,
             'content_server' : content_server,
         }
         
         targetdir = self.path
         targetpath = os.path.join(targetdir, '%s.cpp' % (self.module_name))
         
         # This is just to write the file repositories (if any)
         mfs_client = single_files_nowrite_t( mb_client.code_creator, targetpath, encoding='ascii' )
         mfs_client.write()
         mfs_server = single_files_nowrite_t( mb_server.code_creator, targetpath, encoding='ascii' )
         mfs_server.write()
         
         # Write combined output
         file_writers.write_file(targetpath, content)
     else:    
         mb_client.merge_user_code()
         mb_server.merge_user_code()
         
         # Write client
         self.isclient = True
         self.isserver = False
         targetdir = os.path.join(self.path, self.module_name)
         if not os.path.isdir(targetdir):
             os.mkdir(targetdir)
             
         if not self.client_huge_classes:
             mfs_client = multiple_files_nowrite_t( mb_client.code_creator, targetdir, files_sum_repository=None, encoding='ascii' )
         else:
             mfs_client = class_multiple_files_nowrite_t( mb_client.code_creator, targetdir, self.client_huge_classes, files_sum_repository=None, encoding='ascii' )
         mfs_client.write()
         
         for key in mfs_client.content.keys():
             content = '#include "cbase.h"\r\n' + \
                       mfs_client.content[key]
             file_writers.write_file(key, content) 
         
         # Write server
         self.isclient = False
         self.isserver = True
         targetdir = os.path.join(self.path, self.module_name)
         if not os.path.isdir(targetdir):
             os.mkdir(targetdir)
             
         if not self.server_huge_classes:
             mfs_server = multiple_files_nowrite_t( mb_server.code_creator, targetdir, files_sum_repository=None, encoding='ascii' )
         else:
             mfs_server = class_multiple_files_nowrite_t( mb_server.code_creator, targetdir, self.server_huge_classes, files_sum_repository=None, encoding='ascii' )
         mfs_server.write()
         
         for key in mfs_server.content.keys():
             content = '#include "cbase.h"\r\n' + \
                       mfs_server.content[key]
             file_writers.write_file(key, content)
             
コード例 #4
0
ファイル: modulebuilder.py プロジェクト: ChrisCarlsen/tortuga
   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.
          
          @param moduleName: The name of the module being created.
          @param filename:   The file or directory to create the code.
          @param useScope:   If true the creators all use scope in their code.
          @param multiFile:  If true use the multifile writer.
          @param multiCreateMain: If true and using multifile then create main reg method.
      """
      if not self.mExtModule:
         self.buildCreators(moduleName, filename, useScope)
      extmodule = self.mExtModule
      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 "Sanity check..."
      creators = code_creators.make_flatten(self.mExtModule)
      fmfunctions = filter(lambda creator: isinstance(creator, code_creators.calldef.calldef_t) and not isinstance(creator, code_creators.calldef.constructor_t), creators)
      missing_flag = False
      sanity_failed = []
      for creator in fmfunctions:
         if not creator.declaration.call_policies:
            print "Missing policy:", declarations.full_name(creator.declaration)
            missing_flag = True
         if not self._declSanityCheck(creator.declaration):
            sanity_failed.append(creator.declaration)
      if len(sanity_failed)>0:
         f = file("problems.log", "wt")
         print "***Warning*** The following %d declarations may produce code that compiles, but"%len(sanity_failed)
         print >>f, "***Warning*** The following %d declarations may produce code that compiles, but"%len(sanity_failed)
         print "that does not have the desired effect in Python:"
         print >>f, "that does not have the desired effect in Python:"
         for decl in sanity_failed:
            print " ",decl
            print >>f, " ",decl
            print >>f, "  ",decl.location.line, decl.location.file_name
      if missing_flag:
         print "*** Aborting because of missing policies!"
         return
      
      if self.mVerbose:
         print "Writing out files (%s)..."%filename
      
      # Write out the file(s)
      if not multiFile:
         file_writers.write_file(extmodule, filename)
         # Let the arg policy manager write its files...
         self.mArgPolicyManager.writeFiles(os.path.dirname(filename))
      else:
         mfs = file_writers.multiple_files_t(extmodule, filename, write_main=multiCreateMain)
         mfs.write()
         self.split_header_names = mfs.split_header_names
         self.split_method_names = mfs.split_method_names

         # Let the arg policy manager write its files...
         self.mArgPolicyManager.writeFiles(filename)
         
      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)
コード例 #5
0
ファイル: modulebuilder.py プロジェクト: laxris/pyplusplus
    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.
          
          @param moduleName: The name of the module being created.
          @param filename:   The file or directory to create the code.
          @param useScope:   If true the creators all use scope in their code.
          @param multiFile:  If true use the multifile writer.
          @param multiCreateMain: If true and using multifile then create main reg method.
      """
        if not self.mExtModule:
            self.buildCreators(moduleName, filename, useScope)
        extmodule = self.mExtModule
        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 "Sanity check..."
        creators = code_creators.make_flatten(self.mExtModule)
        fmfunctions = filter(
            lambda creator: isinstance(
                creator, code_creators.calldef.calldef_t) and not isinstance(
                    creator, code_creators.calldef.constructor_t), creators)
        missing_flag = False
        sanity_failed = []
        for creator in fmfunctions:
            if not creator.declaration.call_policies:
                print "Missing policy:", declarations.full_name(
                    creator.declaration)
                missing_flag = True
            if not self._declSanityCheck(creator.declaration):
                sanity_failed.append(creator.declaration)
        if len(sanity_failed) > 0:
            f = file("problems.log", "wt")
            print "***Warning*** The following %d declarations may produce code that compiles, but" % len(
                sanity_failed)
            print >> f, "***Warning*** The following %d declarations may produce code that compiles, but" % len(
                sanity_failed)
            print "that does not have the desired effect in Python:"
            print >> f, "that does not have the desired effect in Python:"
            for decl in sanity_failed:
                print " ", decl
                print >> f, " ", decl
                print >> f, "  ", decl.location.line, decl.location.file_name
        if missing_flag:
            print "*** Aborting because of missing policies!"
            return

        if self.mVerbose:
            print "Writing out files (%s)..." % filename

        # Write out the file(s)
        if not multiFile:
            file_writers.write_file(extmodule, filename)
            # Let the arg policy manager write its files...
            self.mArgPolicyManager.writeFiles(os.path.dirname(filename))
        else:
            mfs = file_writers.multiple_files_t(extmodule,
                                                filename,
                                                write_main=multiCreateMain)
            mfs.write()
            self.split_header_names = mfs.split_header_names
            self.split_method_names = mfs.split_method_names

            # Let the arg policy manager write its files...
            self.mArgPolicyManager.writeFiles(filename)

        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)