From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: autotest@test.kernel.org, kvm@vger.kernel.org,
Michael Goldish <mgoldish@redhat.com>
Subject: Re: [KVM-AUTOTEST PATCH 4/5] kvm_config: add helper to raise exception informing line number
Date: Tue, 11 Jan 2011 01:48:22 -0200 [thread overview]
Message-ID: <1294717702.15303.9.camel@freedom> (raw)
In-Reply-To: <1294330356-17043-5-git-send-email-ehabkost@redhat.com>
On Thu, 2011-01-06 at 14:12 -0200, Eduardo Habkost wrote:
> From: Eduardo Habkost <ehabkost@raisama.net>
>
> Useful for syntax or other errors on the config file. We want to tell
> the user on which file:line the error is located.
>
> Signed-off-by: Eduardo Habkost <ehabkost@raisama.net>
> ---
> client/tests/kvm/kvm_config.py | 16 +++++++++++++++-
> 1 files changed, 15 insertions(+), 1 deletions(-)
>
> diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py
> index 35e2ab9..c206743 100755
> --- a/client/tests/kvm/kvm_config.py
> +++ b/client/tests/kvm/kvm_config.py
> @@ -548,7 +548,8 @@ class configreader:
> self.filename = filename
> self.line_index = 0
> self.lines = []
> - for line in str.splitlines():
> + self.real_number = []
> + for num,line in enumerate(str.splitlines(), 1):
^ enumerate in py 2.4 takes exactly 1 argument, so it's not possible to
provide the enumerate start index like this,
http://docs.python.org/library/functions.html#enumerate
so we have to do something like:
+ sequence = str.splitlines()[1:]
+ for num,line in enumerate(sequence):
To make it py2.4 compliant.
I have read your patchset, looks good to me. Before applying it, I am
going to give Michael time so he can read the patches as well.
> line = line.rstrip().expandtabs()
> stripped_line = line.strip()
> indent = len(line) - len(stripped_line)
> @@ -557,6 +558,7 @@ class configreader:
> or stripped_line.startswith("//")):
> continue
> self.lines.append((line, stripped_line, indent))
> + self.real_number.append(num)
>
>
> def get_next_line(self):
> @@ -589,6 +591,18 @@ class configreader:
> """
> self.line_index = index
>
> + def raise_error(self, msg):
> + """Raise an error related to the last line returned by get_next_line()
> + """
> + if self.line_index == 0: # nothing was read. shouldn't happen, but...
> + line_id = 'BEGIN'
> + elif self.line_index >= len(self.lines): # past EOF
> + line_id = 'EOF'
> + else:
> + # line_index is the _next_ line. get the previous one
> + line_id = str(self.real_number[self.line_index-1])
> + raise error.AutotestError("%s:%s: %s" % (self.filename, line_id, msg))
> +
>
> # Array structure:
> # ----------------
next prev parent reply other threads:[~2011-01-11 3:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-06 16:12 [KVM-AUTOTEST PATCH 0/5] small kvm_config usability changes Eduardo Habkost
2011-01-06 16:12 ` [KVM-AUTOTEST PATCH 1/5] kvm_config: accept multiple filenames as argument Eduardo Habkost
2011-01-06 16:12 ` [KVM-AUTOTEST PATCH 2/5] kvm_config: print directly to stdout instead of using logging Eduardo Habkost
2011-01-06 16:12 ` [KVM-AUTOTEST PATCH 3/5] kvm_config: store filename on configreader Eduardo Habkost
2011-01-06 16:12 ` [KVM-AUTOTEST PATCH 4/5] kvm_config: add helper to raise exception informing line number Eduardo Habkost
2011-01-11 3:48 ` Lucas Meneghel Rodrigues [this message]
2011-01-11 12:52 ` Eduardo Habkost
2011-01-06 16:12 ` [KVM-AUTOTEST PATCH 5/5] kvm_config: inform filename and line number on error message Eduardo Habkost
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=1294717702.15303.9.camel@freedom \
--to=lmr@redhat.com \
--cc=autotest@test.kernel.org \
--cc=ehabkost@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mgoldish@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox