Changeset 0a9686d in sasview for sansmodels/src/python_wrapper


Ignore:
Timestamp:
Jun 25, 2012 9:07:41 AM (13 years ago)
Author:
Kieran Campbell <kieranrcampbell@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
33c671e
Parents:
f8be87d
Message:

Updated python wrapping to automatically generate c_models.cpp

Location:
sansmodels/src/python_wrapper
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/python_wrapper/WrapperGenerator.py

    r0ea247e r0a9686d  
    9393        self.output_dir = output_dir 
    9494        self.c_wrapper_dir = c_wrapper_dir 
     95 
    9596         
    9697         
     
    201202                     
    202203                 
    203                  
     204      
    204205        for line in lines: 
    205206             
     
    209210                try: 
    210211                    index = line.index(key) 
    211                     #toks = string.split( line[index:], "=" ) 
    212212                    toks = line[index:].split("=" ) 
    213213                    self.pythonClass = toks[1].lstrip().rstrip() 
     214 
    214215                except: 
    215216                    raise ValueError, "Could not parse file %s" % self.file 
     
    287288                except: 
    288289                    raise ValueError, "Could not parse file %s" % self.file 
    289                 
    290          
    291                  
     290 
    292291    def write_c_wrapper(self): 
    293292        """ Writes the C file to create the python extension class  
     
    495494        return newline 
    496495         
    497          
     496    def getModelName(self): 
     497        return self.pythonClass 
     498         
     499 
     500 
    498501# main 
    499502if __name__ == '__main__': 
  • sansmodels/src/python_wrapper/wrapping.py

    r101065a r0a9686d  
    66def generate_wrappers(header_dir, output_dir='.', c_wrapper_dir='.'): 
    77    nModels=0 
     8    model_list = list() 
     9 
    810    for item in os.listdir(header_dir): 
    911        toks = os.path.splitext(os.path.basename(item)) 
     
    1719            app.write_c_wrapper() 
    1820            app.write_python_wrapper() 
    19             #print app 
     21            model_list.append(app.getModelName()) 
     22    write_c_models(model_list) 
    2023    print "Total number of model  wrappers created is %s" % nModels 
     24 
     25def write_c_models(model_list): 
     26    # simultaneously generates 'sansmodels/installed_models.txt' 
     27    # and 'sansmodels/src/c_models/c_models.cpp' 
     28    model_list_file = open(os.path.join("sansmodels","installed_models.txt"),"w") 
     29    for model in model_list: 
     30        model_list_file.write(model + "\n") 
     31 
     32    model_list_file.close() 
     33     
     34 
     35    template_file = open(os.path.join("sansmodels","src","c_models","c_models.cpp.template"),"r") 
     36    write_file = open(os.path.join("sansmodels","src","c_models","c_models.cpp"),"w") 
     37    buf = template_file.read() 
     38    lines = buf.split('\n') 
     39     
     40    tag1 = "[TAG_1]" 
     41    tag2 = "[TAG_2]" 
     42     
     43    for line in lines: 
     44         
     45        if line.count(tag1) > 0: 
     46            write_file.write("\n // adding generated code \n") 
     47            for pyclass in model_list: 
     48                write_file.write("void addC" + pyclass 
     49                                 + "(PyObject *module); \n") 
     50            write_file.write(" // end generated code \n") 
     51                 
     52 
     53        elif line.count(tag2) > 0: 
     54            write_file.write("\n // adding generated code \n") 
     55 
     56            for pyclass in model_list: 
     57                write_file.write("addC" + pyclass + "(m); \n") 
     58 
     59            write_file.write("addDisperser(m); \n") 
     60            write_file.write("\n // end generated code \n") 
     61                 
     62                 
     63        else: 
     64            write_file.write(line + "\n") 
     65 
     66 
    2167 
    2268if __name__ == '__main__': 
     
    2571 
    2672 
     73 
     74 
Note: See TracChangeset for help on using the changeset viewer.