def get_var(self, var, image=None, cache=True): """ Get bitbake variable from 'bitbake -e' output or from .env file. This is a lazy method, i.e. it runs bitbake or parses file only when only when variable is requested. It also caches results. """ if not image: image = self.default_image if image not in self: if image and self.vars_dir: fname = os.path.join(self.vars_dir, image + '.env') if os.path.isfile(fname): # parse .env file with open(fname) as varsfile: for line in varsfile: self._parse_line(line, image) else: print("Couldn't get bitbake variable from %s." % fname) print("File %s doesn't exist." % fname) return else: # Get bitbake -e output cmd = "bitbake -e" if image: cmd += " %s" % image log_level = msger.get_loglevel() msger.set_loglevel('normal') ret, lines = _exec_cmd(cmd) msger.set_loglevel(log_level) if ret: print("Couldn't get '%s' output." % cmd) print("Bitbake failed with error:\n%s\n" % lines) return # Parse bitbake -e output for line in lines.split('\n'): self._parse_line(line, image) # Make first image a default set of variables if cache: images = [key for key in self if key] if len(images) == 1: self[None] = self[image] result = self[image].get(var) if not cache: self.pop(image, None) return result
def get_bitbake_var(var, image=None): """ Get bitbake variable value lazy way, i.e. run 'bitbake -e' only when variable is requested. """ if image not in _BITBAKE_VARS: # Get bitbake -e output cmd = "bitbake -e" if image: cmd += " %s" % image log_level = msger.get_loglevel() msger.set_loglevel('normal') rc, lines = __exec_cmd(cmd) msger.set_loglevel(log_level) if rc: print "Couldn't get '%s' output." % cmd print "Bitbake failed with error:\n%s\n" % lines return # Parse bitbake -e output for line in lines.split('\n'): if "=" not in line: continue try: key, val = line.split("=") except ValueError: continue key = key.strip() val = val.strip() if key.replace('_', '').isalnum(): _BITBAKE_VARS[image][key] = val.strip('"') # Make first image a default set of variables images = [key for key in _BITBAKE_VARS if key] if len(images) == 1: _BITBAKE_VARS[None] = _BITBAKE_VARS[image] return _BITBAKE_VARS[image].get(var)
def get_bitbake_var(var, image=None): """ Get bitbake variable value lazy way, i.e. run 'bitbake -e' only when variable is requested. """ if image not in _BITBAKE_VARS: # Get bitbake -e output cmd = "bitbake -e" if image: cmd += " %s" % image log_level = msger.get_loglevel() msger.set_loglevel('normal') ret, lines = __exec_cmd(cmd) msger.set_loglevel(log_level) if ret: print "Couldn't get '%s' output." % cmd print "Bitbake failed with error:\n%s\n" % lines return # Parse bitbake -e output for line in lines.split('\n'): if "=" not in line: continue try: key, val = line.split("=") except ValueError: continue key = key.strip() val = val.strip() if key.replace('_', '').isalnum(): _BITBAKE_VARS[image][key] = val.strip('"') # Make first image a default set of variables images = [key for key in _BITBAKE_VARS if key] if len(images) == 1: _BITBAKE_VARS[None] = _BITBAKE_VARS[image] return _BITBAKE_VARS[image].get(var)