| 1 |
#!/usr/bin/python -O
|
| 2 |
|
| 3 |
import sys
|
| 4 |
import config
|
| 5 |
import ebuilddb
|
| 6 |
import gentoo
|
| 7 |
import os
|
| 8 |
import time
|
| 9 |
from genarchbar import genarchbar
|
| 10 |
|
| 11 |
print 'Status: 200 Ok'
|
| 12 |
print 'Content-type: text/html'
|
| 13 |
print
|
| 14 |
|
| 15 |
def error():
|
| 16 |
print ('<div class="centerpage">\n'
|
| 17 |
'<table class="ebuild">\n'
|
| 18 |
'<tr><td class="fields">Error in request</td></tr><br>\n'
|
| 19 |
'<tr><td class="item"><img src="%s/?category=generic" align="right" alt="">'
|
| 20 |
'<p>An error was encountered processing your request. Request a '
|
| 21 |
'different page or check the <a href="%s">packages.gentoo.org main page</a>.'
|
| 22 |
'</p></td></tr>'
|
| 23 |
'</table>'
|
| 24 |
'</div>') % (config.ICONS,config.FEHOME)
|
| 25 |
|
| 26 |
try:
|
| 27 |
uri = os.environ['REQUEST_URI']
|
| 28 |
datestring = uri.split('/daily/')[1]
|
| 29 |
except KeyError:
|
| 30 |
datestring =""
|
| 31 |
|
| 32 |
params = datestring.split('/')
|
| 33 |
today = time.gmtime(time.time())
|
| 34 |
try:
|
| 35 |
year,month,day = [int(i) for i in params[:3]]
|
| 36 |
except ValueError:
|
| 37 |
year,month,day = today[:3]
|
| 38 |
|
| 39 |
try:
|
| 40 |
arch = params[4]
|
| 41 |
except IndexError:
|
| 42 |
arch = ''
|
| 43 |
|
| 44 |
if arch not in [''] + config.ARCHLIST:
|
| 45 |
arch = ''
|
| 46 |
|
| 47 |
try:
|
| 48 |
branch = params[5]
|
| 49 |
except IndexError:
|
| 50 |
branch = ''
|
| 51 |
|
| 52 |
if branch not in ('','stable','testing'):
|
| 53 |
branch = ''
|
| 54 |
|
| 55 |
# see if we're cached, if so write the cache and exit
|
| 56 |
if today[:3] == (year,month,day):
|
| 57 |
# today is always cached ;-)
|
| 58 |
archnav = os.path.join(config.LOCALHOME,arch,branch,'archnav.html')
|
| 59 |
filename = os.path.join(config.LOCALHOME,arch,branch,'main.shtml')
|
| 60 |
sys.stdout.write(open(archnav,'r').read())
|
| 61 |
sys.stdout.write('<br>\n')
|
| 62 |
sys.stdout.write(open(filename,'r').read())
|
| 63 |
sys.exit(0)
|
| 64 |
else:
|
| 65 |
filename = os.path.join(config.LOCALHOME,'daily','cache',
|
| 66 |
'%d%02d%02d-%s-%s.html' % (year,month,day,arch,branch))
|
| 67 |
if os.path.exists(filename):
|
| 68 |
sys.stdout.write(open(filename,'r').read())
|
| 69 |
sys.exit(0)
|
| 70 |
|
| 71 |
db = ebuilddb.db_connect()
|
| 72 |
c = db.cursor()
|
| 73 |
|
| 74 |
extra = ''
|
| 75 |
if arch:
|
| 76 |
stable_extra = ('FIND_IN_SET("%s", ebuild.arch) > 0 AND '
|
| 77 |
'FIND_IN_SET("%s", ebuild.prevarch) = 0 ' % (arch, arch))
|
| 78 |
testing_extra = ('FIND_IN_SET("~%s", ebuild.arch) > 0 AND '
|
| 79 |
'FIND_IN_SET("%s", ebuild.prevarch) = 0 ' % (arch, arch))
|
| 80 |
if branch == 'stable':
|
| 81 |
extra = ' AND (%s) ' % stable_extra
|
| 82 |
elif branch == 'testing':
|
| 83 |
extra = ' AND (%s) ' % testing_extra
|
| 84 |
else:
|
| 85 |
extra = ' AND ((%s) OR (%s)) ' % (stable_extra, testing_extra)
|
| 86 |
|
| 87 |
query = ('SELECT ebuild.category,'
|
| 88 |
'ebuild.name,'
|
| 89 |
'version,'
|
| 90 |
'when_found,'
|
| 91 |
'description,'
|
| 92 |
'changelog,'
|
| 93 |
'arch,'
|
| 94 |
'homepage,'
|
| 95 |
'license, is_masked '
|
| 96 |
'FROM ebuild,package '
|
| 97 |
'WHERE SUBSTRING(when_found FROM 1 FOR 8) = "%s%02d%02d" '
|
| 98 |
'AND ebuild.name = package.name '
|
| 99 |
'AND ebuild.category = package.category %s'
|
| 100 |
'ORDER BY when_found desc' %
|
| 101 |
(year, month, day,extra))
|
| 102 |
|
| 103 |
c.execute(query)
|
| 104 |
results = c.fetchall()
|
| 105 |
|
| 106 |
s = genarchbar('%sdaily/%d/%02d/%02d/' % (config.FEHOME,year,month,day),arch,branch) + '<br>\n'
|
| 107 |
for result in results:
|
| 108 |
ebuild = gentoo.query_to_dict(result)
|
| 109 |
s = s + gentoo.ebuild_to_html(ebuild) + '<br>\n'
|
| 110 |
print s
|
| 111 |
|
| 112 |
# cache to file, if not todays date
|
| 113 |
if today[:3] != (year,month,day):
|
| 114 |
filename = os.path.join(config.LOCALHOME,'daily','cache',
|
| 115 |
'%d%02d%02d-%s-%s.html' % (year,month,day,arch,branch))
|
| 116 |
open(filename,'w').write(s)
|