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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.20