| 1 |
marduk |
1.4 |
#
|
| 2 |
|
|
# Copyright (C) 2003-2005, marduk <marduk@python.net>
|
| 3 |
|
|
#
|
| 4 |
|
|
# This copyrighted material is made available to anyone wishing to use,
|
| 5 |
|
|
# modify, copy, or redistribute it subject to the terms and conditions
|
| 6 |
|
|
# of the GNU General Public License v.2.
|
| 7 |
|
|
#
|
| 8 |
|
|
# You should have received a copy of the GNU General Public License
|
| 9 |
|
|
# along with this program; if not, write to the Free Software Foundation,
|
| 10 |
|
|
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 11 |
|
|
#
|
| 12 |
|
|
"""Module to deal with Changelog files in the portage tree"""
|
| 13 |
marduk |
1.1 |
|
| 14 |
|
|
import mstring
|
| 15 |
|
|
import re
|
| 16 |
marduk |
1.4 |
from cgi import escape
|
| 17 |
marduk |
1.1 |
|
| 18 |
marduk |
1.4 |
#BUG_REGEX = re.compile(r'#[0-9]+|bug [0-9]+',re.I)
|
| 19 |
|
|
BUG_REGEX = re.compile(r'((\B#|\bbug )([0-9]+))', re.I)
|
| 20 |
|
|
DATE_REGEX = re.compile(
|
| 21 |
|
|
r'[0-9]{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{4}[;:]',
|
| 22 |
|
|
re.M)
|
| 23 |
|
|
GENTOO_DEV = re.compile(r'<((.+))@gentoo.org>', re.I)
|
| 24 |
marduk |
1.1 |
BUG_URL = 'http://bugs.gentoo.org/show_bug.cgi?id='
|
| 25 |
marduk |
1.4 |
CIA_URL = 'http://cia.navi.cx/stats/author/'
|
| 26 |
marduk |
1.1 |
|
| 27 |
marduk |
1.4 |
def bugs_to_html(string):
|
| 28 |
|
|
"""Convert bug #'s to html, escape other html text"""
|
| 29 |
|
|
string = string.strip()
|
| 30 |
|
|
string = escape(string)
|
| 31 |
|
|
index = 0
|
| 32 |
|
|
string = BUG_REGEX.sub('<a href="%s\\3">\\1</a>' % BUG_URL, string)
|
| 33 |
|
|
match = DATE_REGEX.search(string, index)
|
| 34 |
|
|
if match:
|
| 35 |
|
|
start = match.start()
|
| 36 |
|
|
next = DATE_REGEX.search(string, match.end() + 1)
|
| 37 |
|
|
if next:
|
| 38 |
|
|
end = next.start() - 1
|
| 39 |
|
|
else:
|
| 40 |
|
|
end = len(string)
|
| 41 |
|
|
substring = string[start:end]
|
| 42 |
|
|
html = '<span class="change"><span class="date">%s</span>%s</span>' % \
|
| 43 |
|
|
(substring[:11], substring[11:])
|
| 44 |
|
|
(string, index) = mstring.replace_sub(string[:end+1], html, start, end)
|
| 45 |
|
|
string = GENTOO_DEV.sub('(<a href="%s\\2">\\1</a>)' % CIA_URL, string)
|
| 46 |
marduk |
1.5 |
return '<span style="white-space: pre">%s\n\n</span>' % string
|
| 47 |
marduk |
1.1 |
|
| 48 |
|
|
def changelog(filename):
|
| 49 |
marduk |
1.3 |
try:
|
| 50 |
|
|
#print filename
|
| 51 |
|
|
fp = open(filename,'r')
|
| 52 |
|
|
except IOError:
|
| 53 |
|
|
return ""
|
| 54 |
marduk |
1.1 |
|
| 55 |
|
|
|
| 56 |
marduk |
1.3 |
s = ""
|
| 57 |
|
|
# find first line that isn't blank or a comment
|
| 58 |
|
|
while True:
|
| 59 |
|
|
line = fp.readline()
|
| 60 |
|
|
if not line: break
|
| 61 |
|
|
#print line
|
| 62 |
|
|
if line[0] not in ['#','','\n']:
|
| 63 |
|
|
s = s + line
|
| 64 |
|
|
break
|
| 65 |
|
|
|
| 66 |
|
|
# append next strings until you reach next "*"
|
| 67 |
|
|
while True:
|
| 68 |
|
|
line = fp.readline()
|
| 69 |
|
|
#print repr(line)
|
| 70 |
|
|
if not line or line[0] == '*': break
|
| 71 |
|
|
else: s= s + line
|
| 72 |
|
|
|
| 73 |
|
|
return s
|