1 | #!/usr/bin/python -O |
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.16 $" |
5 | __revision__ = "$Revision: 1.16.2.1 $" |
6 | # $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $ |
6 | # $Source: /var/cvsroot/gentoo/src/packages/gentoo.py,v $ |
7 | |
7 | |
8 | import config |
8 | import config |
9 | import os |
9 | import os |
10 | import time |
10 | import time |
… | |
… | |
220 | '</table>']) |
220 | '</table>']) |
221 | |
221 | |
222 | def create_similar_pkgs_link(pkg): |
222 | def create_similar_pkgs_link(pkg): |
223 | """Create a link to similar packages""" |
223 | """Create a link to similar packages""" |
224 | |
224 | |
225 | def strip_chars(mystring): |
225 | return '<a href="/similar/?package=%(category)s/%(name)s">Similar</a>' % pkg |
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</a>' % url |
|
|
244 | |
226 | |
245 | def create_related_bugs_link(pkg): |
227 | def create_related_bugs_link(pkg): |
246 | """Create a link to related bugs""" |
228 | """Create a link to related bugs""" |
247 | |
229 | |
248 | url = ('http://bugs.gentoo.org/buglist.cgi?query_format=' |
230 | url = ('http://bugs.gentoo.org/buglist.cgi?query_format=' |
… | |
… | |
297 | extra = ' AND ((%s) OR (%s)) ' % (stable_extra, testing_extra) |
279 | extra = ' AND ((%s) OR (%s)) ' % (stable_extra, testing_extra) |
298 | |
280 | |
299 | if new: |
281 | if new: |
300 | extra = ('%s AND package.new=1 ' % extra) |
282 | extra = ('%s AND package.new=1 ' % extra) |
301 | |
283 | |
302 | query = """SELECT ebuild.category,ebuild.name,version,when_found,description, |
284 | query = """SELECT ebuild.category,ebuild.name,version,ebuild.when_found,description, |
303 | changelog,arch,homepage,license,is_masked FROM ebuild,package WHERE ebuild.name=\ |
285 | changelog,arch,homepage,license,is_masked FROM ebuild,package WHERE ebuild.name=\ |
304 | package.name AND ebuild.category=package.category %s ORDER by when_found DESC \ |
286 | package.name AND ebuild.category=package.category %s ORDER by ebuild.when_found DESC \ |
305 | LIMIT %s""" % (extra,max) |
287 | LIMIT %s""" % (extra,max) |
306 | c.execute(query) |
288 | c.execute(query) |
307 | results = c.fetchall() |
289 | results = c.fetchall() |
308 | return results |
290 | return results |
309 | |
291 | |