Mercurial > hg > TagInTheMiddle
diff taginthemiddle/model.py @ 1:837cfc05d4d9
add times to tags; cant things ever be easy?
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 04 May 2010 18:46:05 -0700 |
parents | 1c5cbbde4299 |
children | 1182315b18ac |
line wrap: on
line diff
--- a/taginthemiddle/model.py Tue May 04 08:37:15 2010 -0700 +++ b/taginthemiddle/model.py Tue May 04 18:46:05 2010 -0700 @@ -1,4 +1,16 @@ +""" + tags have: + - a list of resources they're applied to + - a time they're applied + for now just assume auth is on and that anyone authenticated may tag + e.g. a tags file + +foo = /bar:1273023556 /fleem/baz:1273023556 etc +cats = /cats:1273023556 /blog/mycat:1273023556 +""" + import os +import time class Tags(object): """file (e.g. .ini) based tagging scheme""" @@ -13,6 +25,7 @@ f.close() self.tags = {} self.urls = {} + self.times = {} self.read(path) @@ -26,12 +39,15 @@ urls = urls.strip() self.tags[tag] = set([urls]) for url in urls: + url, time = url.rsplit(':', 1) self.urls.setdefault(url, set()).add(tag) + self.times[(tag, url)] = int(time) def write(self): f = file(self.path, 'w') for tag in sorted(self.tags.keys()): - print >> f, '%s = %s' % (tag, ' '.join(self.tags[tag])) + print >> f, '%s = %s' % (tag, ' '.join(['%s:%s' % (url, self.times(tag, url)) + for url in self.tags[tag]])) f.close() def add(self, tag, url): @@ -39,6 +55,7 @@ return self.tags[tag].add(url) self.urls[url].add(tag) + self.times[(tag, url)] = int(time.time()) self.write() def remove(self, tag, url):