1 |
marduk |
1.1 |
#!/usr/bin/python -OO |
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">fresh ebuilds 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 |
|
|
if branch == 'stable': |
77 |
|
|
extra = ' AND ebuild.arch REGEXP "^%s| %s" ' % (arch,arch) |
78 |
|
|
elif branch == 'testing': |
79 |
|
|
extra = ' AND ebuild.arch REGEXP "^~%s| ~%s" ' % (arch,arch) |
80 |
|
|
else: |
81 |
|
|
extra = ' AND ebuild.arch LIKE "%%%s%%" ' % arch |
82 |
|
|
|
83 |
|
|
query = ('SELECT ebuild.category,' |
84 |
|
|
'ebuild.name,' |
85 |
|
|
'version,' |
86 |
|
|
'when_found,' |
87 |
|
|
'description,' |
88 |
|
|
'changelog,' |
89 |
|
|
'arch,' |
90 |
|
|
'homepage,' |
91 |
|
|
'license ' |
92 |
|
|
'FROM ebuild,package ' |
93 |
|
|
'WHERE TO_DAYS(when_found) = TO_DAYS("%s-%02d-%02d") ' |
94 |
|
|
'AND ebuild.name = package.name ' |
95 |
|
|
'AND ebuild.category = package.category %s' |
96 |
|
|
'ORDER BY when_found desc' % |
97 |
|
|
(year, month, day,extra)) |
98 |
|
|
|
99 |
|
|
c.execute(query) |
100 |
|
|
results = c.fetchall() |
101 |
|
|
|
102 |
|
|
s = genarchbar('%sdaily/%d/%02d/%02d/' % (config.FEHOME,year,month,day),arch,branch) + '<br>\n' |
103 |
|
|
for result in results: |
104 |
|
|
ebuild = gentoo.query_to_dict(result) |
105 |
|
|
s = s + gentoo.ebuild_to_html(ebuild) + '<br>\n' |
106 |
|
|
print s |
107 |
|
|
|
108 |
|
|
# cache to file, if not todays date |
109 |
|
|
if today[:3] != (year,month,day): |
110 |
|
|
filename = os.path.join(config.LOCALHOME,'daily','cache', |
111 |
|
|
'%d%02d%02d-%s-%s.html' % (year,month,day,arch,branch)) |
112 |
|
|
open(filename,'w').write(s) |