summaryrefslogtreecommitdiff
path: root/src/leap/common/config
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-05-28 17:38:30 -0300
committerTomás Touceda <chiiph@leap.se>2013-05-28 17:38:30 -0300
commit205fcd6c6bb8712a115f3dfe738c490f5427e09b (patch)
tree0d824ab1fc1de09fe2136f1419a0a2966225fac4 /src/leap/common/config
parentb7dc270bce885ce5079d86d8e52fd96b8390fc9d (diff)
parent354467c605f07042568c10c3e931f7fc093c0bf4 (diff)
Merge remote-tracking branch 'kali/bug/allow-absolute-paths2' into develop
Diffstat (limited to 'src/leap/common/config')
-rw-r--r--src/leap/common/config/baseconfig.py73
-rw-r--r--src/leap/common/config/prefixers.py16
2 files changed, 49 insertions, 40 deletions
diff --git a/src/leap/common/config/baseconfig.py b/src/leap/common/config/baseconfig.py
index 146f1e4..e6bd9c4 100644
--- a/src/leap/common/config/baseconfig.py
+++ b/src/leap/common/config/baseconfig.py
@@ -36,18 +36,19 @@ logger = logging.getLogger(__name__)
class BaseConfig:
"""
- Abstract base class for any JSON based configuration
+ Abstract base class for any JSON based configuration.
"""
__metaclass__ = ABCMeta
"""
- Standalone is a class wide parameter
+ Standalone is a class wide parameter.
- @param standalone: if True it will return the prefix for a
- standalone application. Otherwise, it will return the system
- default for configuration storage.
- @type standalone: bool
+ :param standalone: if True it will return the prefix for a
+ standalone application. Otherwise, it will
+ return the system
+ default for configuration storage.
+ :type standalone: bool
"""
standalone = False
@@ -58,16 +59,16 @@ class BaseConfig:
@abstractmethod
def _get_spec(self):
"""
- Returns the spec object for the specific configuration
+ Returns the spec object for the specific configuration.
"""
return None
def _safe_get_value(self, key):
"""
- Tries to return a value only if the config has already been loaded
+ Tries to return a value only if the config has already been loaded.
- @rtype: depends on the config structure, dict, str, array, int
- @return: returns the value for the specified key in the config
+ :rtype: depends on the config structure, dict, str, array, int
+ :return: returns the value for the specified key in the config
"""
leap_assert(self._config_checker, "Load the config first")
return self._config_checker.config.get(key, None)
@@ -88,14 +89,14 @@ class BaseConfig:
def save(self, path_list):
"""
- Saves the current configuration to disk
+ Saves the current configuration to disk.
- @param path_list: list of components that form the relative
- path to configuration. The absolute path will be calculated
- depending on the platform.
- @type path_list: list
+ :param path_list: list of components that form the relative
+ path to configuration. The absolute path
+ will be calculated depending on the platform.
+ :type path_list: list
- @return: True if saved to disk correctly, False otherwise
+ :return: True if saved to disk correctly, False otherwise
"""
config_path = os.path.join(self.get_path_prefix(), *(path_list[:-1]))
mkdir_p(config_path)
@@ -108,19 +109,27 @@ class BaseConfig:
raise
return True
- def load(self, path="", data=None, mtime=None):
+ def load(self, path="", data=None, mtime=None, relative=True):
"""
- Loads the configuration from disk
+ Loads the configuration from disk.
- @type path: str
- @param path: relative path to configuration. The absolute path
- will be calculated depending on the platform
+ :param path: if relative=True, this is a relative path
+ to configuration. The absolute path
+ will be calculated depending on the platform
+ :type path: str
- @return: True if loaded from disk correctly, False otherwise
+ :param relative: if True, path is relative. If False, it's absolute.
+ :type relative: bool
+
+ :return: True if loaded from disk correctly, False otherwise
+ :rtype: bool
"""
- config_path = os.path.join(self.get_path_prefix(),
- path)
+ if relative is True:
+ config_path = os.path.join(
+ self.get_path_prefix(), path)
+ else:
+ config_path = path
self._config_checker = PluggableConfig(format="json")
self._config_checker.options = copy.deepcopy(self._get_spec())
@@ -131,8 +140,8 @@ class BaseConfig:
else:
self._config_checker.load(data, mtime=mtime)
except Exception as e:
- logger.warning("Something went wrong while loading " +
- "the config from %s\n%s" % (config_path, e))
+ logger.error("Something went wrong while loading " +
+ "the config from %s\n%s" % (config_path, e))
self._config_checker = None
return False
return True
@@ -140,7 +149,7 @@ class BaseConfig:
class LocalizedKey(object):
"""
- Decorator used for keys that are localized in a configuration
+ Decorator used for keys that are localized in a configuration.
"""
def __init__(self, func, **kwargs):
@@ -149,13 +158,13 @@ class LocalizedKey(object):
def __call__(self, instance, lang="en"):
"""
Tries to return the string for the specified language, otherwise
- informs the problem and returns an empty string
+ informs the problem and returns an empty string.
- @param lang: language code
- @type lang: str
+ :param lang: language code
+ :type lang: str
- @return: localized value from the possible values returned by
- self._func
+ :return: localized value from the possible values returned by
+ self._func
"""
descriptions = self._func(instance)
description_lang = ""
diff --git a/src/leap/common/config/prefixers.py b/src/leap/common/config/prefixers.py
index 27274bd..050d4cd 100644
--- a/src/leap/common/config/prefixers.py
+++ b/src/leap/common/config/prefixers.py
@@ -39,10 +39,10 @@ class Prefixer:
"""
Returns the platform dependant path prefixer
- @param standalone: if True it will return the prefix for a
+ :param standalone: if True it will return the prefix for a
standalone application. Otherwise, it will return the system
default for configuration storage.
- @type standalone: bool
+ :type standalone: bool
"""
return ""
@@ -65,10 +65,10 @@ class LinuxPrefixer(Prefixer):
This method expects an env variable named LEAP_CLIENT_PATH if
standalone is used.
- @param standalone: if True it will return the prefix for a
+ :param standalone: if True it will return the prefix for a
standalone application. Otherwise, it will return the system
default for configuration storage.
- @type standalone: bool
+ :type standalone: bool
"""
config_dir = BaseDirectory.xdg_config_home
if not standalone:
@@ -87,10 +87,10 @@ class DarwinPrefixer(Prefixer):
This method expects an env variable named LEAP_CLIENT_PATH if
standalone is used.
- @param standalone: if True it will return the prefix for a
+ :param standalone: if True it will return the prefix for a
standalone application. Otherwise, it will return the system
default for configuration storage.
- @type standalone: bool
+ :type standalone: bool
"""
config_dir = BaseDirectory.xdg_config_home
if not standalone:
@@ -109,10 +109,10 @@ class WindowsPrefixer(Prefixer):
This method expects an env variable named LEAP_CLIENT_PATH if
standalone is used.
- @param standalone: if True it will return the prefix for a
+ :param standalone: if True it will return the prefix for a
standalone application. Otherwise, it will return the system
default for configuration storage.
- @type standalone: bool
+ :type standalone: bool
"""
config_dir = BaseDirectory.xdg_config_home