diff --git a/darc/archive.py b/darc/archive.py index cc61c87e3..f7e1d7ac0 100644 --- a/darc/archive.py +++ b/darc/archive.py @@ -30,7 +30,6 @@ class DoesNotExist(Exception): class AlreadyExists(Exception): pass - def __init__(self, store, key, manifest, name, cache=None, create=False, checkpoint_interval=300): self.key = key self.store = store @@ -79,6 +78,7 @@ def __repr__(self): def iter_items(self, callback): unpacker = msgpack.Unpacker() counter = Counter(0) + def cb(chunk, error, id): if error: raise error @@ -157,7 +157,7 @@ def cb(chunk, error, id): try: for id, size, csize in item['chunks']: count, _, _ = self.cache.chunks[id] - stats.update(size, csize, count==1) + stats.update(size, csize, count == 1) stats.nfiles += 1 self.cache.chunks[id] = count - 1, size, csize except KeyError: @@ -168,7 +168,7 @@ def cb(chunk, error, id): for id in self.metadata['items']: self.store.get(id, callback=cb, callback_data=id) count, size, csize = self.cache.chunks[id] - stats.update(size, csize, count==1) + stats.update(size, csize, count == 1) self.cache.chunks[id] = count - 1, size, csize self.store.flush_rpc() cache.rollback() @@ -176,7 +176,6 @@ def cb(chunk, error, id): def extract_item(self, item, dest=None, start_cb=None, restore_attrs=True): dest = dest or os.getcwdu() - dir_stat_queue = [] assert item['path'][0] not in ('/', '\\', ':') path = os.path.join(dest, encode_filename(item['path'])) mode = item['mode'] @@ -266,7 +265,7 @@ def verify_chunk(chunk, error, (id, i)): return if i == 0: start(item) - data = self.key.decrypt(id, chunk) + self.key.decrypt(id, chunk) if i == n - 1: result(item, True) state = {} @@ -377,4 +376,3 @@ def process_file(self, path, st, cache): def list_archives(store, key, manifest, cache=None): for name, info in manifest.archives.items(): yield Archive(store, key, manifest, name, cache=cache) - diff --git a/darc/archiver.py b/darc/archiver.py index 4c5eba1a7..951557c4d 100644 --- a/darc/archiver.py +++ b/darc/archiver.py @@ -14,6 +14,7 @@ get_cache_dir, format_timedelta, purge_split, Manifest from .remote import StoreServer, RemoteStore + class Archiver(object): def __init__(self): @@ -137,6 +138,7 @@ def _process(self, archive, cache, patterns, skip_inodes, path): def do_extract(self, args): def start_cb(item): self.print_verbose(item['path']) + def extract_cb(item): if exclude_path(item['path'], args.patterns): return @@ -211,14 +213,17 @@ def do_verify(self, args): key = Key(store) manifest = Manifest(store, key) archive = Archive(store, key, manifest, args.archive.archive) + def start_cb(item): self.print_verbose('%s ...', item['path'], newline=False) + def result_cb(item, success): if success: self.print_verbose('OK') else: self.print_verbose('ERROR') self.print_error('%s: verification failed' % item['path']) + def callback(item): if exclude_path(item['path'], args.patterns): return @@ -403,6 +408,7 @@ def run(self, args=None): self.verbose = args.verbose return args.func(args) + def main(): archiver = Archiver() sys.exit(archiver.run()) diff --git a/darc/key.py b/darc/key.py index e3e2dbbc2..93f3be7cb 100644 --- a/darc/key.py +++ b/darc/key.py @@ -16,6 +16,7 @@ PREFIX = '\0' * 8 + class Key(object): FILE_ID = 'DARC KEY' @@ -63,7 +64,7 @@ def open(self, filename, prompt=None, password=None): self.path = filename def post_manifest_load(self, config): - iv = bytes_to_long(config['aes_counter'])+100 + iv = bytes_to_long(config['aes_counter']) + 100 self.counter = Counter.new(64, initial_value=iv, prefix=PREFIX) def pre_manifest_write(self, manifest): diff --git a/darc/store.py b/darc/store.py index da98fe275..5259f0c2b 100644 --- a/darc/store.py +++ b/darc/store.py @@ -36,7 +36,6 @@ class Store(object): class DoesNotExist(KeyError): """Requested key does not exist""" - def __init__(self, path, create=False): if create: self.create(path) @@ -133,6 +132,7 @@ def compact_segments(self): """ if not self.compact: return + def lookup(tag, key): return tag == TAG_PUT and self.index.get(key, (-1, -1))[0] == segment segments = self.segments @@ -268,7 +268,7 @@ def close(self): for segment in self.fds.keys(): self.fds.pop(segment).close() self.close_segment() - self.fds = None # Just to make sure we're disabled + self.fds = None # Just to make sure we're disabled def _segment_names(self, reverse=False): for dirpath, dirs, filenames in os.walk(os.path.join(self.path, 'data')): @@ -322,7 +322,7 @@ def get_fd(self, segment): def delete_segment(self, segment): try: os.unlink(self.segment_filename(segment)) - except OSError, e: + except OSError: pass def iter_objects(self, segment, lookup=None, include_data=False): @@ -380,7 +380,6 @@ def write_put(self, id, data): def write_delete(self, id): fd = self.get_write_fd() - offset = self.offset header = self.header_no_crc_fmt.pack(self.put_header_fmt.size, TAG_DELETE) crc = self.crc_fmt.pack(crc32(id, crc32(header)) & 0xffffffff) fd.write(''.join((crc, header, id))) diff --git a/darc/test.py b/darc/test.py index af60ef73f..430062a86 100644 --- a/darc/test.py +++ b/darc/test.py @@ -92,8 +92,8 @@ def diff_dirs(self, dir1, dir2): self.assertEqual(d1, d2) def test_basic_functionality(self): - self.create_regual_file('file1', size=1024*80) - self.create_regual_file('dir2/file2', size=1024*80) + self.create_regual_file('file1', size=1024 * 80) + self.create_regual_file('dir2/file2', size=1024 * 80) x = xattr(os.path.join(self.input_path, 'file1')) x.set('user.foo', 'bar') os.link(os.path.join(self.input_path, 'file1'), @@ -136,9 +136,11 @@ def test_purge_store(self): assert 'test1' not in output assert 'test2' in output + class RemoteTest(Test): prefix = 'localhost:' + def suite(): suite = unittest.TestSuite() suite.addTest(unittest.TestLoader().loadTestsFromTestCase(Test))