1 """class for handling configuration data files
3 Reads the file and obtains its metadata"""
5 import re, oe.data, os, sys
6 from oe import debug, fatal
8 #__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)$")
9 __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>\?)?=\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$")
10 __include_regexp__ = re.compile( r"include\s+(.+)" )
13 if not oe.data.getVar('TOPDIR', data):
14 oe.data.setVar('TOPDIR', os.getcwd(), data)
15 if not oe.data.getVar('OEPATH', data):
16 oebuild = os.path.abspath(sys.argv[0])
17 oebin = os.path.dirname(oebuild)
18 oedir = os.path.dirname(oebin)
19 oe.data.setVar('OEPATH', "${TOPDIR}:%s:%s:${HOME}/.oe:${OEDIR}/bin:${OEDIR}:%s/share/oe" % (oebin, oedir, sys.prefix), data)
21 # Package creation functions:
25 return localpath(fn, d)[-5:] == ".conf"
28 if os.path.exists(fn):
33 localfn = oe.fetch.localpath(fn, d)
34 except oe.MalformedUrl:
41 def obtain(fn, data = {}):
43 fn = oe.data.expand(fn, data)
44 localfn = oe.data.expand(localpath(fn, data), data)
47 dldir = oe.data.getVar('DL_DIR', data, 1)
49 debug(1, "obtain: DL_DIR not defined")
54 except oe.fetch.NoMethodError:
55 (type, value, traceback) = sys.exc_info()
56 debug(1, "obtain: no method: %s" % value)
61 except oe.fetch.MissingParameterError:
62 (type, value, traceback) = sys.exc_info()
63 debug(1, "obtain: missing parameters: %s" % value)
65 except oe.fetch.FetchError:
66 (type, value, traceback) = sys.exc_info()
67 debug(1, "obtain: failed: %s" % value)
72 def include(oldfn, fn, data = {}):
73 if oldfn == fn: # prevent infinate recursion
77 fn = oe.data.expand(fn, data)
78 oldfn = oe.data.expand(oldfn, data)
80 from oe.parse import handle
82 ret = handle(fn, data, 1)
84 debug(2, "CONF file '%s' not found" % fn)
86 def handle(fn, data = {}, include = 0):
88 inc_string = "including"
90 inc_string = "reading"
93 oe.data.inheritFromOS(data)
96 if not os.path.isabs(fn):
98 voepath = oe.data.getVar("OEPATH", data)
100 oepath += voepath.split(":")
102 currname = os.path.join(oe.data.expand(p, data), fn)
103 if os.access(currname, os.R_OK):
104 f = open(currname, 'r')
105 debug(1, "CONF %s %s" % (inc_string, currname))
108 raise IOError("file not found")
111 debug(1, "CONF %s %s" % (inc_string,fn))
118 if not w: continue # skip empty lines
120 if s[0] == '#': continue # skip comments
122 s2 = f.readline()[:-1].strip()
125 feeder(lineno, s, fn, data)
128 def feeder(lineno, s, fn, data = {}):
129 m = __config_regexp__.match(s)
131 groupd = m.groupdict()
133 if "exp" in groupd and groupd["exp"] != None:
134 oe.data.setVarFlag(key, "export", 1, data)
135 if "ques" in groupd and groupd["ques"] != None:
136 val = oe.data.getVar(key, data)
138 val = groupd["value"]
139 elif "colon" in groupd and groupd["colon"] != None:
140 val = oe.data.expand(groupd["value"], data)
142 val = groupd["value"]
143 if 'flag' in groupd and groupd['flag'] != None:
144 #oe.note("setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val))
145 oe.data.setVarFlag(key, groupd['flag'], val, data)
147 oe.data.setVar(key, val, data)
150 m = __include_regexp__.match(s)
152 s = oe.data.expand(m.group(1), data)
153 #debug(2, "CONF %s:%d: including %s" % (fn, lineno, s))
157 fatal("PARSER: %s:%d: unparsed line" % (fn, lineno));
159 # Add us to the handlers list
160 from oe.parse import handlers
161 handlers.append({'supports': supports, 'handle': handle, 'init': init})