is_statement() returns a match object or None, from statement_pat.match()...
>
> def is_traceback(line):
> - return 'traceback' in line.lower() or '== EXTRA DATA ==' in line
> + return line.lower().startswith('traceback') or line.startswith(
> + '== EXTRA DATA ==')
>
> req_vars = []
> statements = []
> first_tb_line = ''
> for line in lines:
> + first_tb_line = line
> line = line.strip()
> if line == '':
> continue
> else:
> - if is_req_var(line):
> - key, value = line.split('=', 1)
> - req_vars.append((urllib.unquote(key), urllib.unquote(value)))
> - elif is_statement(line):
> - match = re.match(
> - r'^(\d+)-(\d+)(?:@([\w-]+))?\s+(.*)', line)
> + if is_statement(line):
> + match = statement_pat.match(line)
> assert match is not None, (
> "Unable to interpret oops line: %s" % line)
... and here, statement_pat.match() is called again. I think
you don't need is_statement() at all: Something like
match = statement_pat.match(line)
if match is not None:
start, end, db_id, statement = match.groups()
Hi Diogo,
the branch looks good.
Just a minor suggestion:
> === modified file 'oops_datedir_ repo/serializer _rfc822. py' repo/serializer _rfc822. py 2011-08-25 20:53:24 +0000 repo/serializer _rfc822. py 2011-08-26 14:17:14 +0000 'exception- value') 'date') parse_date( msg.getheader( 'date') ) parse_date( msg.getheader( 'date') ) 'topic' ) 'user') 'url') msg.getheader( 'duration' , '-1'))) getheader( 'duration' , '-1')) 'informational' ) 'branch' ) 'revision' ) r'^(\d+ )-(\d+) (?:@([\ w-]+))? \s+(.*) ') r'^(\d+ )-(\d+) (?:@([\ w-]+))? \s+(.*) ', line) pat.match( line)
> --- oops_datedir_
> +++ oops_datedir_
> @@ -70,7 +70,7 @@
> exc_value = msg.getheader(
> datestr = msg.getheader(
> if datestr is not None:
> - date =iso8601.
> + date = iso8601.
> else:
> date = None
> topic = msg.getheader(
> @@ -79,9 +79,9 @@
> username = msg.getheader(
> url = msg.getheader(
> try:
> - duration = int(float(
> + duration = float(msg.
> except ValueError:
> - duration = -1
> + duration = float(-1)
> informational = msg.getheader(
> branch_nick = msg.getheader(
> revno = msg.getheader(
> @@ -94,28 +94,27 @@
> lines = iter(msg.fp)
>
> def is_req_var(line):
> - return "=" in line
> + return "=" in line and not is_statement(line)
>
> + statement_pat = re.compile(
> def is_statement(line):
> - return re.match(
> + return statement_
is_statement() returns a match object or None, from statement_ pat.match( )...
> ).startswith( 'traceback' ) or line.startswith( append( (urllib. unquote( key), urllib. unquote( value)) ) )-(\d+) (?:@([\ w-]+))? \s+(.*) ', line) pat.match( line)
> def is_traceback(line):
> - return 'traceback' in line.lower() or '== EXTRA DATA ==' in line
> + return line.lower(
> + '== EXTRA DATA ==')
>
> req_vars = []
> statements = []
> first_tb_line = ''
> for line in lines:
> + first_tb_line = line
> line = line.strip()
> if line == '':
> continue
> else:
> - if is_req_var(line):
> - key, value = line.split('=', 1)
> - req_vars.
> - elif is_statement(line):
> - match = re.match(
> - r'^(\d+
> + if is_statement(line):
> + match = statement_
> assert match is not None, (
> "Unable to interpret oops line: %s" % line)
... and here, statement_ pat.match( ) is called again. I think
you don't need is_statement() at all: Something like
match = statement_ pat.match( line)
if match is not None:
start, end, db_id, statement = match.groups()
would be "good enough" :)