4 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
16 def clFiles(file_dict, directory):
18 Creates the list of the lines for the files founded in file_dict, using
19 directory as the base folder.
22 filelist.append("<VirtualDirectory Name=\"%s\">" %os.path.basename(directory))
23 for f in file_dict[directory]["files"]:
24 filelist.append("<File Name=\"%s\"/>" %os.path.join(directory, f))
25 for d in file_dict[directory]["dirs"]:
26 filelist += clFiles(file_dict, os.path.join(directory, d))
27 filelist.append("</VirtualDirectory>")
30 def findSources(path):
32 Analyzes the directory tree from path and return a dict with filename and
35 if not path.endswith(os.sep):
38 for root, dirs, files in os.walk(path):
39 if root.find("svn") == -1:
40 file_dict[root.replace(path, "")] = {"dirs": [], "files": []}
42 if dir.find("svn") == -1:
43 file_dict[root.replace(path, "")]["dirs"].append(dir)
45 if file.endswith(const.EXTENSION_FILTER):
46 file_dict[root.replace(path, "")]["files"].append(file)
49 def codeliteProjectGenerator(project_info):
51 Returns the string rapresenting the codelite project.
53 template = open("cltemplates/bertos.project", "r").read()
54 filelist = "\n".join(clFiles(findSources(project_info.info("PROJECT_PATH")), ""))
55 while template.find("$filelist") != -1:
56 template = template.replace("$filelist", filelist)
57 project_name = os.path.basename(project_info.info("PROJECT_PATH"))
58 while template.find("$project") != -1:
59 template = template.replace("$project", project_name)
62 def codeliteWorkspaceGenerator(project_info):
64 Returns the string rapresentig the codelite workspace.
66 template = open("cltemplates/bertos.workspace", "r").read()
67 project_name = os.path.basename(project_info.info("PROJECT_PATH"))
68 while template.find("$project") != -1:
69 template = template.replace("$project", project_name)
72 def createProject(project_info):
74 Function that creates codelite projects.
76 directory = project_info.info("PROJECT_PATH")
77 prjdir = directory + "/" + os.path.basename(directory)
78 workspace = codeliteWorkspaceGenerator(project_info)
79 open(directory + "/" + os.path.basename(prjdir) + ".workspace", "w").write(workspace)
80 project = codeliteProjectGenerator(project_info)
81 open(directory + "/" + os.path.basename(prjdir) + ".project", "w").write(project)