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

Contents of /src/packages/query_package.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download) (as text)
Tue Oct 4 01:51:29 2005 UTC (8 years, 6 months ago) by marduk
Branch: MAIN
CVS Tags: release_1-5, v1_3_1, HEAD
Branch point for: v1_3
Changes since 1.4: +9 -5 lines
File MIME type: text/x-python
* fixed code that determines how many pages are in search results

1 #!/usr/bin/python -O
2
3 import cgi
4 from urllib import quote
5 import os
6 import sys
7 import config
8 import gentoo
9 import ebuilddb
10 from MySQLdb import escape_string
11
12 sys.stdout.write('Content-type: text/html; charset=iso-8859-1\n\n')
13
14 def cmp_results(a, b):
15 """Compare results a and b"""
16 category_a = a[0]
17 category_b = b[0]
18
19 order = cmp(category_a, category_b)
20 if order != 0:
21 return order
22
23
24 def query_to_dict(q):
25 pkginfo = {}
26 keys = ('category','name','homepage','description','license')
27 for i in range(len(keys)):
28 try:
29 pkginfo[keys[i]] = q[i]
30 except IndexError:
31 continue
32 return pkginfo
33
34
35 form = cgi.FieldStorage()
36 name = form.getvalue("name","")
37 category = form.getvalue("category","")
38 offset = form.getvalue("offset","0")
39
40 query = ('SELECT category,name,homepage,description,license '
41 'FROM package WHERE category="%s"' % escape_string(category))
42
43 if name:
44 query = ('%s AND name="%s"' %(query,escape_string(name)))
45
46 # first get row count
47 db = ebuilddb.db_connect()
48 c = db.cursor()
49 c.execute(query)
50 total_rows = c.rowcount
51
52 query = ('%s LIMIT %s,%s' % (query,offset,config.MAX_CATEGORIES))
53
54 c.execute(query)
55 results = c.fetchall()
56
57 #print query
58 if results:
59 if name:
60 for result in results:
61 #print result
62 pkg = query_to_dict(result)
63 sys.stdout.write('%s<br>\n<br>\n'
64 % gentoo.package_to_html(pkg,db, full=True))
65 else:
66 sys.stdout.write('<table class="centerpage">\n')
67 sys.stdout.write('<tr><th class="category">'
68 '%s</th></tr>\n<tr><td>' % category)
69 for result in results:
70 pkg = query_to_dict(result)
71 sys.stdout.write(gentoo.package_to_html(pkg, db))
72 sys.stdout.write('</td></tr></table>\n')
73 if offset !="0":
74 sys.stdout.write('<a href="?category=%s;name=%s'
75 ';offset=%s">[Previous]</a> '
76 % (category,name,int(offset) - config.MAX_CATEGORIES))
77 if int(offset) + len(results) < total_rows:
78 sys.stdout.write('<a href="?category=%s;name=%s;offset=%s">[Next]</a> '
79 % (category,name,int(offset) + config.MAX_CATEGORIES))
80
81 else:
82 sys.stdout.write('<div class="centerpage">\n'
83 '<table width="100%%" border="0" align="center"'
84 ' cellspacing="0"><tr><td colspan="3" class="fields">'
85 'Sorry, dude. I could not find that package.<br></td></tr>\n'
86 '<tr><td class="item" colspan="3">'
87 '<img '
88 'src="%s?category=404"'
89 'align="right" alt=""> <p>Information on the package you requested'
90 ' could not be found. Be sure to check the'
91 ' <a HREF="%s">'
92 'packages.gentoo.org main page</a>.</p></td></tr></table>\n'
93 '</div>' % (config.ICONS,config.FEHOME))

  ViewVC Help
Powered by ViewVC 1.1.20