Added rehash command
authorDmitriy Morozov <dmitriy@mrzv.org>
Mon, 12 Oct 2009 08:16:43 -0700
changeset 31 d7ef43f7669a
parent 30 919f428df29a
child 32 c38b0505a831
Added rehash command
alexandria.py
--- a/alexandria.py	Tue Sep 15 17:30:16 2009 -0700
+++ b/alexandria.py	Mon Oct 12 08:16:43 2009 -0700
@@ -250,6 +250,26 @@
         _show_paper(paper)
     else:
         print "No such path %s found" % _colorize_string('path', path)
+
+@command(dbopts,
+         usage='%name PATH')
+def rehash(cfg, path):
+    """Rehash the paper at the given path"""
+
+    m = hashlib.md5()
+    with open(path, 'r') as fd:
+        m.update(fd.read())
+
+    path = _short_path(cfg, path)
+    paper = Paper.get_by(path = path)
+
+    if paper:
+        paper.md5 = m.hexdigest()
+        session.commit()
+
+        _show_paper(paper)
+    else:
+        print "No such path %s found" % _colorize_string('path', path)
     
 def _short_path(cfg, path):
     path = os.path.abspath(path)