From 03b0e85d0bdbedc2901b857950fbede339043ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Fri, 15 Oct 2010 22:29:36 +0200 Subject: [PATCH] Move pretty_size to helpers.py --- dedupestore/archiver.py | 18 ++++-------------- dedupestore/helpers.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/dedupestore/archiver.py b/dedupestore/archiver.py index c028822c8..caee47135 100644 --- a/dedupestore/archiver.py +++ b/dedupestore/archiver.py @@ -8,7 +8,7 @@ from chunkifier import chunkify from cache import Cache, NS_ARCHIVES, NS_CHUNKS from bandstore import BandStore -from helpers import location_validator +from helpers import location_validator, pretty_size CHUNK_SIZE = 55001 @@ -167,16 +167,6 @@ def process_file(self, path, cache): class Archiver(object): - def pretty_size(self, v): - if v > 1024 * 1024 * 1024: - return '%.2f GB' % (v / 1024. / 1024. / 1024.) - elif v > 1024 * 1024: - return '%.2f MB' % (v / 1024. / 1024.) - elif v > 1024: - return '%.2f kB' % (v / 1024.) - else: - return str(v) - def open_store(self, location): store = BandStore(location.path) cache = Cache(store) @@ -215,9 +205,9 @@ def do_info(self, args): store, cache = self.open_store(args.archive) archive = Archive(store, cache, args.archive.archive) stats = archive.stats(cache) - print 'Original size:', self.pretty_size(stats['osize']) - print 'Compressed size:', self.pretty_size(stats['csize']) - print 'Unique data:', self.pretty_size(stats['usize']) + print 'Original size:', pretty_size(stats['osize']) + print 'Compressed size:', pretty_size(stats['csize']) + print 'Unique data:', pretty_size(stats['usize']) def run(self): parser = argparse.ArgumentParser(description='Dedupestore') diff --git a/dedupestore/helpers.py b/dedupestore/helpers.py index ea88efc66..a8d5bb31a 100644 --- a/dedupestore/helpers.py +++ b/dedupestore/helpers.py @@ -49,3 +49,14 @@ def validator(text): return validator +def pretty_size(v): + if v > 1024 * 1024 * 1024: + return '%.2f GB' % (v / 1024. / 1024. / 1024.) + elif v > 1024 * 1024: + return '%.2f MB' % (v / 1024. / 1024.) + elif v > 1024: + return '%.2f kB' % (v / 1024.) + else: + return str(v) + +