From: Michael Tremer Date: Sat, 28 Mar 2009 11:06:56 +0000 (+0100) Subject: Added source site. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=141ef101b5f7d1cc0e10b490b340dd9899b19de6;p=ipfire.org.git Added source site. --- diff --git a/source/dlhandler.py b/source/dlhandler.py index 83e60acc..3e7cec80 100644 --- a/source/dlhandler.py +++ b/source/dlhandler.py @@ -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") diff --git a/source/index.py b/source/index.py index 122a725f..fe83d4e9 120000 --- a/source/index.py +++ b/source/index.py @@ -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 index 00000000..236b4e05 --- /dev/null +++ b/www/pages/source/__init__.py @@ -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("

IPFire Source Base

") + for dir, files in self.dirs: + b = web.Box(dir) + b.w("") + ret += b() + return ret + +Sidebar = web.Sidebar +