Move pretty_size to helpers.py

This commit is contained in:
Jonas Borgström 2010-10-15 22:29:36 +02:00
parent cbb62fd2a6
commit 03b0e85d0b
2 changed files with 15 additions and 14 deletions

View File

@ -8,7 +8,7 @@ import argparse
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 @@ class Archive(object):
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 @@ class Archiver(object):
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')

View File

@ -49,3 +49,14 @@ def location_validator(archive=None):
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)