Correct svn:ignore
[bertos.git] / wizard / plugins / 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     """
18     Creates the list of the lines for the files founded in file_dict, using
19     directory as the base folder.
20     """
21     filelist = []
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>")
28     return filelist
29
30 def findSources(path):
31     """
32     Analyzes the directory tree from path and return a dict with filename and
33     path.
34     """
35     file_dict = {}
36     for root, dirs, files in os.walk(path):
37         if root.find("svn") == -1:
38             file_dict[root] = {"dirs": [], "files": []}
39             for dir in dirs:
40                 if dir.find("svn") == -1:
41                     file_dict[root]["dirs"].append(dir)
42             for file in files:
43                 if file.endswith(const.EXTENSION_FILTER):
44                     file_dict[root]["files"].append(file)
45     return file_dict
46
47 def codeliteProjectGenerator(project_info):
48     """
49     Returns the string rapresenting the codelite project.
50     """
51     template = open("cltemplates/bertos.project", "r").read()
52     filelist = "\n".join(clFiles(findSources(project_info.info("PROJECT_PATH")), project_info.info("PROJECT_PATH")))
53     while template.find("$filelist") != -1:
54         template = template.replace("$filelist", filelist)
55     project_name = os.path.basename(project_info.info("PROJECT_PATH"))
56     while template.find("$project") != -1:
57         template = template.replace("$project", project_name)
58     return template
59
60 def codeliteWorkspaceGenerator(project_info):
61     """
62     Returns the string rapresentig the codelite workspace.
63     """
64     template = open("cltemplates/bertos.workspace", "r").read()
65     project_name = os.path.basename(project_info.info("PROJECT_PATH"))
66     while template.find("$project") != -1:
67         template = template.replace("$project", project_name)
68     return template
69
70 def createProject(project_info):
71     """
72     Function that creates codelite projects.
73     """
74     directory = project_info.info("PROJECT_PATH")
75     prjdir = directory + "/" + os.path.basename(directory)
76     workspace = codeliteWorkspaceGenerator(project_info)
77     open(directory + "/" + os.path.basename(prjdir) + ".workspace", "w").write(workspace)
78     project = codeliteProjectGenerator(project_info)
79     open(directory + "/" + os.path.basename(prjdir) + ".project", "w").write(project)