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

Contents of /src/packages/changelogs.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2.2.2 - (hide annotations) (download) (as text)
Tue Oct 4 17:04:05 2005 UTC (8 years, 11 months ago) by marduk
Branch: pre_2-0
Changes since 1.2.2.1: +11 -0 lines
File MIME type: text/x-python
Refactoring.

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

  ViewVC Help
Powered by ViewVC 1.1.20