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

Contents of /src/packages/query_package.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download) (as text)
Sat Jun 19 15:44:52 2004 UTC (10 years, 4 months ago) by marduk
Branch: MAIN
Changes since 1.2: +1 -1 lines
File MIME type: text/x-python
Changed charset from utf-8 to iso-8859-1. This fixes #53912

1 marduk 1.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 marduk 1.3 sys.stdout.write('Content-type: text/html; charset=iso-8859-1\n\n')
13 marduk 1.1
14     def query_to_dict(q):
15 marduk 1.2 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 marduk 1.1
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 marduk 1.2 'FROM package WHERE category="%s"' % escape_string(category))
32    
33 marduk 1.1 if name:
34 marduk 1.2 query = ('%s AND name="%s"' %(query,escape_string(name)))
35 marduk 1.1
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 marduk 1.2 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><th class="category">'
54     '%s</th></tr>\n<tr><td>' % category)
55     for result in results:
56     pkg = query_to_dict(result)
57     sys.stdout.write(gentoo.package_to_html(pkg, db))
58     sys.stdout.write('</td></tr></table>\n')
59     if offset !="0":
60     sys.stdout.write('<a href="?category=%s;name=%s'
61     ';offset=%s">[Previous]</a> '
62     % (category,name,int(offset) - config.MAX_CATEGORIES))
63     if len(results) == config.MAX_CATEGORIES:
64     sys.stdout.write('<a href="?category=%s;name=%s;offset=%s">[Next]</a> '
65     % (category,name,int(offset) + config.MAX_CATEGORIES))
66 marduk 1.1
67     else:
68 marduk 1.2 sys.stdout.write('<div class="centerpage">\n'
69     '<table width="100%%" border="0" align="center"'
70     ' cellspacing="0"><tr><td colspan="3" class="fields">'
71     'Sorry, dude. I could not find that package.<br></td></tr>\n'
72     '<tr><td class="item" colspan="3">'
73     '<img '
74     'src="%s?category=404"'
75     'align="right" alt=""> <p>Information on the package you requested'
76     ' could not be found. Be sure to check the'
77     ' <a HREF="%s">'
78     'fresh ebuilds main page</a>.</p></td></tr></table>\n'
79     '</div>' % (config.ICONS,config.FEHOME))

  ViewVC Help
Powered by ViewVC 1.1.20