forked from third-party-mirrors/zfs_autobackup
itertools is nice :)
This commit is contained in:
parent
bcc7983492
commit
b7e10242b9
@ -1,3 +1,4 @@
|
|||||||
|
import itertools
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
@ -42,28 +43,15 @@ class TreeHasher():
|
|||||||
|
|
||||||
cwd=os.getcwd()
|
cwd=os.getcwd()
|
||||||
os.chdir(start_path)
|
os.chdir(start_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
current= [None]
|
|
||||||
def per_file_generator():
|
|
||||||
|
|
||||||
(current_file_path, chunk_nr, hash)=current[0]
|
def filter_file_name( file_name, chunk_nr, hexdigest):
|
||||||
yield ( chunk_nr, hash)
|
return ( chunk_nr, hexdigest )
|
||||||
|
|
||||||
for (file_path, chunk_nr, hash) in generator:
|
|
||||||
if file_path==current_file_path:
|
|
||||||
yield ( chunk_nr, hash)
|
|
||||||
else:
|
|
||||||
current[0] = (file_path, chunk_nr, hash)
|
|
||||||
return
|
|
||||||
|
|
||||||
current[0]=None
|
|
||||||
|
|
||||||
|
|
||||||
current[0] = generator.next()
|
for file_name, group_generator in itertools.groupby(generator, lambda x: x[0]):
|
||||||
while current[0] is not None:
|
block_generator=itertools.starmap(filter_file_name, group_generator)
|
||||||
self.block_hasher.compare(current[0][0], per_file_generator())
|
self.block_hasher.compare(file_name, block_generator)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user