4 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
16 ## Plugin interface ##
18 PLUGIN_NAME = "CodeLite"
20 PLUGIN_DESCRIPTION = "Create CodeLite project files"
22 def createProject(project_info):
24 Function that creates codelite projects and return the project relevant file.
26 directory = project_info.info("PROJECT_PATH")
27 prjdir = directory + "/" + os.path.basename(directory)
28 workspace = codeliteWorkspaceGenerator(project_info)
29 open(directory + "/" + os.path.basename(prjdir) + ".workspace", "w").write(workspace)
30 project = codeliteProjectGenerator(project_info)
31 open(directory + "/" + os.path.basename(prjdir) + ".project", "w").write(project)
32 return directory + "/" + os.path.basename(prjdir) + ".workspace"
36 def clFiles(file_dict, directory):
38 Creates the list of the lines for the files founded in file_dict, using
39 directory as the base folder.
42 filelist.append("<VirtualDirectory Name=\"%s\">" %os.path.basename(directory))
43 for f in file_dict[directory]["files"]:
44 filelist.append("<File Name=\"%s\"/>" %os.path.join(directory, f))
45 for d in file_dict[directory]["dirs"]:
46 filelist += clFiles(file_dict, os.path.join(directory, d))
47 filelist.append("</VirtualDirectory>")
50 def findSources(path):
52 Analyzes the directory tree from path and return a dict with filename and
55 if not path.endswith(os.sep):
58 for root, dirs, files in os.walk(path):
59 if root.find("svn") == -1:
60 file_dict[root.replace(path, "")] = {"dirs": [], "files": []}
62 if dir.find("svn") == -1:
63 file_dict[root.replace(path, "")]["dirs"].append(dir)
65 if file.endswith(const.EXTENSION_FILTER):
66 file_dict[root.replace(path, "")]["files"].append(file)
69 def codeliteProjectGenerator(project_info):
71 Returns the string rapresenting the codelite project.
73 template = open("cltemplates/bertos.project", "r").read()
74 filelist = "\n".join(clFiles(findSources(project_info.info("PROJECT_PATH")), ""))
75 while template.find("$filelist") != -1:
76 template = template.replace("$filelist", filelist)
77 project_name = os.path.basename(project_info.info("PROJECT_PATH"))
78 while template.find("$project") != -1:
79 template = template.replace("$project", project_name)
82 def codeliteWorkspaceGenerator(project_info):
84 Returns the string rapresentig the codelite workspace.
86 template = open("cltemplates/bertos.workspace", "r").read()
87 project_name = os.path.basename(project_info.info("PROJECT_PATH"))
88 while template.find("$project") != -1:
89 template = template.replace("$project", project_name)