python sln

 

  1. import re
  2.  
  3. class project(): 
  4.     def __init__(self, prj_name = ''): 
  5.       self.proj_name = prj_name 
  6.       self.dependencies = [] 
  7.       self.vcxproj'' 
  8.  
  9.     def set_name(self, str_name): 
  10.       self.proj_name = str_name 
  11.  
  12.     def get_name(self): 
  13.       return self.proj_name 
  14.  
  15.     def set_vcxproj(self, str_vcxproj): 
  16.       self.vcxprojstr_vcxproj
  17.  
  18.     def get_vcxproj(self): 
  19.       return self.vcxproj
  20.  
  21.     def append(self, str_dependency): 
  22.       self.dependencies.append(str_dependency) 
  23.  
  24.     def show(self): 
  25.       print 
  26.       print "project: ", self.proj_name
  27. print "vcxproj: ", self.vcxproj
  28.       print "dependencies: ",str(len(self.dependencies)) 
  29.       print self.dependencies 
  30.  
  31.     def reset(self): 
  32.       self.proj_name = '' 
  33.       self.dependencies = [] 
  34.  
  35.     def contain(self, str_dependency): 
  36.       if str_dependency in self.dependencies: 
  37.         return True 
  38.       return False 
  39.  

 

  1. def analyze_dependencies(lstDependencies, proj): 
  2.  
  3.     RULE_COUNT = 99 
  4.  
  5.     if 0 == len(lstDependencies): 
  6.       print 'dependencies count is 0' 
  7.       return None 
  8.     rule = '' 
  9.     s = r'{([^}]+)}' 
  10.  
  11.     setsetDependencies = set(lstDependencies) 
  12.     lstDependencies = list(setDependencies) 
  13.  
  14.     lenlenDependencies = len(lstDependencies) 
  15.     time = lenDependencies/RULE_COUNT+1 
  16.  
  17.     index = 0 
  18.     for i in range(time): 
  19.         if i != (time-1): 
  20.           strDependencies = '' 
  21.           rule = '' 
  22.           for j in range(RULE_COUNT): 
  23.             strDependencies += lstDependencies[index+j] 
  24.             rule += s 
  25.           m=re.match(rule, strDependencies) 
  26.           for j in range(RULE_COUNT): 
  27.             proj.append(m.group(j+1)) 
  28.           index += RULE_COUNT 
  29.         else: 
  30.           strDependencies = '' 
  31.           rule = '' 
  32.           for j in range(len(lstDependencies)-index): 
  33.             strDependencies += lstDependencies[index+j] 
  34.             rule += s 
  35.           m=re.match(rule, strDependencies) 
  36.           for j in range(len(lstDependencies)-index): 
  37.             proj.append(m.group(j+1)) 
  38.     #proj.show() 
  39.     return proj 

 

  1. def analyze_sln(lst_proj): 
  2.   BEGIN_Project = 'Project' 
  3.   BEGIN_Section = 'ProjectSection' 
  4.   End_Section   = 'EndProjectSection' 
  5.   End_Project   = 'EndProject' 
  6.  
  7.   b_BEGIN_Project = False 
  8.   b_BEGIN_Section = False 
  9.   b_End_Section   = True 
  10.   b_End_Project   = True 
  11.  
  12.   f = file('all.sln','r') 
  13.   lines = f.readlines() 
  14.   f.close() 
  15.  
  16.   lstDependencies = [] 
  17.   proj = project() 
  18.   #lst_proj = [] 
  19.  
  20.   for line in lines: 
  21.     lineline = line.strip() 
  22.     if b_End_Project: 
  23.       if line.startswith(BEGIN_Project): 
  24.         b_BEGIN_Project = True 
  25.         b_End_Project = False 
  26.         lstDependencies = [] 
  27.         m=re.match(r'[^,]+, ([^,]+), "{([a-zA-Z0-9-]+)}"',line) 
  28.         s_vcxprojm.group(1) 
  29.         s_name = m.group(2) 
  30.         proj = project() 
  31.         proj.set_name(s_name) 
  32.         proj.set_vcxproj(s_vcxproj
  33.         #print s_name       
  34.         continue 
  35.  
  36.     if b_BEGIN_Project: 
  37.       if b_BEGIN_Section: 
  38.         if line.startswith(End_Section): 
  39.           b_BEGIN_Section = False 
  40.           b_End_Section = True 
  41.           if 0 == len(lstDependencies): 
  42.             continue 
  43.           proj = analyze_dependencies(lstDependencies, proj) 
  44.           #proj.show() 
  45.           lst_proj.append(proj) 
  46.  
  47.         else: 
  48.           lineline = line.split('=')[0] 
  49.           lstDependencies.append(line.strip()) 
  50.           continue 
  51.           #............ 
  52.       else: 
  53.         if line.startswith(BEGIN_Section): 
  54.           b_BEGIN_Section = True 
  55.           b_End_Section = False 
  56.           continue 
  57.  
  58.     if b_End_Section: 
  59.       if line.startswith(End_Project): 
  60.         b_End_Project   = True 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章