summaryrefslogtreecommitdiffstats
path: root/bitbake-dev/lib/bb/parse/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake-dev/lib/bb/parse/__init__.py')
-rw-r--r--bitbake-dev/lib/bb/parse/__init__.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/parse/__init__.py b/bitbake-dev/lib/bb/parse/__init__.py
new file mode 100644
index 0000000000..3c9ba8e6da
--- /dev/null
+++ b/bitbake-dev/lib/bb/parse/__init__.py
@@ -0,0 +1,80 @@
1"""
2BitBake Parsers
3
4File parsers for the BitBake build tools.
5
6"""
7
8
9# Copyright (C) 2003, 2004 Chris Larson
10# Copyright (C) 2003, 2004 Phil Blundell
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License version 2 as
14# published by the Free Software Foundation.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License along
22# with this program; if not, write to the Free Software Foundation, Inc.,
23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24#
25# Based on functions from the base bb module, Copyright 2003 Holger Schurig
26
27__all__ = [ 'ParseError', 'SkipPackage', 'cached_mtime', 'mark_dependency',
28 'supports', 'handle', 'init' ]
29handlers = []
30
31import bb, os
32
33class ParseError(Exception):
34 """Exception raised when parsing fails"""
35
36class SkipPackage(Exception):
37 """Exception raised to skip this package"""
38
39__mtime_cache = {}
40def cached_mtime(f):
41 if not __mtime_cache.has_key(f):
42 __mtime_cache[f] = os.stat(f)[8]
43 return __mtime_cache[f]
44
45def cached_mtime_noerror(f):
46 if not __mtime_cache.has_key(f):
47 try:
48 __mtime_cache[f] = os.stat(f)[8]
49 except OSError:
50 return 0
51 return __mtime_cache[f]
52
53def mark_dependency(d, f):
54 if f.startswith('./'):
55 f = "%s/%s" % (os.getcwd(), f[2:])
56 deps = bb.data.getVar('__depends', d) or []
57 deps.append( (f, cached_mtime(f)) )
58 bb.data.setVar('__depends', deps, d)
59
60def supports(fn, data):
61 """Returns true if we have a handler for this file, false otherwise"""
62 for h in handlers:
63 if h['supports'](fn, data):
64 return 1
65 return 0
66
67def handle(fn, data, include = 0):
68 """Call the handler that is appropriate for this file"""
69 for h in handlers:
70 if h['supports'](fn, data):
71 return h['handle'](fn, data, include)
72 raise ParseError("%s is not a BitBake file" % fn)
73
74def init(fn, data):
75 for h in handlers:
76 if h['supports'](fn):
77 return h['init'](data)
78
79
80from parse_py import __version__, ConfHandler, BBHandler