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

Contents of /src/packages/search.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (download) (as text) (vendor branch)
Thu Feb 19 01:49:53 2004 UTC (14 years, 8 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 marduk 1.1 #!/usr/bin/python -OO
2    
3     import sys
4     import config
5     import cgi
6     import ebuilddb
7     import gentoo
8     import os
9     from MySQLdb import escape_string
10    
11     form = cgi.FieldStorage()
12     type = form.getvalue("type","")
13     sstring = form.getvalue("sstring","")
14     offset = form.getvalue("offset","0")
15    
16     if not sstring:
17     sys.exit(0)
18    
19     if type == 'desc':
20     col = "description"
21     else:
22     col = "name"
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     def write_to_cache(s):
35     open(cachefile,'w').write(s)
36    
37     # if it's in the cache, just write that out
38     qs = sys.argv[1]
39     cachefile = os.path.join(config.LOCALHOME,'search/cache',qs)
40     if os.path.exists(cachefile):
41     #sys.stdout.write('<div class="centerpage">using cached results</div>\n')
42     sys.stdout.write(open(cachefile,'r').read())
43     sys.exit(0)
44    
45     escaped = escape_string(sstring)
46     query = ('SELECT category,name,homepage,description,license '
47     'FROM package WHERE name REGEXP "%s" or description REGEXP "%s" '
48     'LIMIT %s,%s'
49     % (escaped,escaped,offset,config.MAXPERPAGE))
50    
51     db = ebuilddb.db_connect()
52     c = db.cursor()
53     try:
54     c.execute(query)
55     results = c.fetchall()
56     except:
57     results = None
58    
59     if not results:
60     s = ( '<div class="centerpage">\n'
61     '<table width="100%%" border="0" align="center"'
62     ' cellspacing="0"><tr><td colspan="3" class="fields">'
63     'Nothing found.<br></td></tr>\n'
64     '<tr><td class="item" colspan="3">'
65     '<img '
66     'src="%s/?category=generic"'
67     'align="right" alt=""> <p>I could not find any ebuild that match'
68     ' your query. Try a different query or check the'
69     ' <a HREF="%s">'
70     'fresh ebuilds main page</a>.</p></td></tr></table>\n'
71     '</div>\n' % (config.ICONS,config.FEHOME))
72     sys.stdout.write(s)
73     write_to_cache(s)
74     sys.exit(0)
75    
76     pkgs = [ query_to_dict(i) for i in results ]
77    
78     s = ''
79     for pkg in pkgs:
80     #print pkg
81     html = gentoo.package_to_html(pkg,db)
82     s = '%s\n%s<br>\n<br>\n' % (s,gentoo.package_to_html(pkg,db))
83    
84     if offset != "0":
85     s = '%s<a href="?sstring=%s;offset=%s">[Previous]</a> ' % (s,sstring,int(offset) - config.MAXPERPAGE)
86     if len(results) == config.MAXPERPAGE:
87     s = '%s<a href="?sstring=%s;offset=%s">[Next]</a> ' % (s,sstring,int(offset) + config.MAXPERPAGE)
88    
89     sys.stdout.write(s)
90     write_to_cache(s)

  ViewVC Help
Powered by ViewVC 1.1.20