| 1 |
#!/usr/bin/python -OO |
| 2 |
|
| 3 |
import mstring |
| 4 |
import re |
| 5 |
|
| 6 |
|
| 7 |
BUG_REGEX = re.compile(r'#[0-9]+|bug [0-9]+',re.I) |
| 8 |
BUG_URL = 'http://bugs.gentoo.org/show_bug.cgi?id=' |
| 9 |
|
| 10 |
def bugs_to_html(s): |
| 11 |
index = 1 |
| 12 |
while 1: |
| 13 |
match = BUG_REGEX.search(s,index) |
| 14 |
if not match: |
| 15 |
break |
| 16 |
start = match.start() |
| 17 |
end = match.end() |
| 18 |
substring = s[start:end] |
| 19 |
if substring[0] == '#': # this of the form "#1234" |
| 20 |
bugid = substring[1:] |
| 21 |
else: # this is of the form "bug 1234" |
| 22 |
bugid = substring[4:] |
| 23 |
url = '<a href="%s%s">%s</a>' % (BUG_URL,bugid,substring) |
| 24 |
(s,index) = mstring.replace_sub(s,url,start,end-1) |
| 25 |
return s |
| 26 |
|
| 27 |
def changelog(filename): |
| 28 |
try: |
| 29 |
#print filename |
| 30 |
fp = open(filename,'r') |
| 31 |
except IOError: |
| 32 |
return "" |
| 33 |
|
| 34 |
|
| 35 |
s = "" |
| 36 |
# find first line that isn't blank or a comment |
| 37 |
while True: |
| 38 |
line = fp.readline() |
| 39 |
if not line: break |
| 40 |
#print line |
| 41 |
if line[0] not in ['#','','\n']: |
| 42 |
s = s + line |
| 43 |
break |
| 44 |
|
| 45 |
# append next strings until you reach next "*" |
| 46 |
while True: |
| 47 |
line = fp.readline() |
| 48 |
#print repr(line) |
| 49 |
if not line or line[0] == '*': break |
| 50 |
else: s= s + line |
| 51 |
|
| 52 |
return s |