KVM test: kvm_config.py: parse extra strings passed as command line args
PATCH 1/4 KVM test: kvm_config.py: parse extra strings passed as command line args
This allows to quickly see the effect of some extra code, e.g.
./kvm_config.py tests.cfg "only my_set" "no qcow2"
The given strings may contain newlines.
Signed-off-by Michael Goldish <[email protected]>
--- client/tests/kvm/kvm_config.py | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
client/tests/kvm/kvm_config.py +6 -1
@@ -640,7 +640,9 @@ class FileReader(StrReader): if __name__ == "__main__": - parser = optparse.OptionParser("usage: %prog [options] <filename>") + parser = optparse.OptionParser('usage: %prog [options] filename ' + '[extra code] ...\n\nExample:\n\n ' + '%prog tests.cfg "only my_set" "no qcow2"') parser.add_option("-v", "--verbose", dest="debug", action="store_true", help="include debug messages in console output") parser.add_option("-f", "--fullname", dest="fullname", action="store_true",
@@ -653,6 +655,9 @@ if __name__ == "__main__": parser.error("filename required") c = Parser(args[0], debug=options.debug) + for s in args[1:]: + c.parse_string(s) + for i, d in enumerate(c.get_dicts()): if options.fullname: print "dict %4d: %s" % (i + 1, d["name"])
Signature · 1 line
1.7.3.4
PATCH 2/4 KVM test: kvm_config.py: allow 'include' when parsing strings
Currently 'include' is only allowed when parsing a file. This patch allows it to be used when parsing a string as well.
Signed-off-by Michael Goldish <[email protected]>
--- client/tests/kvm/kvm_config.py | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
client/tests/kvm/kvm_config.py +4 -5
@@ -441,11 +441,10 @@ class Parser(object): if len(words) < 2: raise ParserError("Syntax error: missing parameter", line, cr.filename, linenum) - if not isinstance(cr, FileReader): - raise ParserError("Cannot include because no file is " - "currently open", - line, cr.filename, linenum) - filename = os.path.join(os.path.dirname(cr.filename), words[1]) + filename = os.path.expanduser(words[1]) + if isinstance(cr, FileReader) and not os.path.isabs(filename): + filename = os.path.join(os.path.dirname(cr.filename), + filename) if not os.path.isfile(filename): self._warn("%r (%s:%s): file doesn't exist or is not a " "regular file", line, cr.filename, linenum)
Signature · 1 line
1.7.3.4
PATCH 3/4 KVM test: kvm_config.py: remove unnecessary 'string' import
In reply to Michael GoldishSigned-off-by Michael Goldish <[email protected]>
--- client/tests/kvm/kvm_config.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
client/tests/kvm/kvm_config.py +1 -1
@@ -5,7 +5,7 @@ KVM test configuration file parser @copyright: Red Hat 2008-2011 """ -import re, os, sys, optparse, collections, string +import re, os, sys, optparse, collections # Filter syntax:
Signature · 1 line
1.7.3.4
PATCH 4/4 KVM test: kvm_config.py: correct docstring of get_next_line()
In reply to Michael GoldishSigned-off-by Michael Goldish <[email protected]>
--- client/tests/kvm/kvm_config.py | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_config.py +1 -2
@@ -607,8 +607,7 @@ class StrReader(object): def get_next_line(self, prev_indent): """ - Get the next non-empty, non-comment line in the string, whose - indentation level is higher than prev_indent. + Get the next line in the current block. @param prev_indent: The indentation level of the previous block. @return: (line, indent, linenum), where indent is the line's
Signature · 1 line
1.7.3.4