/[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.6 Revision 1.7
1#!/usr/bin/python -OO 1#!/usr/bin/python -OO
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.6 $" 5__revision__ = "$Revision: 1.7 $"
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
94 ebuilds = get_recent_releases(pkginfo, db) 95 ebuilds = get_recent_releases(pkginfo, db)
95 releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases') 96 releases = '<tr><td>%s</td></tr>' % archs_to_html(ebuilds, 'Releases')
96 #bug_string = ('<br><h3>Related bugs:</h3>\n%s' 97 #bug_string = ('<br><h3>Related bugs:</h3>\n%s'
97 # % bugs_to_html(pkginfo['name'])) 98 # % bugs_to_html(pkginfo['name']))
98 general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo) 99 general = '<tr><td>%s</td></tr>' % general_info_to_html(pkginfo)
100 similar = '<tr><td>%s</td></tr>' % create_similar_pkgs_link(pkginfo)
99 table_end = '</table>' 101 table_end = '</table>'
100 rows = '\n\t'.join([name, description, releases, general]) 102 rows = '\n\t'.join([name, description, releases, general])
101 return '\n\t'.join([table_begin, rows, table_end]) 103 return '\n\t'.join([table_begin, rows, table_end])
102 104
103def archs_to_html(ebuilds, heading = None): 105def archs_to_html(ebuilds, heading = None):
104 """Create table for availability on each architecture""" 106 """Create table for availability on each architecture"""
105 heading = heading or '&nbsp;' 107 heading = heading or '&nbsp;'
106 table_begin = '<table class="releases">' 108 table_begin = '<table class="releases">'
107 header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] + 109 header_row = ''.join(['<tr><td><b>%s</b></td>' % heading] +
108 ['<th class="arch">%s</th>' % i for i in config.ARCHLIST] + 110 ['<th class="arch">%s</th>' % i.replace('-',' ') for i in config.ARCHLIST] +
109 ['</tr>'] 111 ['</tr>']
110 ) 112 )
111 rows = [] 113 rows = []
114 ebuilds.sort(cmp_ebuilds)
115 ebuilds.reverse()
112 for ebuild in ebuilds: 116 for ebuild in ebuilds:
113 masked = is_masked(ebuild) 117 masked = is_masked(ebuild)
114 archs = ebuild['arch'].split() 118 archs = ebuild['arch'].split()
115 row_start = ('<tr>\n\t<th class="releases"><a href="%sebuilds/?%s-%s"' 119 row_start = ('<tr>\n\t<th class="releases"><a href="%sebuilds/?%s-%s"'
116 ' title="%s">%s</a></th>\n' % (config.FEHOME, 120 ' title="%s">%s</a></th>\n' % (config.FEHOME,
195 homepage = ('<td class="homepage" rowspan="2">%s</td>' 199 homepage = ('<td class="homepage" rowspan="2">%s</td>'
196 % homepage_to_html(pkg['homepage'])) 200 % homepage_to_html(pkg['homepage']))
197 license = ('<td class="license">%s</td>' 201 license = ('<td class="license">%s</td>'
198 % license_to_html(pkg['license'])) 202 % license_to_html(pkg['license']))
199 changelog = ('<td class="changelog" rowspan="2">' 203 changelog = ('<td class="changelog" rowspan="2">'
200 '<a href="%s">ChangeLog</a><td>' % changelogurl) 204 '<a href="%s">ChangeLog</a></td>' % changelogurl)
205 similar = ('<td class="similar" rowspan="2">'
206 '%s</td>' % create_similar_pkgs_link(pkg))
201 207
202 return '\n\t'.join(['<table class="general_info">', 208 return '\n\t'.join(['<table class="general_info">',
203 '<tr>', 209 '<tr>',
204 cat_header, 210 cat_header,
205 homepage, 211 homepage,
206 license_header, 212 license_header,
207 changelog, 213 changelog,
214 similar,
208 '</tr>', 215 '</tr>',
209 '<tr>', 216 '<tr>',
210 category, 217 category,
211 license, 218 license,
212 '</tr>', 219 '</tr>',
213 '</table>']) 220 '</table>'])
214 221
222def create_similar_pkgs_link(pkg):
223 """Create a link to similar packages"""
224
225 def strip_chars(mystring):
226 newstring = ''
227 for char in mystring:
228 if char not in string.punctuation:
229 newstring = newstring + char
230 else:
231 newstring = newstring + ' '
232 return newstring
233
234 description = strip_chars(pkg['description'].lower())
235
236 words = [word for word in description.split()
237 if word and len(word)>2 and word not in config.EXCLUDED_FROM_SIMILAR]
238 words = words[:config.SIMILAR_MAX_WORDS] + [pkg['name']]
239 #query = ['[[:<:]]%s[[:>:]].*' % word for word in words]
240 query = ['[[:<:]]%s.*' % word for word in words]
241 query = '(%s){%s,}' % ('|'.join(query), config.SIMILAR_MIN_MATCHES)
242 url = '%ssearch/?sstring=%s' % (config.FEHOME, escape(query))
243 return '<a href="%s">Similar Packages</a>' % url
244
215def bugs_to_html(package): 245def bugs_to_html(package):
216 """Given package name (no version #s), return html text of bugs as 246 """Given package name (no version #s), return html text of bugs as
217 reported by bugzilla""" 247 reported by bugzilla"""
218 # Right now we have an issue with the bugzilla site. New interface 248 # Right now we have an issue with the bugzilla site. New interface
219 # needs to be written, Bail out. 249 # needs to be written, Bail out.
278 'version DESC LIMIT %s' % (pkg['name'],pkg['category'],max)) 308 'version DESC LIMIT %s' % (pkg['name'],pkg['category'],max))
279 c.execute(query) 309 c.execute(query)
280 results = c.fetchall() 310 results = c.fetchall()
281 #print results 311 #print results
282 return [ query_to_dict(i) for i in results ] 312 return [ query_to_dict(i) for i in results ]
283 313
314def cmp_ebuilds(a, b):
315 """Compare two ebuilds"""
316 fields_a = portage.pkgsplit('%s-%s' % (a['name'], a['version']))
317 fields_b = portage.pkgsplit('%s-%s' % (b['name'], b['version']))
318 return portage.pkgcmp(fields_a, fields_b)
319
284def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""): 320def ebuilds_to_rss(fp, ebuilds, simple=False, subtitle=""):
285 """write out ebuild info to RSS file (fp)""" 321 """write out ebuild info to RSS file (fp)"""
286 fp.write("""<?xml version="1.0" encoding="iso-8859-1"?> 322 fp.write("""<?xml version="1.0" encoding="iso-8859-1"?>
287 <rss version="0.92"> 323 <rss version="0.92">
288 <channel> 324 <channel>
289 <title>Fresh ebuilds %s</title> 325 <title>packages.gentoo.org [ %s ]</title>
290 <link>%s</link> 326 <link>%s</link>
291 <description>Latest ebuilds from the Gentoo Linux portage tree</description> 327 <description>Latest ebuilds from the Gentoo Linux portage tree</description>
292 <![CDATA[<link rel="stylesheet" href="%s" type="text/css" title="styled" />]]> 328 <![CDATA[<link rel="stylesheet" href="%s" type="text/css" title="styled" />]]>
293 <webMaster>www@gentoo.org</webMaster> 329 <webMaster>www@gentoo.org</webMaster>
294 <managingEditor>marduk@gentoo.org</managingEditor> 330 <managingEditor>marduk@gentoo.org</managingEditor>

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.20