[yocto] [PATCH] [yocto-ab-helper] utils.py: Resolved unicode data expansion
Aaron Chan
aaron.chun.yew.chan at intel.com
Tue Jul 3 23:07:24 PDT 2018
Patch fix on utils:getconfig:expandresult function to handle the expansion
This patch is to add a condition to handle unicode entries as dict & list
have been handled during expandresult.
janitor/clobberdir: [line 46]: changes
from : trashdir = ourconfig["TRASH_DIR"]
to : trashdir = utils.getconfig("TRASH_DIR", ourconfig)
scripts/utils.py: [line 41-47]: added
getconfig invokes only unicode entries and handles the data expansions.
This allows ${BUILDDIR} to be expanded, to retain ${BUILDDIR} in ourconfig[c],
we should never invoke utils.getconfig("BUILDDIR", ourconfig) in our scripts
unless we intend to change the BUILDDIR paths.
Signed-off-by: Aaron Chan <aaron.chun.yew.chan at intel.com>
---
janitor/clobberdir | 5 ++---
scripts/utils.py | 8 ++++++++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/janitor/clobberdir b/janitor/clobberdir
index 5dab5af..5e04ed7 100755
--- a/janitor/clobberdir
+++ b/janitor/clobberdir
@@ -43,11 +43,10 @@ if "TRASH_DIR" not in ourconfig:
print("Please set TRASH_DIR in the configuration file")
sys.exit(1)
-trashdir = ourconfig["TRASH_DIR"]
+trashdir = utils.getconfig("TRASH_DIR", ourconfig)
for x in [clobberdir]:
if os.path.exists(x):
trashdest = trashdir + "/" + str(int(time.time())) + '-' + str(random.randrange(100, 100000, 2))
mkdir(trashdest)
- subprocess.check_call(['mv', x, trashdest])
-
+ subprocess.check_call(['mv', x, trashdest])
\ No newline at end of file
diff --git a/scripts/utils.py b/scripts/utils.py
index db1e3c2..373f8de 100644
--- a/scripts/utils.py
+++ b/scripts/utils.py
@@ -26,6 +26,7 @@ def configtrue(name, config):
# Handle variable expansion of return values, variables are of the form ${XXX}
# need to handle expansion in list and dicts
__expand_re__ = re.compile(r"\${[^{}@\n\t :]+}")
+__expansion__ = re.compile(r"\${(.+)}")
def expandresult(entry, config):
if isinstance(entry, list):
ret = []
@@ -37,6 +38,13 @@ def expandresult(entry, config):
for k in entry:
ret[expandresult(k, config)] = expandresult(entry[k], config)
return ret
+ if isinstance(entry, unicode):
+ entry = str(entry)
+ entryExpand = __expansion__.match(entry).group(1)
+ if entryExpand:
+ return entry.replace('${' + entryExpand + '}', config[entryExpand])
+ else:
+ return entry
if not isinstance(entry, str):
return entry
class expander:
--
2.7.4
More information about the yocto
mailing list