From: Michael Tremer Date: Mon, 18 Jan 2010 22:00:20 +0000 (+0100) Subject: Add a SourceHandler. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e2b0b0e45a554e55597bb6355838ff1944d8ed7d;p=ipfire.org.git Add a SourceHandler. --- diff --git a/www/templates/sources.html b/www/templates/sources.html new file mode 100644 index 00000000..61899662 --- /dev/null +++ b/www/templates/sources.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% block title %}{{ _("Sources") }}{% end block %} + +{% block content %} +

{{ _("Source Code") }}

+ +

+ {{ _("There are %s source files on the server.") % len(files) }} +

+ +
+ + +{% end block %} diff --git a/www/webapp/__init__.py b/www/webapp/__init__.py index 1a856164..9898f03f 100644 --- a/www/webapp/__init__.py +++ b/www/webapp/__init__.py @@ -72,7 +72,7 @@ class Application(tornado.web.Application): # source.ipfire.org self.add_handlers(r"source\.ipfire\.org", [ (r"/", MainHandler), -# (r"/[A-Za-z]{2}/index", SourceHandler), + (r"/[A-Za-z]{2}/index", SourceHandler), ] + static_handlers) # torrent.ipfire.org diff --git a/www/webapp/handlers.py b/www/webapp/handlers.py index 4a0a2a06..27c159c0 100644 --- a/www/webapp/handlers.py +++ b/www/webapp/handlers.py @@ -1,8 +1,10 @@ #!/usr/bin/python import httplib +import operator import os import simplejson +import sqlite3 import time import urlparse @@ -11,6 +13,7 @@ import tornado.locale import tornado.web from banners import banners +from helpers import size from info import info from news import news from releases import releases @@ -197,3 +200,43 @@ class ApiClusterInfoHandler(BaseHandler): class TranslationHandler(BaseHandler): def get(self): self.render("translations.html", projects=translations.projects) + + +class SourceHandler(BaseHandler): + def prepare(self): + if not hasattr(self, "db"): + self.db = sqlite3.connect("/srv/www/ipfire.org/source/hashes.db") + c = self.db.cursor() + c.execute("CREATE TABLE IF NOT EXISTS hashes(file, sha1)") + c.close() + + def get(self): + source_path = "/srv/sources" + fileobjects = [] + + for dir, subdirs, files in os.walk(source_path): + if not files: + continue + for file in files: + if file in [f["name"] for f in fileobjects]: + continue + + c = self.db.cursor() + c.execute("SELECT sha1 FROM hashes WHERE file = '%s'" % file) + hash = "%s" % c.fetchone() + + if hash == "None": + hash = "0000000000000000000000000000000000000000" + + fileobjects.append({ + "dir" : dir[len(source_path)+1:], + "name" : file, + "hash" : hash, + "size" : size(os.path.getsize(os.path.join(source_path, dir, file))), + }) + + c.close() + + fileobjects.sort(key=operator.itemgetter("name")) + + self.render("sources.html", files=fileobjects)