How about just this:
def repl(m):
issues = m.group(1).split(', ')
return ", ".join("<a href='
http://code.google.com/p/chromium/issues/detail?id=%s'>%s</a>" % (s, s) for
s in issues)
if __name__ == '__main__':
description = "\nBUG=2, 3"
description = re.sub("\nBUG=(\d+[, \d+]*)", repl, description)
print description
Works great!
- Mohamed Mansour
On Wed, Sep 9, 2009 at 11:25 PM, Jeremy Orlow <[email protected]> wrote:
> I don't have a rietveld dev environment set up, so I wrote a quick script
> to test the general algorithm. It's not as pythony as I'd like, but it
> seems to be fairly robust:
> #!/usr/bin/python
> import re
>
> description = """\
> Blah blah blah.
> Blaaahhhh
>
> TEST=none
> BUG=123,456, 798,0
> BUG=888
> BUG=none
> BUG = none, 2349,2,asdf
> BUG = http://crbug.com/123
> BUG = crbug.com/234 crbug/82
> """
>
> LINK = "<a href='http://code.google.com/p/chromium/issues/detail?id=%s
> '>%s</a>"
> def rewrite_bug_numbers(string):
> if ',' in string:
> right, left = string.split(',', 1)
> return rewrite_bug_numbers(right) + ',' + rewrite_bug_numbers(left)
> if ' ' in string:
> right, left = string.split(' ', 1)
> return rewrite_bug_numbers(right) + ' ' + rewrite_bug_numbers(left)
>
> # Base cases:
> if string.isdigit():
> return LINK % (string, string)
> match = re.search(r'^(http://|)crbug.com/(\d+)', string)
> if match:
> return LINK % (match.group(2), string)
> return string
>
> output = []
> for line in description.splitlines():
> match = re.search(r'^(\s*BUG\s*=)(.*)$', line)
> if match:
> line = match.group(1) + rewrite_bug_numbers(match.group(2))
> output.append(line)
> print "<br>\n".join(output)
>
>
>
> Prints out
>
> Blah blah blah.<br>
> Blaaahhhh<br>
> <br>
> TEST=none<br>
> BUG=<a
> href='http://code.google.com/p/chromium/issues/detail?id=123'>123</a>,<a
> href='http://code.google.com/p/chromium/issues/detail?id=456'>456</a>, <a
> href='http://code.google.com/p/chromium/issues/detail?id=798'>798</a>,<a
> href='http://code.google.com/p/chromium/issues/detail?id=0'>0</a><br>
> BUG=<a href='http://code.google.com/p/chromium/issues/detail?id=888
> '>888</a><br>
> BUG=none<br>
> BUG = none, <a href='
> http://code.google.com/p/chromium/issues/detail?id=2349'>2349</a>,<a
> href='http://code.google.com/p/chromium/issues/detail?id=2'>2</a>,asdf<br>
> BUG = <a href='http://code.google.com/p/chromium/issues/detail?id=123'>
> http://crbug.com/123</a><br>
> BUG = <a href='http://code.google.com/p/chromium/issues/detail?id=234'>
> crbug.com/234</a> crbug/82
>
>
> If we weren't concerned about preserving formatting, you could do it with
> replace and split:
>
> line = "1234, 23 , 2"
> bugs = line.replace(",", " ").split()
>
>
> But it's not toooo much more work to keep in all the formatting.
>
>
> On Thu, Sep 10, 2009 at 11:01 AM, John Abd-El-Malek <[email protected]>wrote:
>
>> Thanks, glad you enjoy it :)
>> This was a side distraction to fix the annoying issue of having to
>> manually copying and pasting the bug ids. It severely tested my regex-fu
>> and since the multiple bugs case should be rare, I'll hide behind the excuse
>> that if they're duplicates they should be marked as such and only end up
>> with one, and if they're different bugs there should be separate changelists
>> ;) The rietveld change is at
>> http://code.google.com/p/rietveld/source/detail?r=455, if anyone sends me
>> a patch to make it work with multiple bug ids, I'd be happy to push it.
>>
>>
>> On Wed, Sep 9, 2009 at 6:15 PM, Mohamed Mansour <[email protected]> wrote:
>>
>>> Very nice, no longer I have to put crbug.com/#. Whoever did that
>>> autolink, can you support multiple bugs as well? The format bugdroid uses is
>>> BUG=1, 2, 3
>>> - Mohamed Mansour
>>>
>>>
>>>
>>> On Wed, Sep 9, 2009 at 8:58 PM, Paweł Hajdan Jr. <
>>> [email protected]> wrote:
>>>
>>>> I just noticed that BUG=1234 lines are autolinked to the correct bug
>>>> when viewed in Rietveld (codereview.chromium.org). This is very useful,
>>>> thanks!
>>>>
>>>>
>>>
>>>
>>>
>>
>> >>
>>
>
--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: [email protected]
View archives, change email options, or unsubscribe:
http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---