summaryrefslogtreecommitdiff
path: root/python/skytools/config.py
diff options
context:
space:
mode:
authormartinko2012-02-17 09:43:22 +0000
committermartinko2012-02-17 09:43:22 +0000
commitcc6358bca8445898441af6883fa0357a3a695cc5 (patch)
treee9847537ec3c36ebfd299ac34b4438d917a6236c /python/skytools/config.py
parentb013f553319e0e2db7db2a5de0080ad23d2101cf (diff)
added support for sizes specified in human readable format
Config options that hold size in bytes can now be specified in human readable format. Examples: 1, 2 B, 3K, 4 MB
Diffstat (limited to 'python/skytools/config.py')
-rw-r--r--python/skytools/config.py15
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."""