/[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.1
1#!/usr/bin/python -OO 1"""Module to deal with Changelog files in the portage tree"""
2 2
3import mstring 3from packages import mstring
4import re 4import re
5from cgi import escape
5 6
7#BUG_REGEX = re.compile(r'\B#[0-9]+|\bbug [0-9]+', re.I)
8BUG_REGEX = re.compile(r'((\B#|\bbug )([0-9]+))', re.I)
9DATE_REGEX = re.compile(
10 r'[0-9]{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{4}[;:]',
11 re.M)
12GENTOO_DEV = re.compile(r'<((.+))@gentoo.org>', re.I)
6 13
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): 14def bugs_to_html(string):
15 """Convert bug #'s to html, escape other html text"""
16 string = string.strip()
17 string = escape(string)
11 index = 1 18## index = 1
12 while 1: 19## while 1:
13 match = BUG_REGEX.search(s,index) 20## match = BUG_REGEX.search(string, index)
14 if not match: 21## if not match:
15 break 22## break
23## start = match.start()
24## end = match.end()
25## substring = string[start:end]
26## if substring[0] == '#': # this of the form "#1234"
27## bugid = substring[1:]
28## else: # this is of the form "bug 1234"
29## bugid = substring[4:]
30## url = '<a href="/bugs/%s">%s</a>' % (bugid, substring)
31## (string, index) = mstring.replace_sub(string, url, start , end-1)
32 index = 0
33 string = BUG_REGEX.sub(r'<a href="/bugs/\3">\1</a>', string)
34 match = DATE_REGEX.search(string, index)
35 if match:
16 start = match.start() 36 start = match.start()
17 end = match.end() 37 next = DATE_REGEX.search(string, match.end() + 1)
38 if next:
39 end = next.start() - 1
40 else:
41 end = len(string)
18 substring = s[start:end] 42 substring = string[start:end]
19 if substring[0] == '#': # this of the form "#1234" 43 html = '<span class="change"><span class="date">%s</span>%s</span>' % \
20 bugid = substring[1:] 44 (substring[:11], substring[11:])
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) 45 (string, index) = mstring.replace_sub(string[:end+1], html, start, end)
46 #s = '<ul>' + s + '</ul>\n'
47 # convert email address to links to CIA stats
48 string = GENTOO_DEV.sub(r'(<a href="/stats/\2">\1</a>)', string)
25 return s 49 return string
26 50
27def changelog(filename): 51def changelog(filename):
52 """(Try to) Extract only the most recent bits from a changelog file"""
28 try: 53 try:
29 #print filename 54 #print filename
30 fp = open(filename,'r') 55 _file = file(filename, 'r')
31 except IOError: 56 except IOError:
32 return "" 57 return ""
33 58
34 59
35 s = "" 60 string = ""
36 # find first line that isn't blank or a comment 61 # find first line that isn't blank or a comment
37 while True: 62 while True:
38 line = fp.readline() 63 line = _file.readline()
39 if not line: break 64 if not line:
65 break
40 #print line 66 #print line
41 if line[0] not in ['#','','\n']: 67 if line[0] not in ['#', '', '\n']:
42 s = s + line 68 string = string + line
43 break 69 break
44 70
45 # append next strings until you reach next "*" 71 # append next strings until you reach next "*"
46 while True: 72 while True:
47 line = fp.readline() 73 line = _file.readline()
48 #print repr(line) 74 #print repr(line)
49 if not line or line[0] == '*': break 75 if not line or line[0] == '*':
76 break
50 else: s= s + line 77 else: string = string + line
51 78
52 return s 79 return string

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

  ViewVC Help
Powered by ViewVC 1.1.20