| 1 |
#
|
| 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 |
|
| 14 |
import re
|
| 15 |
from cgi import escape
|
| 16 |
|
| 17 |
BUG_REGEX = re.compile(r'((\B#|\bbug )([0-9]+))', re.I)
|
| 18 |
DATE_REGEX = re.compile(r"""
|
| 19 |
(
|
| 20 |
[0-9]{2}\s # Day
|
| 21 |
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s # Month
|
| 22 |
[0-9]{4} # Year
|
| 23 |
)
|
| 24 |
[;:]""",
|
| 25 |
re.M|re.VERBOSE)
|
| 26 |
GENTOO_DEV = re.compile(r'<((.+))@gentoo.org>', re.I)
|
| 27 |
|
| 28 |
def bugs_to_html(string):
|
| 29 |
"""Convert bug #'s to html, escape other html text"""
|
| 30 |
string = string.strip()
|
| 31 |
string = escape(string)
|
| 32 |
string = BUG_REGEX.sub(r'<a href="/bugs/\3">\1</a>', string)
|
| 33 |
match = DATE_REGEX.search(string)
|
| 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 |
string = string[start:end]
|
| 42 |
string = DATE_REGEX.sub(r'<span class="date">\1</span>: ', string)
|
| 43 |
string = GENTOO_DEV.sub(r'(<a href="/stats/\2">\1</a>)', string)
|
| 44 |
return '<span class="change">%s</span>' % string
|
| 45 |
|
| 46 |
def changelog(filename):
|
| 47 |
"""(Try to) Extract only the most recent bits from a changelog file"""
|
| 48 |
try:
|
| 49 |
#print filename
|
| 50 |
_file = file(filename, 'r')
|
| 51 |
except IOError:
|
| 52 |
return ""
|
| 53 |
|
| 54 |
|
| 55 |
string = ""
|
| 56 |
# find first line that isn't blank or a comment
|
| 57 |
while True:
|
| 58 |
line = _file.readline()
|
| 59 |
if not line:
|
| 60 |
break
|
| 61 |
#print line
|
| 62 |
if line[0] not in ['#', '', '\n']:
|
| 63 |
string = string + line
|
| 64 |
break
|
| 65 |
|
| 66 |
# append next strings until you reach next "*"
|
| 67 |
while True:
|
| 68 |
line = _file.readline()
|
| 69 |
#print repr(line)
|
| 70 |
if not line or line[0] == '*':
|
| 71 |
break
|
| 72 |
else: string = string + line
|
| 73 |
|
| 74 |
return string
|