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

Contents of /src/packages/query_package.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (as text) (vendor branch)
Thu Feb 19 01:49:53 2004 UTC (10 years, 7 months ago) by marduk
Branch: packages_g_o
CVS Tags: ver_0-1
Changes since 1.1: +0 -0 lines
File MIME type: text/x-python

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=UTF-8\n\n')
13
14 def query_to_dict(q):
15 pkginfo = {}
16 keys = ('category','name','homepage','description','license')
17 for i in range(len(keys)):
18 try:
19 pkginfo[keys[i]] = q[i]
20 except IndexError:
21 continue
22 return pkginfo
23
24
25 form = cgi.FieldStorage()
26 name = form.getvalue("name","")
27 category = form.getvalue("category","")
28 offset = form.getvalue("offset","0")
29
30 query = ('SELECT category,name,homepage,description,license '
31 'FROM package WHERE category="%s"' % escape_string(category))
32
33 if name:
34 query = ('%s AND name="%s"' %(query,escape_string(name)))
35
36 query = ('%s LIMIT %s,%s' % (query,offset,config.MAX_CATEGORIES))
37
38 db = ebuilddb.db_connect()
39 c = db.cursor()
40 c.execute(query)
41 results = c.fetchall()
42
43 #print query
44 if results:
45 if name:
46 for result in results:
47 #print result
48 pkg = query_to_dict(result)
49 sys.stdout.write('%s<br>\n<br>\n'
50 % gentoo.package_to_html(pkg,db))
51 else:
52 sys.stdout.write('<table class="centerpage">\n')
53 sys.stdout.write('<tr><td class="fields">'
54 '%s</td><td align="center"><img alt="" src="'
55 '%s/%s.png"></td></tr>\n'
56 % (category,config.ICONS,category))
57 for result in results:
58 pkg = query_to_dict(result)
59 sys.stdout.write('<tr><td width="25%%" class="fields">'
60 '<a href="?category=%s;name=%s">%s</a></td>'
61 '<td class="description">%s</td></tr>\n'
62 % (pkg['category'],quote(pkg['name']),pkg['name'],
63 cgi.escape(pkg['description'])))
64 sys.stdout.write('</table>\n')
65 if offset !="0":
66 sys.stdout.write('<a href="?category=%s;name=%s'
67 ';offset=%s">[Previous]</a> '
68 % (category,name,int(offset) - config.MAX_CATEGORIES))
69 if len(results) == config.MAX_CATEGORIES:
70 sys.stdout.write('<a href="?category=%s;name=%s;offset=%s">[Next]</a> '
71 % (category,name,int(offset) + config.MAX_CATEGORIES))
72
73 else:
74 sys.stdout.write('<div class="centerpage">\n'
75 '<table width="100%%" border="0" align="center"'
76 ' cellspacing="0"><tr><td colspan="3" class="fields">'
77 'Sorry, dude. I could not find that package.<br></td></tr>\n'
78 '<tr><td class="item" colspan="3">'
79 '<img '
80 'src="%s?category=404"'
81 'align="right" alt=""> <p>Information on the package you requested'
82 ' could not be found. Be sure to check the'
83 ' <a HREF="%s">'
84 'fresh ebuilds main page</a>.</p></td></tr></table>\n'
85 '</div>' % (config.ICONS,config.FEHOME))

  ViewVC Help
Powered by ViewVC 1.1.20