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

Diff of /src/packages/query_package.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.20