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

Diff of /src/packages/gentoo.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.4 Revision 1.16.2.3
1#!/usr/bin/python -OO 1#!/usr/bin/python -O
2"""These functions mainly take ebuild info (grabbed from the database and 2"""These functions mainly take ebuild info (grabbed from the database and
3 convert it to HTML. See the "main" function at the bottom.""" 3 convert it to HTML. See the "main" function at the bottom."""
4 4
5__revision__ = "$Revision: 1.4 $" 5__revision__ = "$Revision: 1.16.2.3 $"
6# $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $ 6# $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $
7 7
8import config 8import config
9import os 9import os
10import time 10import time
11import string
11import sys 12import sys
12import ebuilddb 13import ebuilddb
13import bugs 14import bugs
14import changelogs 15import changelogs
15from cgi import escape 16from cgi import escape
16from urllib import quote 17from urllib import quote
18from portage_versions import pkgcmp, pkgsplit
17 19
18# import portage, but temporarily redirect stderr
19if 'portage' not in dir():
20 null = open('/dev/null', 'w')
21 tmp = sys.stderr
22 sys.stderr = null
23 sys.path = ["/usr/lib/portage/pym"]+sys.path
24 import portage
25 sys.stderr = tmp
26 sys.path = sys.path[1:]
27
28tree = portage.portdbapi('/usr/portage')
29
30def is_masked(ebuild):
31 """Return true if ebuild is masked"""
32
33 return (not tree.visible(['%(category)s/%(name)s-%(version)s' % ebuild]))
34
35def is_new(db, ebuild): 20def is_new(db, ebuild):
36 """Check for newness. An ebuild is considered new if it is the 21 """Check for newness."""
37 only ebuild with that category/name in ebuild and it has no prevarch""" 22
38
39 c = db.cursor() 23 c = db.cursor()
40 query = ('SELECT prevarch FROM ebuild WHERE category="%s" AND name="%s"' 24 query = ('SELECT new FROM package WHERE category="%s" AND name="%s"'
41 % (ebuild['category'], ebuild['name'])) 25 % (ebuild['category'], ebuild['name']))
42 c.execute(query) 26 c.execute(query)
43 results = c.fetchall() 27 results = c.fetchall()
44 if len(results) == 1 and results[0][0] is None: 28 if len(results) == 1 and results[0][0]:
45 return 1 29 return 1
46 return 0 30 return 0
47 31
48def changelog_to_html(changelog): 32changelog_to_html = changelogs.bugs_to_html
49 """HTML-ize a changelog entry"""
50 html = ""
51 for char in changelog:
52 if char == '\n':
53 html = "%s<br>" % html
54 else:
55 html = "%s%s" % (html, escape(char))
56 html = changelogs.bugs_to_html(html)
57 return html
58 33
59def homepage_to_html(homepage): 34def homepage_to_html(homepage):
60 """convert HOMEPAGE entry to HTML""" 35 """convert HOMEPAGE entry to HTML"""
61 if not homepage.strip(): 36 if not homepage.strip():
62 return "?" 37 return "?"
63 homepage = homepage.replace('|',' ') 38 homepage = homepage.replace('|',' ')
64 pieces = homepage.split() 39 pieces = homepage.split()
65 count = len(pieces) 40 count = len(pieces)
66 if count == 1: 41 if count == 1:
67 return ('<a class="homepage" href="%s">' 42 return ('<a class="homepage" href="%s">'
68 'Homepage</a>' % pieces[0]) 43 'Homepage</a>' % pieces[0])
69 44
70 html = ['[<a href="%s">%s</a>]' % (page, index + 1) for index, 45 html = ['[<a href="%s">%s</a>]' % (page, index + 1) for index,
71 page in enumerate(pieces)] 46 page in enumerate(pieces)]
72 return " ".join(['<span class="homepage">Homepages'] + html + 47 return " ".join(['<span class="homepage">Homepages'] + html +
73 ['</span>']) 48 ['</span>'])
74 49
75def license_to_html(license): 50def license_to_html(license):
76 """Create link to license[s]""" 51 """Create link to license[s]"""
77 if not license.strip(): return "?" 52 if not license.strip(): return "?"
78 license = license.replace('|',' ') 53 license = license.replace('|',' ')
54 license = license.replace('(', '')
55 license = license.replace(')', '')
79 pieces = license.split() 56 pieces = license.split()
80 html = ['<a href="http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/' 57 html = ['<a href="http://sources.gentoo.org/viewcvs.py/*checkout*/'
81 'licenses/%s">%s</a>' % (piece, piece) for piece in pieces] 58 'gentoo-x86/licenses/%s">%s</a>' % (piece, piece) for piece in pieces]
82 return '<br>\n'.join(html) 59 return '<br>\n'.join(html)
83 60
84def package_to_html(pkginfo, db): 61def package_to_html(pkginfo, db, full=False):
85 """This function needs a database (db) connection because it performs a 62 """This function needs a database (db) connection because it performs a
86 query_to_dict on the package""" 63 query_to_dict on the package"""
87 64
88 table_begin = '<table class="ebuild">' 65 table_begin = '<table class="ebuild">'
89 name = '<tr><td class="fields">%s</td></tr>' % pkginfo['name'] 66 name = '<tr><td class="fields">%s</td></tr>' % pkginfo['name']
67 if full:
68 image = ('<img class="pkgimg"alt="" src="%s/%s/%s.jpg" align="right">' %
69 (config.ICONS, pkginfo['category'], pkginfo['name'])
70 )
71 else:
72 image = ''
90 description = ('<tr><td class="item">' 73 description = ('<tr><td class="item">'
91 '<img align="right" alt="" src="%s/%s.png">'
92 '<b>Description: </b>%s</td></tr>' % (config.ICONS, 74 '%s<b>Description: </b>%s</td></tr>'
93 pkginfo['category'], escape(pkginfo['description']))) 75 % (image, escape(pkginfo['description']))
76 )
94 ebuilds = get_recent_releases(pkginfo, db) 77 ebuilds = get_recent_releases(pkginfo, db)
95 releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases') 78 releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases')
96 #bug_string = ('<br><h3>Related bugs:</h3>\n%s' 79 #bug_string = ('<br><h3>Related bugs:</h3>\n%s'
97 # % bugs_to_html(pkginfo['name'])) 80 # % bugs_to_html(pkginfo['name']))
98 general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo) 81 general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo)
82 #similar = '<tr><td>%s</td></tr>' % create_similar_pkgs_link(pkginfo)
99 table_end = '</table>' 83 table_end = '</table>'
100 rows = '\n\t'.join([name, description, releases, general]) 84 rows = '\n\t'.join([name, description, releases, general])
101 return '\n\t'.join([table_begin, rows, table_end]) 85 return '\n\t'.join([table_begin, rows, table_end])
102 86
103def archs_to_html(ebuilds, heading = None): 87def archs_to_html(ebuilds, heading = None):
104 """Create table for availability on each architecture""" 88 """Create table for availability on each architecture"""
105 heading = heading or '&nbsp;' 89 heading = heading or '&nbsp;'
106 table_begin = '<table class="releases">' 90 table_begin = '<table class="releases">'
107 header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] + 91 header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] +
108 ['<th class="arch">%s</th>' % i for i in config.ARCHLIST] + 92 ['<th class="arch">%s</th>' % i.replace('-',' ') for i in config.ARCHLIST] +
109 ['</tr>'] 93 ['</tr>']
110 ) 94 )
111 rows = [] 95 rows = []
96 ebuilds.sort(cmp_ebuilds)
97 ebuilds.reverse()
112 for ebuild in ebuilds: 98 for ebuild in ebuilds:
113 masked = is_masked(ebuild)
114 archs = ebuild['arch'].split() 99 archs = ebuild['arch'].split(',')
115 row_start = ('<tr>\n\t<th class="releases"><a href="%sebuilds/?%s-%s"' 100 row_start = ('<tr>\n\t<th class="releases"><a href="%sebuilds/?%s-%s"'
116 ' title="%s">%s</a></th>\n' % (config.FEHOME, 101 ' title="%s">%s</a></th>\n' % (config.FEHOME,
117 ebuild['name'], ebuild['version'], ebuild['time'], 102 ebuild['name'], ebuild['version'], ebuild['time'],
118 ebuild['version'])) 103 ebuild['version']))
119 row_data = [] 104 row_data = []
120 for arch in config.ARCHLIST: 105 for arch in config.ARCHLIST:
121 if arch in archs: 106 if arch in archs:
122 arch_string = '+' 107 arch_string = '+'
123 elif '~%s' % arch in archs: 108 elif '~%s' % arch in archs:
124 arch_string = '~' 109 arch_string = '~'
125 else: 110 else:
126 arch_string = '-' 111 arch_string = '-'
127 if arch_string != '-' and masked: 112 if arch_string != '-' and ebuild['masked']:
128 arch_string = 'M' + arch_string 113 arch_string = 'M' + arch_string
129 row_data.append('\t<td class="archcell" arch="%s">%s</td>' 114 row_data.append('\t<td class="archcell" arch="%s">%s</td>'
130 % (arch_string, arch_string)) 115 % (arch_string, arch_string))
131 row_end = '</tr>' 116 row_end = '</tr>'
132 rows.append('\n\t'.join([row_start] + row_data + [row_end])) 117 rows.append('\n\t'.join([row_start] + row_data + [row_end]))
133 table_end = '</table>' 118 table_end = '</table>'
134 return '\n\t'.join([table_begin] + [header_row] + rows + [table_end]) 119 return '\n\t'.join([table_begin] + [header_row] + rows + [table_end])
135 120
136def ebuild_to_html(ebinfo, new=0, show_bugs=0): 121def ebuild_to_html(ebinfo, new=0, show_bugs=0, full = False):
137 """Convert ebuild (dict) to html, if new, print out a "this is new" notice 122 """Convert ebuild (dict) to html, if new, print out a "this is new" notice
138 if show_bugs, show bugs for this particular ebuild (requires access to 123 if show_bugs, show bugs for this particular ebuild (requires access to
139 bugzilla""" 124 bugzilla"""
140 if new: 125 if new:
141 new_string = """ &nbsp;&nbsp;<span class="new">new!</span> """ 126 new_string = """ &nbsp;&nbsp;<span class="new">new!</span> """
142 else: 127 else:
143 new_string = "" 128 new_string = ""
144 129
145 table_begin = '<table class="ebuild">' 130 table_begin = '<table class="ebuild">'
146 name_and_date = ('<tr><td class="fields">' 131 name_and_date = ('<tr><td class="fields">'
147 '<a href="%spackages/?category=%s;name=%s">%s</a> %s%s<br>' 132 '<a href="%spackages/?category=%s;name=%s">%s</a> %s%s<br>'
148 '<span class="time">%s</span>' 133 '<span class="time">%s</span>'
149 '</td></tr>' % (config.FEHOME, quote(ebinfo['category']), 134 '</td></tr>' % (config.FEHOME, quote(ebinfo['category']),
150 quote(ebinfo['name']), 135 quote(ebinfo['name']),
151 ebinfo['name'], 136 ebinfo['name'],
152 ebinfo['version'], 137 ebinfo['version'],
153 new_string, 138 new_string,
154 ebinfo['time'].localtime().strftime("%c %Z"))) 139 ebinfo['time'].strftime("%c %Z")))
140
141 if full:
142 image = ('<img class="pkgimg" alt="" src="%s/%s/%s.jpg" align="right">' %
143 (config.ICONS, ebinfo['category'], ebinfo['name'])
155 144 )
145 else:
146 image = ''
156 desc_and_changes = ('<tr><td class="item" valign="top">' 147 desc_and_changes = ('<tr><td class="item" valign="top">'
157 '<img alt="" align="right" src="%simages/%s.png">'
158 '<p><b>Description:</b> %s</p>' 148 '<p><b>Description:</b> %s %s</p>'
159 '<p><b>Changes:</b><br>' 149 '<p><b>Changes:</b><br>'
160 '%s</p></td></tr>' % ( 150 '%s</p></td></tr>' % (
161 config.FEHOME,
162 ebinfo['category'],
163 escape(ebinfo['description']), 151 escape(ebinfo['description']),
152 image,
164 changelog_to_html(ebinfo['changelog']))) 153 changelog_to_html(ebinfo['changelog'])))
165 154
166 archs = '<tr><td>%s</td></tr>' % archs_to_html([ebinfo]) 155 archs = '<tr><td>%s</td></tr>' % archs_to_html([ebinfo])
167 general = '<tr><td>%s</td></tr>' % general_info_to_html(ebinfo) 156 general = '<tr><td>%s</td></tr>' % general_info_to_html(ebinfo)
168 table_end = '</table>' 157 table_end = '</table>'
169 158
170 if 1 == 1:
171 bug_string = '' 159 bug_string = ''
172 else: 160 if show_bugs:
161 bug_string = bugs_to_html(ebinfo['name'])
162 if bug_string:
173 bug_string = '<br><h3>Related bugs:</h3>%s' \ 163 bug_string = '<br><h3 class="bugs">Related bugs:</h3>%s' \
174 % bugs_to_html(ebinfo['name']) 164 % bug_string
175 165
176 return '\n\t'.join([table_begin, 166 return '\n\t'.join([table_begin,
177 name_and_date, 167 name_and_date,
178 desc_and_changes, 168 desc_and_changes,
179 archs, 169 archs,
180 general, 170 general,
181 table_end, 171 table_end,
182 bug_string]) 172 bug_string])
183 173
184def general_info_to_html(pkg): 174def general_info_to_html(pkg):
185 """This actually will (should) take either a package or ebuild dict 175 """This actually will (should) take either a package or ebuild dict
186 as an argument""" 176 as an argument"""
187 177
178 import forums
179
188 changelogurl = ('http://www.gentoo.org/cgi-bin/viewcvs.cgi/*checkout*/' 180 changelogurl = ('http://sources.gentoo.org/viewcvs.py/*checkout*/'
189 '%s/%s/ChangeLog' % (pkg['category'],pkg['name'])) 181 'gentoo-x86/%s/%s/ChangeLog' % (pkg['category'],pkg['name']))
190 cat_header = '<th class="category">Category</th>' 182 cat_header = '<th class="category">Category</th>'
191 license_header = '<th class="license">License</th>' 183 license_header = '<th class="license">License</th>'
192 category = ('<td class="category">' 184 category = ('<td class="category">'
193 '<a href="%spackages/?category=%s">%s</a></td>' % (config.FEHOME, 185 '<a href="%spackages/?category=%s">%s</a></td>' % (config.FEHOME,
194 pkg['category'], pkg['category'])) 186 pkg['category'], pkg['category']))
195 homepage = ('<td class="homepage" rowspan="2">%s</td>' 187 homepage = ('<td class="homepage" rowspan="2">%s</td>'
196 % homepage_to_html(pkg['homepage'])) 188 % homepage_to_html(pkg['homepage']))
197 license = ('<td class="license">%s</td>' 189 license = ('<td class="license">%s</td>'
198 % license_to_html(pkg['license'])) 190 % license_to_html(pkg['license']))
199 changelog = ('<td class="changelog" rowspan="2">' 191 changelog = ('<td class="changelog" rowspan="2">'
200 '<a href="%s">ChangeLog</a><td>' % changelogurl) 192 '<a href="%s">ChangeLog</a></td>' % changelogurl)
201 193 similar = ('<td class="similar" rowspan="2">'
194 '%s</td>' % create_similar_pkgs_link(pkg))
195 related_bugs = ('<td class="related_bugs" rowspan="2">'
196 '%s</td>' % create_related_bugs_link(pkg))
197 forums = ('<td class="forums" rowspan="2">'
198 '%s</td>' % forums.create_forums_link(pkg))
199
202 return '\n\t'.join(['<table class="general_info">', 200 return '\n\t'.join(['<table class="general_info">',
203 '<tr>', 201 '<tr>',
204 cat_header, 202 cat_header,
205 homepage, 203 homepage,
206 license_header, 204 license_header,
207 changelog, 205 changelog,
206 similar,
207 related_bugs,
208 forums,
208 '</tr>', 209 '</tr>',
209 '<tr>', 210 '<tr>',
210 category, 211 category,
211 license, 212 license,
212 '</tr>', 213 '</tr>',
213 '</table>']) 214 '</table>'])
214 215
216def create_similar_pkgs_link(pkg):
217 """Create a link to similar packages"""
218
219 return '<a href="/similar/?package=%(category)s/%(name)s">Similar</a>' % pkg
220
221def create_related_bugs_link(pkg):
222 """Create a link to related bugs"""
223
224 url = ('http://bugs.gentoo.org/buglist.cgi?query_format='
225 '&amp;short_desc_type=allwords'
226 '&amp;short_desc=%s'
227 '&amp;bug_status=UNCONFIRMED'
228 '&amp;bug_status=NEW'
229 '&amp;bug_status=ASSIGNED'
230 '&amp;bug_status=REOPENED'
231 % escape(pkg['name']))
232
233 return '<a title="bugs.gentoo.org" href="%s">Bugs</a>' % url
234
215def bugs_to_html(package): 235def bugs_to_html(package):
216 """Given package name (no version #s), return html text of bugs as 236 """Given package name (no version #s), return html text of bugs as
217 reported by bugzilla""" 237 reported by bugzilla"""
218 # Right now we have an issue with the bugzilla site. New interface 238 # Right now we have an issue with the bugzilla site. New interface
219 # needs to be written, Bail out. 239 # needs to be written, Bail out.
220 return "" 240 #return ""
221 import urllib2 241 import urllib2
222 url = ('http://bugs.gentoo.org/buglist.cgi?query_format=' 242 url = ('http://bugs.gentoo.org/buglist.cgi?query_format='
223 '&short_desc_type=allwords&short_desc=%s' 243 '&amp;short_desc_type=allwords'
224 '&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED' 244 '&amp;short_desc=%s'
245 '&amp;bug_status=UNCONFIRMED'
246 '&amp;bug_status=NEW'
247 '&amp;bug_status=ASSIGNED'
225 '&bug_status=REOPENED' 248 '&amp;bug_status=REOPENED'
249 '&amp;ctype=csv'
226 '&ctype=csv' % package) 250 % package)
227 fp = urllib2.urlopen(url) 251 fp = urllib2.urlopen(url)
228 factory = bugs.BugFactory() 252 factory = bugs.BugFactory()
229 package_bugs = factory.fromCSV(fp) 253 package_bugs = factory.fromCSV(fp)
230 if package_bugs: 254 if package_bugs:
231 writer = bugs.HTMLWriter(package_bugs, 'bugs.gentoo.org') 255 writer = bugs.HTMLWriter(package_bugs, 'bugs.gentoo.org')
232 return str(writer) 256 return str(writer)
233 else: 257 else:
234 return "None" 258 return ""
235 259
236def get_most_recent(db, max=config.MAXPERPAGE, arch="", branch=""): 260def get_most_recent(db, max=config.MAXPERPAGE, arch="", branch="", new = False):
237 c = db.cursor() 261 c = db.cursor()
238 extra = '' 262 extra = ''
239 if arch: 263 if arch:
240 stable_extra = ('ebuild.arch REGEXP "^%s| %s" ' 264 stable_extra = ('FIND_IN_SET("%s", ebuild.arch) > 0 AND '
241 ' AND ebuild.prevarch NOT REGEXP"^%s| %s"' 265 'FIND_IN_SET("%s", ebuild.prevarch) = 0 ' % (arch, arch))
242 % (arch,arch,arch,arch)) 266 testing_extra = ('FIND_IN_SET("~%s", ebuild.arch) > 0 AND '
243 testing_extra = ('ebuild.arch REGEXP "^~%s| ~%s" ' 267 'FIND_IN_SET("~%s", ebuild.prevarch) = 0 ' % (arch, arch))
244 ' AND ebuild.prevarch NOT REGEXP "^~%s| ~%s"'
245 % (arch,arch,arch,arch))
246 if branch == 'stable': 268 if branch == 'stable':
247 extra = ' AND (%s) ' % stable_extra 269 extra = ' AND (%s) ' % stable_extra
248 elif branch == 'testing': 270 elif branch == 'testing':
249 extra = ' AND (%s) ' % testing_extra 271 extra = ' AND (%s) ' % testing_extra
250 else: 272 else:
251 extra = ' AND ((%s) OR (%s)) ' % (stable_extra, testing_extra) 273 extra = ' AND ((%s) OR (%s)) ' % (stable_extra, testing_extra)
274
275 if new:
276 extra = ('%s AND package.new=1 ' % extra)
277
252 query = """SELECT ebuild.category,ebuild.name,version,when_found,description, 278 query = """SELECT ebuild.category,ebuild.name,version,ebuild.when_found,description,
253 changelog,arch,homepage,license FROM ebuild,package WHERE ebuild.name=\ 279 changelog,arch,homepage,license,is_masked FROM ebuild,package WHERE ebuild.name=\
254 package.name AND ebuild.category=package.category %s ORDER by when_found DESC \ 280 package.name AND ebuild.category=package.category %s ORDER by ebuild.when_found DESC \
255 LIMIT %s""" % (extra,max) 281 LIMIT %s""" % (extra,max)
256 c.execute(query) 282 c.execute(query)
257 results = c.fetchall() 283 results = c.fetchall()
258 return results 284 return results
259 285
286def get_most_recent_bumps(db, max=config.MAXPERPAGE):
287 """Return most recent version bumps (pkgs with no prevarch)"""
288 c = db.cursor()
289 query = ('SELECT ebuild.category, ebuild.name, version, when_found, '
290 'description, changelog, arch, homepage, license,is_masked FROM ebuild, package '
291 'WHERE ebuild.name=package.name AND ebuild.category=package.category '
292 'AND prevarch="" AND version NOT LIKE "%%-r_" AND version NOT LIKE '
293 '"%%-r__" AND NOT new ORDER by when_found '
294 'DESC LIMIT %s' % max)
295
296 c.execute(query)
297 results = c.fetchall()
298 return results
299
260def query_to_dict(d): 300def query_to_dict(d):
261 """Convert a SQL query to a dict""" 301 """Convert a SQL query to a dict"""
262 einfo = {} 302 einfo = {}
263 keys = ('category', 'name', 'version', 'time', 'description', 'changelog', 303 keys = ('category', 'name', 'version', 'time', 'description', 'changelog',
264 'arch', 'homepage', 'license') 304 'arch', 'homepage', 'license', 'masked')
265 for i in range(len(keys)): 305 for i in range(len(keys)):
266 try: 306 try:
267 einfo[keys[i]] = d[i] 307 einfo[keys[i]] = d[i]
268 except IndexError: 308 except IndexError:
269 continue 309 continue
272def get_recent_releases(pkg, db, max=config.MAX_RECENT_RELEASES): 312def get_recent_releases(pkg, db, max=config.MAX_RECENT_RELEASES):
273 """Return MAX_RECENT_RELEASES most recent releases for pkg. Returns and 313 """Return MAX_RECENT_RELEASES most recent releases for pkg. Returns and
274 ebuild-type dict""" 314 ebuild-type dict"""
275 c = db.cursor() 315 c = db.cursor()
276 query = ('SELECT category,name,version,when_found,NULL,changelog,arch ,' 316 query = ('SELECT category,name,version,when_found,NULL,changelog,arch ,'
277 'NULL,NULL FROM ebuild WHERE name="%s" AND category="%s" ORDER BY ' 317 'NULL,NULL,is_masked FROM ebuild WHERE name="%s" AND category="%s" ORDER BY '
278 'version DESC LIMIT %s' % (pkg['name'],pkg['category'],max)) 318 'version DESC LIMIT %s' % (pkg['name'],pkg['category'],max))
279 c.execute(query) 319 c.execute(query)
280 results = c.fetchall() 320 results = c.fetchall()
281 #print results 321 #print results
282 return [ query_to_dict(i) for i in results ] 322 return [ query_to_dict(i) for i in results ]
283 323
324def cmp_ebuilds(a, b):
325 """Compare two ebuilds"""
326 fields_a = pkgsplit('%s-%s' % (a['name'], a['version']))
327 fields_b = pkgsplit('%s-%s' % (b['name'], b['version']))
328 return pkgcmp(fields_a, fields_b)
329
284def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""): 330def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""):
285 """write out ebuild info to RSS file (fp)""" 331 """write out ebuild info to RSS file (fp)"""
332
333 # web link for RSS feed
334 if subtitle:
335 link = '%s/%s' % (config.FEHOME, subtitle.replace(' ','/',1))
336 else:
337 link = config.FEHOME
338
339 pubDate = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
286 fp.write("""<?xml version="1.0" encoding="iso-8859-1"?> 340 fp.write("""<?xml version="1.0" encoding="UTF-8"?>
287 <rss version="0.92"> 341 <rss version="2.0">
288 <channel> 342 <channel>
289 <title>Fresh ebuilds %s</title> 343 <title>packages.gentoo.org [ %s ]</title>
290 <link>%s</link> 344 <link>%s</link>
291 <description>Latest ebuilds from the Gentoo Linux portage tree</description> 345 <description>Latest ebuilds from the Gentoo Linux portage tree</description>
292 <![CDATA[<link rel="stylesheet" href="%s" type="text/css" title="styled" />]]>
293 <webMaster>www@gentoo.org</webMaster> 346 <webMaster>www@gentoo.org</webMaster>
347
348 <image>
349 <title>Online Package Database</title>
350 <url>%s</url>
351 <link>%s</link>
352 </image>
353
294 <managingEditor>marduk@gentoo.org</managingEditor> 354 <managingEditor>marduk@gentoo.org</managingEditor>
295 <pubDate>%s</pubDate>""" % (subtitle,config.FEHOME, config.STYLESHEET, 355 <pubDate>%s</pubDate>""" % (subtitle, link, config.RSS_IMAGE,
296 time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))) 356 config.FEHOME, pubDate))
297 357
298 for ebuild in ebuilds: 358 for ebuild in ebuilds:
299 if simple: 359 if simple:
300 description = escape(ebuild['description']) 360 description = escape(ebuild['description'])
301 else: 361 else:
302 description = '\n<![CDATA[\n%s\n]]>' % ebuild_to_html(ebuild) 362 description = ('\n'
363 '<![CDATA[\n'
364 '<link rel="stylesheet" type="text/css" href="%s"></link>\n'
365 '%s\n]]>' % (config.STYLESHEET, ebuild_to_html(ebuild, full=True))
366 )
303 367
304 fp.write("""<item> 368 fp.write("""<item>
305 <title>%s %s</title> 369 <title>%s/%s %s</title>
306 <link>%sebuilds/?%s-%s</link> 370 <link>%sebuilds/?%s-%s</link>
307 <description> 371 <description>
308 %s 372 %s
309 </description> 373 </description>
310 <pubDate>%s</pubDate> 374 <pubDate>%s</pubDate>
311 </item> 375 </item>
312 """ % (ebuild['name'], 376 """ % (ebuild['category'],
377 ebuild['name'],
313 ebuild['version'], 378 ebuild['version'],
314 config.FEHOME, 379 config.FEHOME,
315 ebuild['name'], 380 ebuild['name'],
316 ebuild['version'], 381 ebuild['version'],
317 description, 382 description,
318 ebuild['time'].gmtime().strftime("%a, %d %b %Y %H:%M:%S +0000")) 383 ebuild['time'].strftime("%a, %d %b %Y %H:%M:%S +0000"))
319 ) 384 )
320 385
321 fp.write("</channel>\n</rss>\n") 386 fp.write("\n\
322 387 <textInput>\n\
323if __name__ == '__main__': 388 <title>Search the Online Package Database</title>\n\
389 <link>%s/search/</link>\n\
390 <description>emerge -Ss</description>\n\
391 <name>sstring</name>\n\
392 </textInput>\n\
393 </channel>\n\
394 </rss>\n" % config.FEHOME)
395
396def main(argv=None):
397 if argv is None:
398 argv = sys.argv
324 try: 399 try:
325 if sys.argv[1] == '-g': 400 if argv[1] == '-g':
326 ebuilddb.main() 401 ebuilddb.main()
327 except IndexError: 402 except IndexError:
328 pass 403 pass
329 404
330 db = ebuilddb.db_connect() 405 db = ebuilddb.db_connect()
331 branches = ('', 'stable', 'testing') 406 branches = ('', 'stable', 'testing')
332 for arch in [''] + config.ARCHLIST: 407 for arch in [''] + config.ARCHLIST:
333 for branch in branches: 408 for branch in branches:
334 fullpath = os.path.join(config.LOCALHOME, "archs", arch, branch, 409 fullpath = os.path.join(config.LOCALHOME, "archs", arch, branch,
335 config.INDEX) 410 config.INDEX)
336 index = open(fullpath,'w') 411 index = open(fullpath,'w')
337 if arch: 412
338 sarch = arch
339 else:
340 sarch = 'all'
341 if branch:
342 sbranch = branch
343 else:
344 sbranch = 'all'
345
346 index.write("""<table border="0" cellpadding="0" cellspacing="5" 413 index.write("""<table border="0" cellpadding="0" cellspacing="5"
347 width="100%">\n""") 414 width="100%">\n""")
348 index.write("""<tr><td valign="top">\n""") 415 index.write("""<tr><td valign="top">\n""")
349 index.write('<!--#include file="archnav.html" -->\n\n</td></tr>\n' 416 index.write('<!--#include file="archnav.html" -->\n\n</td></tr>\n'
350 '<tr><td>') 417 '<tr><td>')
351 results = get_most_recent(db, arch=arch, branch=branch) 418 results = get_most_recent(db, arch=arch, branch=branch)
352 ebuilds = [ query_to_dict(i) for i in results ] 419 ebuilds = [ query_to_dict(i) for i in results ]
353 for ebuild in ebuilds: 420 for ebuild in ebuilds:
354 new = is_new(db, ebuild) 421 new = is_new(db, ebuild)
355 pkgfilename = "%s/%s-%s.html" % ( 422 pkgfilename = "%s/%s-%s.html" % (
356 config.EBUILD_FILES,ebuild['name'],ebuild['version']) 423 config.EBUILD_FILES,ebuild['name'],ebuild['version'])
357 ebuild_html = ebuild_to_html(ebuild, new) 424 ebuild_html = ebuild_to_html(ebuild, new, show_bugs = False)
358 if arch == '' and branch == '': 425 if arch == '' and branch == '':
359 pkgfile = open(pkgfilename,'w') 426 pkgfile = open(pkgfilename,'w')
360 pkgfile.write(ebuild_html) 427 pkgfile.write(ebuild_html)
361 pkgfile.close() 428 pkgfile.close()
362 ebuildfilename = "%s/%s/%s/%s-%s.ebuild" \ 429 ebuildfilename = "%s/%s/%s/%s-%s.ebuild" \
363 % (ebuilddb.config.PORTAGE_DIR, 430 % (ebuilddb.config.PORTAGE_DIR,
364 ebuild['category'],ebuild['name'],ebuild['name'], 431 ebuild['category'],ebuild['name'],ebuild['name'],
365 ebuild['version']) 432 ebuild['version'])
366 os.system('touch -r %s %s || touch -d "today -1 year" %s' 433 os.system('touch -r %s %s || touch -d "today -1 year" %s'
367 % (ebuildfilename,pkgfilename,pkgfilename)) 434 % (ebuildfilename,pkgfilename,pkgfilename))
368 435
369 try: 436 try:
370 index.write('%s\n\n' % (ebuild_html)) 437 index.write('%s\n\n' % (ebuild_html))
371 except IOError: 438 except IOError:
372 continue 439 continue
373 index.write("""</table>\n""") 440 index.write("""</table>\n""")
374 index.close() 441 index.close()
375 442
376 subtitle = ' %s %s' % (arch, branch) 443 subtitle = ' %s %s' % (arch, branch)
377 rss = open(os.path.join(config.LOCALHOME, "archs", arch, branch, 444 rss = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
378 config.RSS), 'w') 445 config.RSS), 'w')
379 ebuilds_to_rss(rss, ebuilds, simple=False, subtitle=subtitle) 446 ebuilds_to_rss(rss, ebuilds, simple=False, subtitle=subtitle)
380 rss.close() 447 rss.close()
381 448
382 rss2 = open(os.path.join(config.LOCALHOME, "archs", arch, branch, 449 rss2 = open(os.path.join(config.LOCALHOME, "archs", arch, branch,
383 config.RSS2), 'w') 450 config.RSS2), 'w')
384 ebuilds_to_rss(rss2, ebuilds, simple=True, subtitle=subtitle) 451 ebuilds_to_rss(rss2, ebuilds, simple=True, subtitle=subtitle)
385 rss.close() 452 rss.close()
453
454if __name__ == '__main__':
455 sys.exit(main())

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.16.2.3

  ViewVC Help
Powered by ViewVC 1.1.20