diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-07-04 16:53:05 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-07-04 16:53:05 +1200 |
commit | a577264a8b46c1b8983f45bf1be56d7f74b2dd38 (patch) | |
tree | 41541bc2ea9e364f919487512f163c44382180ad | |
parent | ba786e32fcd4ea3feabdc16b4971538202110955 (diff) | |
download | obnam-a577264a8b46c1b8983f45bf1be56d7f74b2dd38.tar.gz |
Add new option type for specifying sizes in bytes.
-rw-r--r-- | obnamlib/cfg.py | 6 | ||||
-rw-r--r-- | obnamlib/cfg_tests.py | 10 |
2 files changed, 16 insertions, 0 deletions
diff --git a/obnamlib/cfg.py b/obnamlib/cfg.py index 89137a1d..ff635b32 100644 --- a/obnamlib/cfg.py +++ b/obnamlib/cfg.py @@ -95,6 +95,12 @@ class Configuration(object): self.new_string(names, help) self.processors[names[0]] = callback + def new_bytesize(self, names, help): + def callback(value): + p = obnamlib.ByteSizeParser() + return p.parse(value) + self.new_processed(names, help, callback) + def new_list(self, names, help): self.new_setting('list', names, help, 'append', []) diff --git a/obnamlib/cfg_tests.py b/obnamlib/cfg_tests.py index 248437fb..551a84ad 100644 --- a/obnamlib/cfg_tests.py +++ b/obnamlib/cfg_tests.py @@ -73,3 +73,13 @@ class ConfigurationTests(unittest.TestCase): self.cfg.load(['--size=123']) self.assertEqual(self.cfg['size'], 123) + def test_handles_unadorned_bytesize(self): + self.cfg.new_bytesize(['size'], 'size help') + self.cfg.load(['--size=123']) + self.assertEqual(self.cfg['size'], 123) + + def test_handles_bytesize_with_units(self): + self.cfg.new_bytesize(['size'], 'size help') + self.cfg.load(['--size=123KiB']) + self.assertEqual(self.cfg['size'], 123*1024) + |