Remove codelite specific functions from bertos_utils module
[bertos.git] / wizard / codelite_project.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id:$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 import os
13
14 import const
15
16 def clFiles(file_dict, directory):
17     filelist = []
18     filelist.append("<VirtualDirectory Name=\"%s\">" %os.path.basename(directory))
19     for f in file_dict[directory]["files"]:
20         filelist.append("<File Name=\"%s\"/>" %os.path.join(directory, f))
21     for d in file_dict[directory]["dirs"]:
22         filelist += clFiles(file_dict, os.path.join(directory, d))
23     filelist.append("</VirtualDirectory>")
24     return filelist
25
26 def findSources(path):
27     file_dict = {}
28     for root, dirs, files in os.walk(path):
29         if root.find("svn") == -1:
30             file_dict[root] = {"dirs": [], "files": []}
31             for dir in dirs:
32                 if dir.find("svn") == -1:
33                     file_dict[root]["dirs"].append(dir)
34             for file in files:
35                 if file.endswith(const.EXTENSION_FILTER):
36                     file_dict[root]["files"].append(file)
37     return file_dict
38
39 def codeliteProjectGenerator(project_info):
40     template = open("cltemplates/bertos.project").read()
41     filelist = "\n".join(clFiles(findSources(project_info.info("PROJECT_PATH")), project_info.info("PROJECT_PATH")))
42     while template.find("$filelist") != -1:
43         template = template.replace("$filelist", filelist)
44     project_name = os.path.basename(project_info.info("PROJECT_PATH"))
45     while template.find("$project") != -1:
46         template = template.replace("$project", project_name)
47     return template
48
49 def codeliteWorkspaceGenerator(project_info):
50     template = open("cltemplates/bertos.workspace").read()
51     project_name = os.path.basename(project_info.info("PROJECT_PATH"))
52     while template.find("$project") != -1:
53         template = template.replace("$project", project_name)
54     return template