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

Contents of /src/packages/changelogs.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2.2.1 - (show annotations) (download) (as text)
Tue Oct 4 03:17:31 2005 UTC (8 years, 11 months ago) by marduk
Branch: pre_2-0
Changes since 1.2: +60 -33 lines
File MIME type: text/x-python
This is the development code for what will eventually become version 2.0
of packages.gentoo.org (P2).  Finally commiting to CVS. It is mostly a
complete re-write, which explains the multitude of removals and additions.
The new code will use the Quixote framework
http://www.mems-exchange.org/software/quixote/

1 """Module to deal with Changelog files in the portage tree"""
2
3 from packages import mstring
4 import re
5 from cgi import escape
6
7 #BUG_REGEX = re.compile(r'\B#[0-9]+|\bbug [0-9]+', re.I)
8 BUG_REGEX = re.compile(r'((\B#|\bbug )([0-9]+))', re.I)
9 DATE_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)
12 GENTOO_DEV = re.compile(r'<((.+))@gentoo.org>', re.I)
13
14 def bugs_to_html(string):
15 """Convert bug #'s to html, escape other html text"""
16 string = string.strip()
17 string = escape(string)
18 ## index = 1
19 ## while 1:
20 ## match = BUG_REGEX.search(string, index)
21 ## if not match:
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:
36 start = match.start()
37 next = DATE_REGEX.search(string, match.end() + 1)
38 if next:
39 end = next.start() - 1
40 else:
41 end = len(string)
42 substring = string[start:end]
43 html = '<span class="change"><span class="date">%s</span>%s</span>' % \
44 (substring[:11], substring[11:])
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)
49 return string
50
51 def changelog(filename):
52 """(Try to) Extract only the most recent bits from a changelog file"""
53 try:
54 #print filename
55 _file = file(filename, 'r')
56 except IOError:
57 return ""
58
59
60 string = ""
61 # find first line that isn't blank or a comment
62 while True:
63 line = _file.readline()
64 if not line:
65 break
66 #print line
67 if line[0] not in ['#', '', '\n']:
68 string = string + line
69 break
70
71 # append next strings until you reach next "*"
72 while True:
73 line = _file.readline()
74 #print repr(line)
75 if not line or line[0] == '*':
76 break
77 else: string = string + line
78
79 return string

  ViewVC Help
Powered by ViewVC 1.1.20