- def __init__(self, path):
- self.path = path
-
- self.object_type = None
-
- # Init hashes
- self.hash_md5 = None
- self.hash_sha1 = None
-
- def hash(self):
- ## This is for python 2.4.
- #import md5
- #self.hash_md5 = md5.new(self.data()).hexdigest()
-
- import sha
- self.hash_sha1 = sha.new(self.data()).hexdigest()
-
- def data(self):
- return self.filedata
-
- def run(self):
- self.hash()
- self.showhttpheaders()
- print self.data()
-
- def showhttpheaders(self):
+ def __init__(self, file):
+ self.file = file
+
+ self.db = sqlite.connect("hashes.db")
+ c = self.db.cursor()
+ c.execute("CREATE TABLE IF NOT EXISTS hashes(file, sha1)")
+ c.close()
+
+ def getHash(self, type="sha1"):
+ hash = None
+ c = self.db.cursor()
+ c.execute("SELECT %s FROM hashes WHERE file = '%s'" % (type, self.file,))
+ try:
+ hash = c.fetchone()[0]
+ except TypeError:
+ pass
+ c.close()
+
+ if not hash:
+ hash = sha.new(self.filedata).hexdigest()
+ c = self.db.cursor()
+ c.execute("INSERT INTO hashes(file, sha1) VALUES('%s', '%s')" % \
+ (self.file, hash,))
+ c.close()
+ self.db.commit()
+ return hash
+
+ def __call__(self):
+ print "Status: 200 - OK"