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

Contents of /src/packages/changelogs.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2.2.3 - (hide annotations) (download) (as text)
Wed Oct 5 22:18:25 2005 UTC (8 years, 11 months ago) by marduk
Branch: pre_2-0
Changes since 1.2.2.2: +12 -28 lines
File MIME type: text/x-python
Removed dependency on mstring.py

1 marduk 1.2.2.2 #
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 marduk 1.2.2.1 """Module to deal with Changelog files in the portage tree"""
13 marduk 1.1
14     import re
15 marduk 1.2.2.1 from cgi import escape
16 marduk 1.1
17 marduk 1.2.2.1 BUG_REGEX = re.compile(r'((\B#|\bbug )([0-9]+))', re.I)
18 marduk 1.2.2.3 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 marduk 1.2.2.1 GENTOO_DEV = re.compile(r'&lt;((.+))@gentoo.org&gt;', 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 marduk 1.2.2.3 match = DATE_REGEX.search(string)
34 marduk 1.2.2.1 if match:
35 marduk 1.2 start = match.start()
36 marduk 1.2.2.1 next = DATE_REGEX.search(string, match.end() + 1)
37     if next:
38     end = next.start() - 1
39     else:
40     end = len(string)
41 marduk 1.2.2.3 string = string[start:end]
42     string = DATE_REGEX.sub(r'<span class="date">\1</span>: ', string)
43 marduk 1.2.2.1 string = GENTOO_DEV.sub(r'(<a href="/stats/\2">\1</a>)', string)
44 marduk 1.2.2.3 return '<span class="change">%s</span>' % string
45 marduk 1.1
46     def changelog(filename):
47 marduk 1.2.2.1 """(Try to) Extract only the most recent bits from a changelog file"""
48 marduk 1.2 try:
49     #print filename
50 marduk 1.2.2.1 _file = file(filename, 'r')
51 marduk 1.2 except IOError:
52     return ""
53 marduk 1.1
54    
55 marduk 1.2.2.1 string = ""
56 marduk 1.2 # find first line that isn't blank or a comment
57     while True:
58 marduk 1.2.2.1 line = _file.readline()
59     if not line:
60     break
61 marduk 1.2 #print line
62 marduk 1.2.2.1 if line[0] not in ['#', '', '\n']:
63     string = string + line
64 marduk 1.2 break
65 marduk 1.2.2.1
66 marduk 1.2 # append next strings until you reach next "*"
67     while True:
68 marduk 1.2.2.1 line = _file.readline()
69 marduk 1.2 #print repr(line)
70 marduk 1.2.2.1 if not line or line[0] == '*':
71     break
72     else: string = string + line
73    
74     return string

  ViewVC Help
Powered by ViewVC 1.1.20