From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mail.openembedded.org (Postfix) with ESMTP id 239F7772BA for ; Wed, 21 Dec 2016 15:05:25 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP; 21 Dec 2016 07:05:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,384,1477983600"; d="scan'208";a="1085082128" Received: from linux.intel.com ([10.54.29.200]) by fmsmga001.fm.intel.com with ESMTP; 21 Dec 2016 07:05:26 -0800 Received: from vmed.fi.intel.com (vmed.fi.intel.com [10.237.72.38]) by linux.intel.com (Postfix) with ESMTP id 0946F6A4080; Wed, 21 Dec 2016 07:04:36 -0800 (PST) From: Ed Bartosh To: openembedded-core@lists.openembedded.org Date: Wed, 21 Dec 2016 17:05:11 +0200 Message-Id: <1482332711-23829-1-git-send-email-ed.bartosh@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [wic][PATCH v2] wic: fix parsing of 'bitbake -e' output X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2016 15:05:26 -0000 Current parsing code can wrongly interpret arbitrary lines that are of 'key=value' format as legitimate bitbake variables. Implemented more strict parsing of key=value pairs using regular expressions. Signed-off-by: Ed Bartosh --- scripts/lib/wic/utils/oe/misc.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py index fe188c9..2a2fcc9 100644 --- a/scripts/lib/wic/utils/oe/misc.py +++ b/scripts/lib/wic/utils/oe/misc.py @@ -27,6 +27,7 @@ """Miscellaneous functions.""" import os +import re from collections import defaultdict from distutils import spawn @@ -148,21 +149,18 @@ class BitbakeVars(defaultdict): self.default_image = None self.vars_dir = None - def _parse_line(self, line, image): + def _parse_line(self, line, image, matcher=re.compile(r"^(\w+)=(.+)")): """ Parse one line from bitbake -e output or from .env file. Put result key-value pair into the storage. """ if "=" not in line: return - try: - key, val = line.split("=") - except ValueError: + match = matcher.match(line) + if not match: return - key = key.strip() - val = val.strip() - if key.replace('_', '').isalnum(): - self[image][key] = val.strip('"') + key, val = match.groups() + self[image][key] = val.strip('"') def get_var(self, var, image=None): """ -- 2.1.4