diff options
Diffstat (limited to 'python/skytools/config.py')
-rw-r--r-- | python/skytools/config.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/python/skytools/config.py b/python/skytools/config.py index 9f19306f..3e58139b 100644 --- a/python/skytools/config.py +++ b/python/skytools/config.py @@ -3,6 +3,8 @@ import os, os.path, ConfigParser, socket +import skytools + __all__ = ['Config'] class Config(object): @@ -161,6 +163,19 @@ class Config(object): return fn + def getbytes(self, key, default=None): + """Reads a size value in human format, if not set then default. + + Examples: 1, 2 B, 3K, 4 MB + """ + try: + s = self.cf.get(self.main_section, key) + except ConfigParser.NoOptionError: + if default is None: + raise Exception("Config value not set: " + key) + s = default + return skytools.hsize_to_bytes(s) + def get_wildcard(self, key, values=[], default=None): """Reads a wildcard property from conf and returns its string value, if not set then default.""" |