4 # This file is part of BeRTOS.
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction. Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License. This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
40 class BProject(object):
42 Simple class for store and retrieve project informations.
47 self._cached_queries = {}
49 def setInfo(self, key, value):
51 Store the given value with the name key.
53 self.infos[key] = value
55 def info(self, key, default=None):
57 Retrieve the value associated with the name key.
60 return copy.deepcopy(self.infos[key])
63 def loadSourceTree(self):
64 # Index only the SOURCES_PATH/bertos content
65 bertos_sources_dir = os.path.join(self.info("SOURCES_PATH"), 'bertos')
67 if os.path.exists(bertos_sources_dir):
68 for element in os.walk(bertos_sources_dir):
70 file_dict[f] = file_dict.get(f, []) + [element[0]]
71 self.setInfo("FILE_DICT", file_dict)
73 def searchFiles(self, filename):
74 file_dict = self.infos["FILE_DICT"]
75 return [(filename, dirname) for dirname in file_dict.get(filename, [])]
77 def findDefinitions(self, ftype):
78 definitions = self._cached_queries.get(ftype, None)
79 if definitions is not None:
81 file_dict = self.infos["FILE_DICT"]
83 for filename in file_dict:
84 if fnmatch.fnmatch(filename, ftype):
85 definitions += [(filename, dirname) for dirname in file_dict.get(filename, [])]
86 self._cached_queries[ftype] = definitions
90 return repr(self.infos)