]> git.ipfire.org Git - ipfire.org.git/commitdiff
Add a SourceHandler.
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Jan 2010 22:00:20 +0000 (23:00 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Jan 2010 22:00:30 +0000 (23:00 +0100)
www/templates/sources.html [new file with mode: 0644]
www/webapp/__init__.py
www/webapp/handlers.py

diff --git a/www/templates/sources.html b/www/templates/sources.html
new file mode 100644 (file)
index 0000000..6189966
--- /dev/null
@@ -0,0 +1,23 @@
+{% extends "base.html" %}
+
+{% block title %}{{ _("Sources") }}{% end block %}
+
+{% block content %}
+       <h3>{{ _("Source Code") }}</h3>
+
+       <p>
+               {{ _("There are %s source files on the server.") % len(files) }}
+       </p>
+
+       <br class="clear" />
+
+       <ul class="sources">
+               {% for file in files %}
+                       <li>
+                               {{ file["hash"] }} |
+                               <a href="/{{ file["dir"] }}/{{ file["name"] }}">{{ file["name"] }}</a>
+                               ({{ file["size"] }})
+                       </li>
+               {% end %}
+       </ul>
+{% end block %}
index 1a8561641b9b93f8e32fb87eb29e2cee73d708b8..9898f03fac83051e198c2b5ef6dd2083235d452d 100644 (file)
@@ -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
index 4a0a2a066613a1b175d80647f7dfd1d76f4effa0..27c159c026cf870576b17b76f221f36f7783a0f0 100644 (file)
@@ -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)