/[gentoo]/src/packages/changelogs.py
Gentoo

Diff of /src/packages/changelogs.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.2.2.3
1#!/usr/bin/python -OO 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"""
2 13
3import mstring
4import re 14import re
15from cgi import escape
5 16
17BUG_REGEX = re.compile(r'((\B#|\bbug )([0-9]+))', re.I)
18DATE_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)
26GENTOO_DEV = re.compile(r'&lt;((.+))@gentoo.org&gt;', re.I)
6 27
7BUG_REGEX = re.compile(r'\b#[0-9]+|\bbug [0-9]+',re.I)
8BUG_URL = 'http://bugs.gentoo.org/show_bug.cgi?id='
9
10def bugs_to_html(s): 28def bugs_to_html(string):
11 index = 1 29 """Convert bug #'s to html, escape other html text"""
12 while 1: 30 string = string.strip()
31 string = escape(string)
32 string = BUG_REGEX.sub(r'<a href="/bugs/\3">\1</a>', string)
13 match = BUG_REGEX.search(s,index) 33 match = DATE_REGEX.search(string)
14 if not match: 34 if match:
15 break
16 start = match.start() 35 start = match.start()
17 end = match.end() 36 next = DATE_REGEX.search(string, match.end() + 1)
37 if next:
38 end = next.start() - 1
39 else:
40 end = len(string)
18 substring = s[start:end] 41 string = string[start:end]
19 if substring[0] == '#': # this of the form "#1234" 42 string = DATE_REGEX.sub(r'<span class="date">\1</span>: ', string)
20 bugid = substring[1:] 43 string = GENTOO_DEV.sub(r'(<a href="/stats/\2">\1</a>)', string)
21 else: # this is of the form "bug 1234" 44 return '<span class="change">%s</span>' % string
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 45
27def changelog(filename): 46def changelog(filename):
47 """(Try to) Extract only the most recent bits from a changelog file"""
28 try: 48 try:
29 #print filename 49 #print filename
30 fp = open(filename,'r') 50 _file = file(filename, 'r')
31 except IOError: 51 except IOError:
32 return "" 52 return ""
33 53
34 54
35 s = "" 55 string = ""
36 # find first line that isn't blank or a comment 56 # find first line that isn't blank or a comment
37 while True: 57 while True:
38 line = fp.readline() 58 line = _file.readline()
39 if not line: break 59 if not line:
60 break
40 #print line 61 #print line
41 if line[0] not in ['#','','\n']: 62 if line[0] not in ['#', '', '\n']:
42 s = s + line 63 string = string + line
43 break 64 break
44 65
45 # append next strings until you reach next "*" 66 # append next strings until you reach next "*"
46 while True: 67 while True:
47 line = fp.readline() 68 line = _file.readline()
48 #print repr(line) 69 #print repr(line)
49 if not line or line[0] == '*': break 70 if not line or line[0] == '*':
71 break
50 else: s= s + line 72 else: string = string + line
51 73
52 return s 74 return string

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.2.2.3

  ViewVC Help
Powered by ViewVC 1.1.20