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

Contents of /src/packages/query_package.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download) (as text)
Sun Oct 17 16:53:21 2004 UTC (10 years, 2 months ago) by marduk
Branch: MAIN
Branch point for: pre_2-0
Changes since 1.3: +11 -1 lines
File MIME type: text/x-python
Various fixes & enhancements

1 #!/usr/bin/python -OO
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 query = ('%s LIMIT %s,%s' % (query,offset,config.MAX_CATEGORIES))
47
48 db = ebuilddb.db_connect()
49 c = db.cursor()
50 c.execute(query)
51 results = c.fetchall()
52
53 #print query
54 if results:
55 if name:
56 for result in results:
57 #print result
58 pkg = query_to_dict(result)
59 sys.stdout.write('%s<br>\n<br>\n'
60 % gentoo.package_to_html(pkg,db))
61 else:
62 sys.stdout.write('<table class="centerpage">\n')
63 sys.stdout.write('<tr><th class="category">'
64 '%s</th></tr>\n<tr><td>' % category)
65 for result in results:
66 pkg = query_to_dict(result)
67 sys.stdout.write(gentoo.package_to_html(pkg, db))
68 sys.stdout.write('</td></tr></table>\n')
69 if offset !="0":
70 sys.stdout.write('<a href="?category=%s;name=%s'
71 ';offset=%s">[Previous]</a> '
72 % (category,name,int(offset) - config.MAX_CATEGORIES))
73 if len(results) == config.MAX_CATEGORIES:
74 sys.stdout.write('<a href="?category=%s;name=%s;offset=%s">[Next]</a> '
75 % (category,name,int(offset) + config.MAX_CATEGORIES))
76
77 else:
78 sys.stdout.write('<div class="centerpage">\n'
79 '<table width="100%%" border="0" align="center"'
80 ' cellspacing="0"><tr><td colspan="3" class="fields">'
81 'Sorry, dude. I could not find that package.<br></td></tr>\n'
82 '<tr><td class="item" colspan="3">'
83 '<img '
84 'src="%s?category=404"'
85 'align="right" alt=""> <p>Information on the package you requested'
86 ' could not be found. Be sure to check the'
87 ' <a HREF="%s">'
88 'packages.gentoo.org main page</a>.</p></td></tr></table>\n'
89 '</div>' % (config.ICONS,config.FEHOME))

  ViewVC Help
Powered by ViewVC 1.1.20