Python 2.5 compatibility
[trackgit.git] / commitcache.py
blobe3eb781c55c140eed0a4333313be5be82cecec66
1 import shelve
2 import time
4 from git import git
6 class Commit(object):
8 def __init__(self, cdate):
9 self.cdate = cdate
11 def __cmp__(self, other):
12 return cmp(self.cdate, other.cdate)
14 def __str__(self):
15 return '<Commit %s>' % time.strftime("%c", time.localtime(self.cdate))
17 @classmethod
18 def scan(cls, sha1):
19 cdate = int(git('log', '-1', '--pretty=format:%ct', sha1)[0].strip())
20 return cls(cdate)
22 class CommitCache(object):
24 def __init__(self, filename):
25 self._db = shelve.open(filename)
27 def __getitem__(self, key):
28 if key in self._db:
29 return self._db[key]
30 v = self._db[key] = Commit.scan(key)
31 return v