1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#!/usr/bin/python
import cgi
import os
import sys
import config
import gentoo,ebuilddb
DEFAULT = "404"
PKG_DIR = config.EBUILD_FILES
if len(sys.argv):
ebuild = sys.argv[1]
else:
ebuild = DEFAULT
html_file = os.path.join(PKG_DIR,"%s.html" % ebuild.replace('..',''))
if os.path.exists(html_file):
send_file = html_file
else:
# let's try the database
# connect
pos=ebuilddb.FINDVER.search(ebuild).start()
name = ebuild[:pos]
version = ebuild[pos+1:]
db = ebuilddb.db_connect()
# query
query = ('SELECT ebuild.category,ebuild.name,version,when_found,'
'description,changelog,arch,homepage,license '
'FROM ebuild,package WHERE ebuild.name="%s" AND '
'version="%s" AND '
'ebuild.name=package.name AND ebuild.category=package.category '
'ORDER by when_found DESC LIMIT 1' % (name,version))
#print query
c = db.cursor()
c.execute(query)
result = c.fetchone()
if result:
#print result
eb = gentoo.query_to_dict(result)
sys.stdout.write(gentoo.ebuild_to_html(eb))
sys.exit(0)
# else 404
else:
send_file = os.path.join(PKG_DIR,"%s.html" % DEFAULT)
sys.stdout.write(open(send_file,"r").read())
sys.stdout.flush()
|