diff options
Diffstat (limited to 'bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py')
-rw-r--r-- | bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py | 241 |
1 files changed, 0 insertions, 241 deletions
diff --git a/bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py b/bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py deleted file mode 100644 index 23316ada58..0000000000 --- a/bitbake-dev/lib/bb/parse/parse_py/ConfHandler.py +++ /dev/null | |||
@@ -1,241 +0,0 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | """ | ||
5 | class for handling configuration data files | ||
6 | |||
7 | Reads a .conf file and obtains its metadata | ||
8 | |||
9 | """ | ||
10 | |||
11 | # Copyright (C) 2003, 2004 Chris Larson | ||
12 | # Copyright (C) 2003, 2004 Phil Blundell | ||
13 | # | ||
14 | # This program is free software; you can redistribute it and/or modify | ||
15 | # it under the terms of the GNU General Public License version 2 as | ||
16 | # published by the Free Software Foundation. | ||
17 | # | ||
18 | # This program is distributed in the hope that it will be useful, | ||
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | # GNU General Public License for more details. | ||
22 | # | ||
23 | # You should have received a copy of the GNU General Public License along | ||
24 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
25 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
26 | |||
27 | import re, bb.data, os, sys | ||
28 | from bb.parse import ParseError | ||
29 | |||
30 | #__config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}]+)\s*(?P<colon>:)?(?P<ques>\?)?=\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$") | ||
31 | __config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}/]+)(\[(?P<flag>[a-zA-Z0-9\-_+.]+)\])?\s*((?P<colon>:=)|(?P<ques>\?=)|(?P<append>\+=)|(?P<prepend>=\+)|(?P<predot>=\.)|(?P<postdot>\.=)|=)\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$") | ||
32 | __include_regexp__ = re.compile( r"include\s+(.+)" ) | ||
33 | __require_regexp__ = re.compile( r"require\s+(.+)" ) | ||
34 | __export_regexp__ = re.compile( r"export\s+(.+)" ) | ||
35 | |||
36 | def init(data): | ||
37 | topdir = bb.data.getVar('TOPDIR', data) | ||
38 | if not topdir: | ||
39 | topdir = os.getcwd() | ||
40 | bb.data.setVar('TOPDIR', topdir, data) | ||
41 | if not bb.data.getVar('BBPATH', data): | ||
42 | from pkg_resources import Requirement, resource_filename | ||
43 | bitbake = Requirement.parse("bitbake") | ||
44 | datadir = resource_filename(bitbake, "../share/bitbake") | ||
45 | basedir = resource_filename(bitbake, "..") | ||
46 | bb.data.setVar('BBPATH', '%s:%s:%s' % (topdir, datadir, basedir), data) | ||
47 | |||
48 | |||
49 | def supports(fn, d): | ||
50 | return localpath(fn, d)[-5:] == ".conf" | ||
51 | |||
52 | def localpath(fn, d): | ||
53 | if os.path.exists(fn): | ||
54 | return fn | ||
55 | |||
56 | if "://" not in fn: | ||
57 | return fn | ||
58 | |||
59 | localfn = None | ||
60 | try: | ||
61 | localfn = bb.fetch.localpath(fn, d, False) | ||
62 | except bb.MalformedUrl: | ||
63 | pass | ||
64 | |||
65 | if not localfn: | ||
66 | return fn | ||
67 | return localfn | ||
68 | |||
69 | def obtain(fn, data): | ||
70 | import sys, bb | ||
71 | fn = bb.data.expand(fn, data) | ||
72 | localfn = bb.data.expand(localpath(fn, data), data) | ||
73 | |||
74 | if localfn != fn: | ||
75 | dldir = bb.data.getVar('DL_DIR', data, 1) | ||
76 | if not dldir: | ||
77 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: DL_DIR not defined") | ||
78 | return localfn | ||
79 | bb.mkdirhier(dldir) | ||
80 | try: | ||
81 | bb.fetch.init([fn], data) | ||
82 | except bb.fetch.NoMethodError: | ||
83 | (type, value, traceback) = sys.exc_info() | ||
84 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: no method: %s" % value) | ||
85 | return localfn | ||
86 | |||
87 | try: | ||
88 | bb.fetch.go(data) | ||
89 | except bb.fetch.MissingParameterError: | ||
90 | (type, value, traceback) = sys.exc_info() | ||
91 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: missing parameters: %s" % value) | ||
92 | return localfn | ||
93 | except bb.fetch.FetchError: | ||
94 | (type, value, traceback) = sys.exc_info() | ||
95 | bb.msg.debug(1, bb.msg.domain.Parsing, "obtain: failed: %s" % value) | ||
96 | return localfn | ||
97 | return localfn | ||
98 | |||
99 | |||
100 | def include(oldfn, fn, data, error_out): | ||
101 | """ | ||
102 | |||
103 | error_out If True a ParseError will be reaised if the to be included | ||
104 | """ | ||
105 | if oldfn == fn: # prevent infinate recursion | ||
106 | return None | ||
107 | |||
108 | import bb | ||
109 | fn = bb.data.expand(fn, data) | ||
110 | oldfn = bb.data.expand(oldfn, data) | ||
111 | |||
112 | if not os.path.isabs(fn): | ||
113 | dname = os.path.dirname(oldfn) | ||
114 | bbpath = "%s:%s" % (dname, bb.data.getVar("BBPATH", data, 1)) | ||
115 | abs_fn = bb.which(bbpath, fn) | ||
116 | if abs_fn: | ||
117 | fn = abs_fn | ||
118 | |||
119 | from bb.parse import handle | ||
120 | try: | ||
121 | ret = handle(fn, data, True) | ||
122 | except IOError: | ||
123 | if error_out: | ||
124 | raise ParseError("Could not %(error_out)s file %(fn)s" % vars() ) | ||
125 | bb.msg.debug(2, bb.msg.domain.Parsing, "CONF file '%s' not found" % fn) | ||
126 | |||
127 | def handle(fn, data, include = 0): | ||
128 | if include: | ||
129 | inc_string = "including" | ||
130 | else: | ||
131 | inc_string = "reading" | ||
132 | init(data) | ||
133 | |||
134 | if include == 0: | ||
135 | oldfile = None | ||
136 | else: | ||
137 | oldfile = bb.data.getVar('FILE', data) | ||
138 | |||
139 | fn = obtain(fn, data) | ||
140 | if not os.path.isabs(fn): | ||
141 | f = None | ||
142 | bbpath = bb.data.getVar("BBPATH", data, 1) or [] | ||
143 | for p in bbpath.split(":"): | ||
144 | currname = os.path.join(p, fn) | ||
145 | if os.access(currname, os.R_OK): | ||
146 | f = open(currname, 'r') | ||
147 | abs_fn = currname | ||
148 | bb.msg.debug(2, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string, currname)) | ||
149 | break | ||
150 | if f is None: | ||
151 | raise IOError("file '%s' not found" % fn) | ||
152 | else: | ||
153 | f = open(fn,'r') | ||
154 | bb.msg.debug(1, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string,fn)) | ||
155 | abs_fn = fn | ||
156 | |||
157 | if include: | ||
158 | bb.parse.mark_dependency(data, abs_fn) | ||
159 | |||
160 | lineno = 0 | ||
161 | bb.data.setVar('FILE', fn, data) | ||
162 | while 1: | ||
163 | lineno = lineno + 1 | ||
164 | s = f.readline() | ||
165 | if not s: break | ||
166 | w = s.strip() | ||
167 | if not w: continue # skip empty lines | ||
168 | s = s.rstrip() | ||
169 | if s[0] == '#': continue # skip comments | ||
170 | while s[-1] == '\\': | ||
171 | s2 = f.readline()[:-1].strip() | ||
172 | lineno = lineno + 1 | ||
173 | s = s[:-1] + s2 | ||
174 | feeder(lineno, s, fn, data) | ||
175 | |||
176 | if oldfile: | ||
177 | bb.data.setVar('FILE', oldfile, data) | ||
178 | return data | ||
179 | |||
180 | def feeder(lineno, s, fn, data): | ||
181 | def getFunc(groupd, key, data): | ||
182 | if 'flag' in groupd and groupd['flag'] != None: | ||
183 | return bb.data.getVarFlag(key, groupd['flag'], data) | ||
184 | else: | ||
185 | return bb.data.getVar(key, data) | ||
186 | |||
187 | m = __config_regexp__.match(s) | ||
188 | if m: | ||
189 | groupd = m.groupdict() | ||
190 | key = groupd["var"] | ||
191 | if "exp" in groupd and groupd["exp"] != None: | ||
192 | bb.data.setVarFlag(key, "export", 1, data) | ||
193 | if "ques" in groupd and groupd["ques"] != None: | ||
194 | val = getFunc(groupd, key, data) | ||
195 | if val == None: | ||
196 | val = groupd["value"] | ||
197 | elif "colon" in groupd and groupd["colon"] != None: | ||
198 | e = data.createCopy() | ||
199 | bb.data.update_data(e) | ||
200 | val = bb.data.expand(groupd["value"], e) | ||
201 | elif "append" in groupd and groupd["append"] != None: | ||
202 | val = "%s %s" % ((getFunc(groupd, key, data) or ""), groupd["value"]) | ||
203 | elif "prepend" in groupd and groupd["prepend"] != None: | ||
204 | val = "%s %s" % (groupd["value"], (getFunc(groupd, key, data) or "")) | ||
205 | elif "postdot" in groupd and groupd["postdot"] != None: | ||
206 | val = "%s%s" % ((getFunc(groupd, key, data) or ""), groupd["value"]) | ||
207 | elif "predot" in groupd and groupd["predot"] != None: | ||
208 | val = "%s%s" % (groupd["value"], (getFunc(groupd, key, data) or "")) | ||
209 | else: | ||
210 | val = groupd["value"] | ||
211 | if 'flag' in groupd and groupd['flag'] != None: | ||
212 | bb.msg.debug(3, bb.msg.domain.Parsing, "setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) | ||
213 | bb.data.setVarFlag(key, groupd['flag'], val, data) | ||
214 | else: | ||
215 | bb.data.setVar(key, val, data) | ||
216 | return | ||
217 | |||
218 | m = __include_regexp__.match(s) | ||
219 | if m: | ||
220 | s = bb.data.expand(m.group(1), data) | ||
221 | bb.msg.debug(3, bb.msg.domain.Parsing, "CONF %s:%d: including %s" % (fn, lineno, s)) | ||
222 | include(fn, s, data, False) | ||
223 | return | ||
224 | |||
225 | m = __require_regexp__.match(s) | ||
226 | if m: | ||
227 | s = bb.data.expand(m.group(1), data) | ||
228 | include(fn, s, data, "include required") | ||
229 | return | ||
230 | |||
231 | m = __export_regexp__.match(s) | ||
232 | if m: | ||
233 | bb.data.setVarFlag(m.group(1), "export", 1, data) | ||
234 | return | ||
235 | |||
236 | raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s)); | ||
237 | |||
238 | # Add us to the handlers list | ||
239 | from bb.parse import handlers | ||
240 | handlers.append({'supports': supports, 'handle': handle, 'init': init}) | ||
241 | del handlers | ||