[mirrorbrain-commits] r8060 - /trunk/mb/mb/hashes.py

From: <poeml_at_mirrorbrain.org>
Date: Thu, 06 May 2010 22:02:58 -0000
Author: poeml
Date: Fri May  7 00:02:57 2010
New Revision: 8060

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8060&view=rev
Log:
mb makehashes:
- adjust for creating zsync hashes only when configured to do so.

Modified:
    trunk/mb/mb/hashes.py

Modified: trunk/mb/mb/hashes.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/hashes.py?rev=8060&r1=8059&r2=8060&view=diff
==============================================================================
--- trunk/mb/mb/hashes.py (original)
+++ trunk/mb/mb/hashes.py Fri May  7 00:02:57 2010
_at_@ -30,7 +30,7 @@
 class Hasheable:
     """represent a file and its metadata"""
     def __init__(self, basename, src_dir=None, dst_dir=None,
-                 base_dir=None):
+                 base_dir=None, do_zsync=False):
         self.basename = basename
         if src_dir:
             self.src_dir = src_dir
_at_@ -54,6 +54,7 @@
         self.dst = os.path.join(self.dst_dir, self.dst_basename)
 
         self.hb = HashBag(src=self.src, parent=self)
+        self.hb.do_zsync = do_zsync
 
     def islink(self):
         return stat.S_ISLNK(self.mode)
_at_@ -154,7 +155,7 @@
                        ''.join(self.hb.pieceshex),
                        self.hb.pgp or '',
                        self.hb.zblocksize,
-                       '%s,%s,%s' % (self.hb.zseq_matches, self.hb.zrsum_len, self.hb.zchecksum_len),
+                       self.hb.get_zparams(),
                        binascii.hexlify(''.join(self.hb.zsums))]
                       )
             if verbose:
_at_@ -186,7 +187,7 @@
                        PIECESIZE, ''.join(self.hb.pieceshex),
                        self.hb.pgp or '', 
                        self.hb.zblocksize,
-                       '%s,%s,%s' % (self.hb.zseq_matches, self.hb.zrsum_len, self.hb.zchecksum_len),
+                       self.hb.get_zparams(),
                        binascii.hexlify(''.join(self.hb.zsums)),
                        file_id])
             if verbose:
_at_@ -220,7 +221,12 @@
         self.pieces = []
         self.pieceshex = []
 
+        self.do_zsync = False
         self.zsums = []
+        self.zblocksize = 0
+        self.zseq_matches = None
+        self.zrsum_len = None
+        self.zchecksum_len = None
 
         self.empty = True
 
_at_@ -230,7 +236,8 @@
             sys.stdout.write('Hashing %r... ' % self.src)
             sys.stdout.flush()
 
-        self.zs_guess_zsync_params()
+        if self.do_zsync:
+            self.zs_guess_zsync_params()
 
         m = md5.md5()
         s1 = sha1.sha1()
_at_@ -294,6 +301,17 @@
         return '\n'.join(r)
 
 
+    def get_zparams(self):
+        if self.zseq_matches and \
+           self.zrsum_len and \
+           self.zchecksum_len:
+            return '%s,%s,%s' % (self.zseq_matches, 
+                                 self.zrsum_len, 
+                                 self.zchecksum_len)
+        else:
+            return ''
+
+
     def __str__(self):
         return self.dump_raw()
 
_at_@ -386,9 +404,10 @@
             md4.update(block)
             c = md4.digest()
 
-            r = zsync.rsum06(block)
-
-            self.zsums.append( r[-self.zrsum_len:] )      # save only some trailing bytes
-            self.zsums.append( c[0:self.zchecksum_len] )  # save only some leading bytes
-
-
+            if self.do_zsync:
+                r = zsync.rsum06(block)
+
+                self.zsums.append( r[-self.zrsum_len:] )      # save only some trailing bytes
+                self.zsums.append( c[0:self.zchecksum_len] )  # save only some leading bytes
+
+




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Thu May 06 2010 - 22:02:59 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT