/[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.2.3 Revision 1.6
9# along with this program; if not, write to the Free Software Foundation, 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 10# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
11# 11#
12"""Module to deal with Changelog files in the portage tree""" 12"""Module to deal with Changelog files in the portage tree"""
13 13
14import mstring
14import re 15import re
15from cgi import escape 16from cgi import escape
16 17
18#BUG_REGEX = re.compile(r'#[0-9]+|bug [0-9]+',re.I)
17BUG_REGEX = re.compile(r'((\B#|\bbug )([0-9]+))', re.I) 19BUG_REGEX = re.compile(r'((\B#|\bbug )([0-9]+))', re.I)
18DATE_REGEX = re.compile(r""" 20DATE_REGEX = re.compile(
19 ( 21 r'[0-9]{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{4}[;:]',
20 [0-9]{2}\s # Day 22 re.M)
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'<((.+))@gentoo.org>', re.I) 23GENTOO_DEV = re.compile(r'<((.+))@gentoo.org>', re.I)
24BUG_URL = 'http://bugs.gentoo.org/show_bug.cgi?id='
25CIA_URL = 'http://cia.navi.cx/stats/author/'
27 26
28def bugs_to_html(string): 27def bugs_to_html(string):
29 """Convert bug #'s to html, escape other html text""" 28 """Convert bug #'s to html, escape other html text"""
30 string = string.strip() 29 string = string.strip()
31 string = escape(string) 30 string = escape(string)
31 index = 0
32 string = BUG_REGEX.sub(r'<a href="/bugs/\3">\1</a>', string) 32 string = BUG_REGEX.sub('<a href="%s\\3">\\1</a>' % BUG_URL, string)
33 match = DATE_REGEX.search(string) 33 match = DATE_REGEX.search(string, index)
34 if match: 34 if match:
35 start = match.start() 35 start = match.start()
36 next = DATE_REGEX.search(string, match.end() + 1) 36 next = DATE_REGEX.search(string, match.end() + 1)
37 if next: 37 if next:
38 end = next.start() - 1 38 end = next.start() - 1
39 else: 39 else:
40 end = len(string) 40 end = len(string)
41 string = string[start:end] 41 substring = string[start:end]
42 string = DATE_REGEX.sub(r'<span class="date">\1</span>: ', string) 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)
43 string = GENTOO_DEV.sub(r'(<a href="/stats/\2">\1</a>)', string) 45 string = GENTOO_DEV.sub('(<a href="%s\\2">\\1</a>)' % CIA_URL, string)
44 return '<span class="change">%s</span>' % string 46 return '<span class="change">%s\n\n</span>' % string
45 47
46def changelog(filename): 48def changelog(filename):
47 """(Try to) Extract only the most recent bits from a changelog file""" 49 try:
48 try:
49 #print filename 50 #print filename
50 _file = file(filename, 'r') 51 fp = open(filename,'r')
51 except IOError: 52 except IOError:
52 return "" 53 return ""
53 54
54 55
55 string = "" 56 s = ""
56 # find first line that isn't blank or a comment 57 # find first line that isn't blank or a comment
57 while True: 58 while True:
58 line = _file.readline() 59 line = fp.readline()
59 if not line: 60 if not line: break
60 break 61 #print line
61 #print line
62 if line[0] not in ['#', '', '\n']: 62 if line[0] not in ['#','','\n']:
63 string = string + line 63 s = s + line
64 break 64 break
65 65
66 # append next strings until you reach next "*" 66 # append next strings until you reach next "*"
67 while True: 67 while True:
68 line = _file.readline() 68 line = fp.readline()
69 #print repr(line) 69 #print repr(line)
70 if not line or line[0] == '*': 70 if not line or line[0] == '*': break
71 break 71 else: s= s + line
72 else: string = string + line 72
73 73 return s
74 return string

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

  ViewVC Help
Powered by ViewVC 1.1.20