Last active
December 20, 2015 15:39
-
-
Save c4pt0r/6155510 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#encoding=utf-8 | |
import os | |
import sys | |
import StringIO | |
import json | |
def get_file_content(path_to_sln): | |
with open(path_to_sln) as fp: | |
content = fp.read() | |
return content | |
return None | |
def get_projects(sln_file_content): | |
ret = {} | |
content = sln_file_content | |
for line in content.split('\n'): | |
if line.startswith('Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}")'): | |
uuid = line.split(', ')[-1].replace('"', '').lstrip().rstrip() | |
project_name = line.split(', ')[0].split('=')[-1].replace('"', '').lstrip().rstrip() | |
ret[uuid] = (project_name, line.split(', ')[-2].replace("\"", "")) | |
return ret | |
def get_project_dependencys(sln_file_content, project_name): | |
project_name_map = get_projects(sln_file_content) | |
ret = [] | |
content = sln_file_content | |
buf = StringIO.StringIO(content) | |
while True: | |
line = buf.readline().lstrip().rstrip() | |
#print line | |
if not line: | |
break | |
if not (line.startswith('Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}")') and line.find('"' + project_name + '"') != -1): | |
continue | |
#print line | |
flg = False | |
while True: | |
s = buf.readline().lstrip().rstrip() | |
if not s or flg or s.startswith("EndProject"): | |
break | |
if s.startswith('ProjectSection(ProjectDependencies) = postProject'): | |
while True: | |
line = buf.readline().rstrip().lstrip() | |
if line.startswith("EndProjectSection"): | |
flg = True | |
break | |
uuid = line.split('=')[0].lstrip().rstrip().replace("\"", "") | |
ret.append(project_name_map[uuid][1]) | |
return ret | |
def bfs(start_node, nodes): | |
queue = [] | |
seen = {} | |
queue.append(start_node) | |
while len(queue) != 0: | |
n = queue.pop(0) | |
for sub_node in nodes[n]: | |
if seen.get(sub_node, 0) == 0: | |
seen[sub_node] = 1 | |
print sub_node | |
queue.append(sub_node) | |
if __name__ == '__main__': | |
sln_path = sys.argv[1] | |
content = get_file_content(sln_path) | |
projects = get_projects(content) | |
ret = {} | |
for k in projects.keys(): | |
ret[projects[k][1]] = get_project_dependencys(content, k) | |
#bfs("platform\connection.vcproj", ret) | |
if '-i' in sys.argv: | |
while True: | |
try: | |
prj_name = raw_input() | |
except EOFError: | |
break | |
for k in ret.keys(): | |
if prj_name in k: | |
print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>', k | |
bfs(k, ret) | |
print '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment