All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH] Recognize parameters surrounded by quotes v2
Date: Sat, 29 Jan 2011 21:22:21 -0200	[thread overview]
Message-ID: <1296343341-21198-1-git-send-email-lmr@redhat.com> (raw)

Sometime we need to pass the parameters which contains blanks and it
is usually done through surrounding it with quotes. So this patch use
re.findall() to try to recognize the parameter surrounded by quotes
and pass it as one single argument to the control file.

Kvm subtest would first benefit from this patch as we could pass
something like "vms='vm1 vm2'" to it.

Changes from v1:
- Isolate the parsing code to a specific classmethod.
- Create a simple unittest for the parsing code.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/bin/job.py          |    7 ++++++-
 client/bin/job_unittest.py |   13 +++++++++++++
 2 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/client/bin/job.py b/client/bin/job.py
index 3d5d937..3e285c6 100644
--- a/client/bin/job.py
+++ b/client/bin/job.py
@@ -135,6 +135,11 @@ class base_client_job(base_job.base_job):
         return autodir, clientdir, None
 
 
+    @classmethod
+    def _parse_args(cls, args):
+        return re.findall("[^\s]*?['|\"].*?['|\"]|[^\s]+", args)
+
+
     def _find_resultdir(self, options):
         """
         Determine the directory for storing results. On a client this is
@@ -243,7 +248,7 @@ class base_client_job(base_job.base_job):
 
         self.args = []
         if options.args:
-            self.args = options.args.split()
+            self.args = self._parse_args(options.args)
 
         if options.user:
             self.user = options.user
diff --git a/client/bin/job_unittest.py b/client/bin/job_unittest.py
index dba7e08..0e5aede 100755
--- a/client/bin/job_unittest.py
+++ b/client/bin/job_unittest.py
@@ -694,5 +694,18 @@ class test_base_job(unittest.TestCase):
         self.god.check_playback()
 
 
+    def test_parse_args(self):
+        test_set = {"a='foo bar baz' b='moo apt'":
+                    ["a='foo bar baz'", "b='moo apt'"],
+                    "a='foo bar baz' only=gah":
+                    ["a='foo bar baz'", "only=gah"],
+                    "a='b c d' no=argh":
+                    ["a='b c d'", "no=argh"]}
+        for t in test_set:
+            parsed_args = job.base_client_job._parse_args(t)
+            expected_args = test_set[t]
+            self.assertEqual(parsed_args, expected_args)
+
+
 if __name__ == "__main__":
     unittest.main()
-- 
1.7.3.5

                 reply	other threads:[~2011-01-29 23:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1296343341-21198-1-git-send-email-lmr@redhat.com \
    --to=lmr@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.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.