Ignore:
Timestamp:
Jan 30, 2009 4:04:23 PM (15 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
68dada4
Parents:
836fe6e
Message:

wrappergenerator modified

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/sans/models/c_models/WrapperGenerator.py

    r836fe6e rda3dae3  
    44 
    55import os, sys,re 
     6def split_list(separator, mylist, n=0): 
     7    """ 
     8        @return a list of string without white space of separator 
     9        @param separator: the string to remove 
     10    """ 
     11    list=[] 
     12    for item in mylist: 
     13        if re.search( separator,item)!=None: 
     14            if n >0: 
     15                word =re.split(separator,item,int(n)) 
     16            else: 
     17                word =re.split( separator,item) 
     18            for new_item in word:  
     19                if new_item.lstrip().rstrip() !='': 
     20                    list.append(new_item.lstrip().rstrip()) 
     21    return list 
     22def split_text(separator, string1, n=0): 
     23    """ 
     24        @return a list of string without white space of separator 
     25        @param separator: the string to remove 
     26    """ 
     27    list=[] 
     28    if re.search( separator,string1)!=None: 
     29        if n >0: 
     30            word =re.split(separator,string1,int(n)) 
     31        else: 
     32            word =re.split(separator,string1) 
     33        for item in word:  
     34            if item.lstrip().rstrip() !='': 
     35                list.append(item.lstrip().rstrip()) 
     36    return list 
     37def look_for_tag( string1,begin, end=None ): 
     38    """ 
     39        @note: this method  remove the begin and end tags given by the user 
     40        from the string . 
     41        @param begin: the initial tag 
     42        @param end: the final tag 
     43        @param string: the string to check 
     44        @return: begin_flag==True if begin was found, 
     45         end_flag==if end was found else return false, false 
     46          
     47    """ 
     48    begin_flag= False 
     49    end_flag= False 
     50    if  re.search( begin,string1)!=None: 
     51        begin_flag= True 
     52    if end !=None: 
     53        if  re.search(end,string1)!=None: 
     54            end_flag= True 
     55    return begin_flag, end_flag 
    656 
    757class WrapperGenerator: 
     
    116166        key2="<%s>"%text.lower() 
    117167        # close an item in this case fixed 
    118         text='text' 
     168        text='TexT' 
    119169        key3="</%s>"%text.lower() 
    120170        temp="" 
    121171        # flag to found key 
    122         find_fixed= 0 
     172        find_fixed= False 
     173        find_key2=False 
     174        find_key3=False 
    123175         
    124176        for line in lines: 
    125177            if line.count(key)>0 :#[FIXED]= ..... 
    126178                try: 
    127                     find_fixed= 1 
     179                    find_fixed= True 
    128180                    index = line.index(key) 
    129181                    toks  = line[index:].split("=",1 ) 
    130182                    temp  = toks[1].lstrip().rstrip() 
    131                     if re.match(key2,temp)!=None:#[FIXED]= <text> axis_phi.width; axis_theta</text> 
    132                         print "when here" 
    133                         toks2=temp.split(key2,1)\ 
    134                         # split the ";" inside the string 
    135                         print "toks[2]",toks2,toks2[1] 
    136                         if  re.search(";",toks2[1]) !=None: 
    137                             params= toks2[1].split(";") 
    138                             for item in params: 
    139                                 print "item", item 
    140                                 if  re.search( key3,item)!=None: 
    141                                     par= item.split(key3)#remove key3 
    142                                     print "par", par, par[0] 
    143                                     new_par=par[0].lstrip().rstrip() 
    144                                     break 
    145                             #print "Key2 and Key3 in the same line , more than 1 param", self.fixed 
    146                         else:#only 1 param with key2 and key3 
    147                             if  re.search( key3,toks2[1])!=None: 
    148                                 par= toks2[1].split(key3)#remove key3 
    149                                 new_par=par[0].lstrip().rstrip() 
    150                                 self.fixed.append(new_par.lstrip().rstrip()) 
    151                                 #print "Key2 and Key3 in the same line , only 1 param ",self.fixed  
    152                                 break 
    153                     else: # no key2 and key3 #[FIXED]=  axis_phi.width; axis_theta 
    154                         temp2 = temp.lstrip().rstrip() 
    155                         if  re.search(";", temp2) !=None:# more than 1 param in the same line 
    156                             params= temp2.split(";") 
    157                             #print "no key2 and key3  params", params 
    158                             for item in params: 
    159                                 if item!='': 
    160                                     self.fixed.append(item.lstrip().rstrip()) 
    161                             #print "no key2 and key3, more than 1 param ",self.fixed 
    162                         else:# only one param per line #[FIXED]=  axis_phi.width 
    163                              self.fixed.append(temp2) 
    164                              #print "no key2 and key3, only 1 param ",self.fixed 
     183                    find_key2, find_key3=look_for_tag( string1=temp,begin=key2, end=key3 ) 
     184                    if find_key2 and find_key3: 
     185                        #print"Found both:find_key2, find_key3", find_key2, find_key3 
     186                        temp1=[] 
     187                        temp2=[] 
     188                        temp3=[] 
     189                        temp4=[] 
     190                        temp1=split_text(separator=key2, string1=temp) 
     191                        temp2=split_list(separator=key3, mylist=temp1) 
     192                        temp3=split_list(separator=';', mylist=temp2) 
     193                        temp4=split_list(separator=',', mylist=temp3) 
     194                        self.fixed= temp3 + temp4 
     195                        break 
     196                         
     197                    elif find_key2 and not find_key3: 
     198                        #print"Find  find_key2 not find_key3", find_key2, find_key3 
     199                        temp1=[] 
     200                        temp2=[] 
     201                        temp3=[] 
     202                        temp4=[] 
     203                        temp1=split_text(separator=key2, string1=temp) 
     204                        temp3=split_list(separator=';', mylist=temp1) 
     205                        temp4=split_list(separator=',', mylist=temp3) 
     206                        #print "found only key2 , temp4", temp3,temp4 
     207                        if len(temp3+ temp4)==0:# [FIXED]=  only one param 
     208                            self.fixed+= temp1 
     209                        self.fixed+=temp3+temp4 # 
     210                    elif not (find_key2 and find_key3) : 
     211                        #print"Find nothing find_key2 not find_key3", find_key2, find_key3 
     212                        temp3=[] 
     213                        temp4=[] 
     214                        if look_for_tag( string1=temp,begin=";")[0]:# split ";" first 
     215                            temp3=split_text(separator=';',string1=temp) 
     216                            temp4=split_list(separator=',', mylist=temp3) 
     217                        else: 
     218                            temp3=split_text(separator=',',string1=temp)# slip "," first 
     219                            temp4=split_list(separator=';', mylist=temp3) 
     220                        if len(temp3+ temp4)==0:# [FIXED]=  only one param 
     221                            self.fixed= [temp] 
     222                        self.fixed+=temp3+temp4 # 
    165223                        break 
    166224                except: 
    167                      raise 
    168                      raise ValueError, "Could not parse file %s" % self.file 
    169             if find_fixed==1:# go to the 2nd line containing info found 1 key2 
    170                 #[FIXED]= <text> axis_phi.width; axis_theta;radius_a.width; 
    171                 #radius_</text> 
    172                 if re.search(key3,line)!=None:# find  </text> 
    173                     tok=line.split(key3,1) 
    174                     print "tok",tok,tok[0] 
    175                     if re.match('//',tok[0].lstrip().rstrip())!=None:# look for '//' 
    176                         temp=tok[0].split("//",1)# remove "//" 
    177                     elif re.match('\*',tok[0].lstrip().rstrip())!=None: 
    178                         temp=tok[0].split("*",1)# remove "*" 
     225                    raise ValueError, "Could not parse file %s" % self.file 
     226             
     227            elif find_fixed: 
     228                #looking only for key3 
     229                if not find_key2: 
     230                    raise ValueError, "Could not parse file %s" % self.file 
     231                find_key3=look_for_tag( string1=line,begin=key3)[0]# split "</text>" first 
     232                #print "find_key3",find_key3,line,key3 
     233                if find_key3: 
     234                    temp1=[] 
     235                    temp2=[] 
     236                    temp3=[] 
     237                    temp4=[] 
     238                    temp5=[] 
     239                    
     240                    temp1=split_text(separator=key3, string1=line) 
     241                    temp2=split_list(separator='//',mylist=temp1) 
     242                    temp5=split_list(separator="\*",mylist=temp1) 
     243                     
     244                    if len(temp5)>0: 
     245                        temp3=split_list(separator=';',mylist=temp5) 
     246                        temp4=split_list(separator=',', mylist=temp5) 
     247                    elif len(temp2)>0: 
     248                        temp3=split_list(separator=';',mylist=temp2) 
     249                        temp4=split_list(separator=',', mylist=temp2) 
    179250                    else: 
    180                         # missing "*" or "//" on comment  
    181                         raise 
    182                         #raise ValueError, "Could not parse file %s" % self.file 
    183                     for item in temp: 
    184                         if item.lstrip().rstrip() !='': 
    185                             pars= item.lstrip().rstrip() 
    186                             if  re.search(";",pars) !=None:# split string by ";" more than 1 parameter 
    187                                 params= pars.split(";") 
    188                                 for name in params: 
    189                                     if name.lstrip().rstrip() !='': 
    190                                         self.fixed.append(name.lstrip().rstrip()) 
    191                             else:# contains only one parameter 
    192                                 name=pars.lstrip().rstrip() 
    193                                 if name!='' and name!= key3:#only 1 parameter but ignore key3 
    194                                     self.fixed.append(name.lstrip().rstrip()) 
    195                                     #print "the line contains only one parameters",name.lstrip().rstrip() 
    196                                 break 
    197              
    198                  
     251                        temp3=split_list(separator=';',mylist=temp1) 
     252                        temp4=split_list(separator=',', mylist=temp1) 
     253                     
     254                    if len(temp3+ temp4)==0:# [FIXED]=  only one param 
     255                        self.fixed+= temp1 
     256                    self.fixed+=temp3+temp4 #    
     257                    break  
     258                else: 
     259                    temp2=split_text(separator='//',string1=line) 
     260                    temp5=split_text(separator="\*",string1=line) 
     261                    if len(temp5)>0: 
     262                        temp3=split_list(separator=';',mylist=temp5) 
     263                        temp4=split_list(separator=',', mylist=temp5) 
     264                    elif len(temp2)>0: 
     265                        temp3=split_list(separator=';',mylist=temp2) 
     266                        temp4=split_list(separator=',', mylist=temp2) 
     267                    else: 
     268                        if look_for_tag( string1=line,begin=";")[0]:# split ";" first 
     269                            temp3=split_text(separator=';',string1=line) 
     270                            temp4=split_list(separator=',', mylist=temp3) 
     271                        else: 
     272                            temp3=split_text(separator=',',string1=line)# slip "," first 
     273                            temp4=split_list(separator=';', mylist=temp3) 
     274                    if len(temp3+ temp4)==0:# [FIXED]=  only one param 
     275                        self.fixed= [line.lstrip().rstrip()] 
     276                    self.fixed+=temp3+temp4 # 
     277                     
     278                 
     279                     
    199280        # Catch Description 
    200281        key = "[DESCRIPTION]" 
Note: See TracChangeset for help on using the changeset viewer.