- import re
- class project():
- def __init__(self, prj_name = ''):
- self.proj_name = prj_name
- self.dependencies = []
- self.vcxproj = ''
- def set_name(self, str_name):
- self.proj_name = str_name
- def get_name(self):
- return self.proj_name
- def set_vcxproj(self, str_vcxproj):
- self.vcxproj = str_vcxproj
- def get_vcxproj(self):
- return self.vcxproj
- def append(self, str_dependency):
- self.dependencies.append(str_dependency)
- def show(self):
- print "project: ", self.proj_name
- print "vcxproj: ", self.vcxproj
- print "dependencies: ",str(len(self.dependencies))
- print self.dependencies
- def reset(self):
- self.proj_name = ''
- self.dependencies = []
- def contain(self, str_dependency):
- if str_dependency in self.dependencies:
- return True
- return False
- def analyze_dependencies(lstDependencies, proj):
- RULE_COUNT = 99
- if 0 == len(lstDependencies):
- print 'dependencies count is 0'
- return None
- rule = ''
- s = r'{([^}]+)}'
- setsetDependencies = set(lstDependencies)
- lstDependencies = list(setDependencies)
- lenlenDependencies = len(lstDependencies)
- time = lenDependencies/RULE_COUNT+1
- index = 0
- for i in range(time):
- if i != (time-1):
- strDependencies = ''
- rule = ''
- for j in range(RULE_COUNT):
- strDependencies += lstDependencies[index+j]
- rule += s
- m=re.match(rule, strDependencies)
- for j in range(RULE_COUNT):
- proj.append(m.group(j+1))
- index += RULE_COUNT
- else:
- strDependencies = ''
- rule = ''
- for j in range(len(lstDependencies)-index):
- strDependencies += lstDependencies[index+j]
- rule += s
- m=re.match(rule, strDependencies)
- for j in range(len(lstDependencies)-index):
- proj.append(m.group(j+1))
- #proj.show()
- return proj
- def analyze_sln(lst_proj):
- BEGIN_Project = 'Project'
- BEGIN_Section = 'ProjectSection'
- End_Section = 'EndProjectSection'
- End_Project = 'EndProject'
- b_BEGIN_Project = False
- b_BEGIN_Section = False
- b_End_Section = True
- b_End_Project = True
- f = file('all.sln','r')
- lines = f.readlines()
- f.close()
- lstDependencies = []
- proj = project()
- #lst_proj = []
- for line in lines:
- lineline = line.strip()
- if b_End_Project:
- if line.startswith(BEGIN_Project):
- b_BEGIN_Project = True
- b_End_Project = False
- lstDependencies = []
- m=re.match(r'[^,]+, ([^,]+), "{([a-zA-Z0-9-]+)}"',line)
- s_vcxproj = m.group(1)
- s_name = m.group(2)
- proj = project()
- proj.set_name(s_name)
- proj.set_vcxproj(s_vcxproj)
- #print s_name
- continue
- if b_BEGIN_Project:
- if b_BEGIN_Section:
- if line.startswith(End_Section):
- b_BEGIN_Section = False
- b_End_Section = True
- if 0 == len(lstDependencies):
- continue
- proj = analyze_dependencies(lstDependencies, proj)
- #proj.show()
- lst_proj.append(proj)
- else:
- lineline = line.split('=')[0]
- lstDependencies.append(line.strip())
- continue
- #............
- else:
- if line.startswith(BEGIN_Section):
- b_BEGIN_Section = True
- b_End_Section = False
- continue
- if b_End_Section:
- if line.startswith(End_Project):
- b_End_Project = True