All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Chan <aaron.chun.yew.chan@intel.com>
To: richard.purdie@linuxfoundation.org, yocto@yoctoproject.org
Cc: Aaron Chan <aaron.chun.yew.chan@intel.com>
Subject: [PATCH] [yocto-ab-helper] utils.py: Resolved unicode data expansion
Date: Wed,  4 Jul 2018 14:07:24 +0800	[thread overview]
Message-ID: <1530684444-8440-1-git-send-email-aaron.chun.yew.chan@intel.com> (raw)

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@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



             reply	other threads:[~2018-07-04  6:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-04  6:07 Aaron Chan [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-07-03  1:44 [PATCH] [yocto-ab-helper] utils.py: Resolved unicode data expansion Aaron Chan
2018-07-03 13:25 ` Richard Purdie
2018-07-04  6:42   ` Chan, Aaron Chun Yew
2018-07-04  7:51     ` Richard Purdie
2018-07-05  5:38       ` Chan, Aaron Chun Yew

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1530684444-8440-1-git-send-email-aaron.chun.yew.chan@intel.com \
    --to=aaron.chun.yew.chan@intel.com \
    --cc=richard.purdie@linuxfoundation.org \
    --cc=yocto@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.