summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/packages/daily.py')
-rw-r--r--src/packages/daily.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/packages/daily.py b/src/packages/daily.py
new file mode 100644
index 0000000000..2907147fed
--- /dev/null
+++ b/src/packages/daily.py
@@ -0,0 +1,112 @@
+#!/usr/bin/python -OO
+
+import sys
+import config
+import ebuilddb
+import gentoo
+import os
+import time
+from genarchbar import genarchbar
+
+print 'Status: 200 Ok'
+print 'Content-type: text/html'
+print
+
+def error():
+ print ('<div class="centerpage">\n'
+ '<table class="ebuild">\n'
+ '<tr><td class="fields">Error in request</td></tr><br>\n'
+ '<tr><td class="item"><img src="%s/?category=generic" align="right" alt="">'
+ '<p>An error was encountered processing your request. Request a '
+ 'different page or check the <a href="%s">fresh ebuilds main page</a>.'
+ '</p></td></tr>'
+ '</table>'
+ '</div>') % (config.ICONS,config.FEHOME)
+
+try:
+ uri = os.environ['REQUEST_URI']
+ datestring = uri.split('/daily/')[1]
+except KeyError:
+ datestring =""
+
+params = datestring.split('/')
+today = time.gmtime(time.time())
+try:
+ year,month,day = [int(i) for i in params[:3]]
+except ValueError:
+ year,month,day = today[:3]
+
+try:
+ arch = params[4]
+except IndexError:
+ arch = ''
+
+if arch not in [''] + config.ARCHLIST:
+ arch = ''
+
+try:
+ branch = params[5]
+except IndexError:
+ branch = ''
+
+if branch not in ('','stable','testing'):
+ branch = ''
+
+# see if we're cached, if so write the cache and exit
+if today[:3] == (year,month,day):
+ # today is always cached ;-)
+ archnav = os.path.join(config.LOCALHOME,arch,branch,'archnav.html')
+ filename = os.path.join(config.LOCALHOME,arch,branch,'main.shtml')
+ sys.stdout.write(open(archnav,'r').read())
+ sys.stdout.write('<br>\n')
+ sys.stdout.write(open(filename,'r').read())
+ sys.exit(0)
+else:
+ filename = os.path.join(config.LOCALHOME,'daily','cache',
+ '%d%02d%02d-%s-%s.html' % (year,month,day,arch,branch))
+if os.path.exists(filename):
+ sys.stdout.write(open(filename,'r').read())
+ sys.exit(0)
+
+db = ebuilddb.db_connect()
+c = db.cursor()
+
+extra = ''
+if arch:
+ if branch == 'stable':
+ extra = ' AND ebuild.arch REGEXP "^%s| %s" ' % (arch,arch)
+ elif branch == 'testing':
+ extra = ' AND ebuild.arch REGEXP "^~%s| ~%s" ' % (arch,arch)
+ else:
+ extra = ' AND ebuild.arch LIKE "%%%s%%" ' % arch
+
+query = ('SELECT ebuild.category,'
+ 'ebuild.name,'
+ 'version,'
+ 'when_found,'
+ 'description,'
+ 'changelog,'
+ 'arch,'
+ 'homepage,'
+ 'license '
+ 'FROM ebuild,package '
+ 'WHERE TO_DAYS(when_found) = TO_DAYS("%s-%02d-%02d") '
+ 'AND ebuild.name = package.name '
+ 'AND ebuild.category = package.category %s'
+ 'ORDER BY when_found desc' %
+ (year, month, day,extra))
+
+c.execute(query)
+results = c.fetchall()
+
+s = genarchbar('%sdaily/%d/%02d/%02d/' % (config.FEHOME,year,month,day),arch,branch) + '<br>\n'
+for result in results:
+ ebuild = gentoo.query_to_dict(result)
+ s = s + gentoo.ebuild_to_html(ebuild) + '<br>\n'
+print s
+
+# cache to file, if not todays date
+if today[:3] != (year,month,day):
+ filename = os.path.join(config.LOCALHOME,'daily','cache',
+ '%d%02d%02d-%s-%s.html' % (year,month,day,arch,branch))
+ open(filename,'w').write(s)