]> git.ipfire.org Git - ipfire.org.git/commitdiff
Added source site.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 28 Mar 2009 11:06:56 +0000 (12:06 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 28 Mar 2009 11:06:56 +0000 (12:06 +0100)
source/dlhandler.py
source/index.py
www/pages/source/__init__.py [new file with mode: 0644]

index 83e60acc16bca882fb291c187388ffa589a88115..3e7cec80f9f8b2e671e837c1c438a29e70ea6024 100644 (file)
@@ -29,6 +29,8 @@ sys.path.append(".")
 
 from git import *
 
+SOURCE_BASE = "/srv/sources"
+
 def give_403():
        print "Status: 403 Forbidden"
        print "Pragma: no-cache"
@@ -105,7 +107,7 @@ class FileObject(SourceObject):
        def __init__(self, path, file):
                SourceObject.__init__(self, file)
                self.path = path
-               self.filepath = "/%s/%s/%s" % (os.getcwd(), path, file,)
+               self.filepath = "/%s/%s/%s" % (SOURCE_BASE, path, file,)
 
                try:
                        f = open(self.filepath, "rb")
index 122a725f4e3a19dd2a70c48636f3ea7473caa6a9..fe83d4e9e9aba10c1933eb51a134f5dbc0d96bbc 120000 (symlink)
@@ -1 +1 @@
-../www/index.py
\ No newline at end of file
+../www/redirect.py
\ No newline at end of file
diff --git a/www/pages/source/__init__.py b/www/pages/source/__init__.py
new file mode 100644 (file)
index 0000000..236b4e0
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/python
+
+SOURCE_BASE="/srv/sources"
+SOURCE_HASHES="/srv/www/ipfire.org/source/hashes.db"
+
+SOURCE_URL="http://source.ipfire.org"
+
+import os
+import sha
+from pysqlite2 import dbapi2 as sqlite
+
+import web
+
+class SourceObject:
+       def __init__(self, db, file):
+               self.file = file
+               self.name = os.path.basename(file)
+
+               if db:
+                       self.db = db
+               else:
+                       self.db = sqlite.connect(SOURCE_HASHES)
+                       c = self.db.cursor()
+                       c.execute("CREATE TABLE IF NOT EXISTS hashes(file, sha1)")
+                       c.close()
+               
+       def data(self):
+               f = open(self.file, "rb")
+               data = f.read()
+               f.close()
+               return data
+
+       def getHash(self, type="sha1"):
+               hash = None
+               c = self.db.cursor()
+               c.execute("SELECT %s FROM hashes WHERE file = '%s'" % (type, self.name,))
+               try:
+                       hash = c.fetchone()[0]
+               except TypeError:
+                       pass
+               c.close()
+
+               if not hash:
+                       hash = sha.new(self.data()).hexdigest()
+                       c = self.db.cursor()
+                       c.execute("INSERT INTO hashes(file, sha1) VALUES('%s', '%s')" % \
+                               (self.name, hash,))
+                       c.close()
+                       self.db.commit()
+               return hash
+
+
+class Content(web.Content):
+       def __init__(self, name):
+               web.Content.__init__(self, name)
+               
+               self.dirs = []
+
+               # Open database
+               db = sqlite.connect(SOURCE_HASHES)
+               
+               for dir, subdirs, files in os.walk(SOURCE_BASE):
+                       if not files:
+                               continue
+                       fileobjects = []
+                       files.sort()
+                       for file in files:
+                               file = os.path.join(dir, file)
+                               fileobjects.append(SourceObject(db, file))
+                       self.dirs.append((os.path.basename(dir), fileobjects))
+               
+       def __call__(self, lang):
+               ret = ""
+               self.w("<h3>IPFire Source Base</h3>")
+               for dir, files in self.dirs:
+                       b = web.Box(dir)
+                       b.w("<ul>")
+                       for file in files:
+                               b.w("""<li style="font-family: courier;">%(hash)s | <a href="%(url)s/%(dir)s/%(file)s">%(file)s</a></li>""" % \
+                                       { "file" : file.name,
+                                         "hash" : file.getHash() or "0000000000000000000000000000000000000000",
+                                         "dir"  : dir,
+                                         "url"  : SOURCE_URL, })
+                       b.w("</ul>")
+                       ret += b()
+               return ret
+
+Sidebar = web.Sidebar
+