summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-08-23 23:22:36 +0900
committerkali <kali@leap.se>2012-08-23 23:25:10 +0900
commitae64232f5edbb71cbe871a7ae9c76c1839654795 (patch)
tree0a74ced95905bc707545725441cfbc2e937104ba
parent1da2cf6bbc64bfc624ea6fed9beb83d301f308d1 (diff)
base config and json-config
an initial attempt at stablishing base classes for config. we go with a jsonconfig by now, and will switch to a different storage backend in near future. things will surely be broken at this state; i'm splitting work on different commits.
-rw-r--r--src/leap/base/config.py81
-rw-r--r--src/leap/base/configuration.py11
-rw-r--r--src/leap/base/connection.py4
3 files changed, 83 insertions, 13 deletions
diff --git a/src/leap/base/config.py b/src/leap/base/config.py
new file mode 100644
index 0000000..ccbf3c8
--- /dev/null
+++ b/src/leap/base/config.py
@@ -0,0 +1,81 @@
+"""
+Configuration Base Class
+"""
+import configuration # python configuration module, not local!
+import os
+
+from leap.eip import config as eip_config
+
+
+class BaseLeapConfig(object):
+ slug = None
+
+ # XXX we have to enforce that we have a slug (via interface)
+ # get property getter that raises NI..
+
+ def save(self):
+ raise NotImplementedError("abstract base class")
+
+ def load(self):
+ raise NotImplementedError("abstract base class")
+
+ def get_config(self, *kwargs):
+ raise NotImplementedError("abstract base class")
+
+ #XXX todo: enable this property after
+ #fixing name clash with "config" in use at
+ #vpnconnection
+
+ #@property
+ #def config(self):
+ #return self.get_config()
+
+ def get_value(self, *kwargs):
+ raise NotImplementedError("abstract base class")
+
+
+class JSONLeapConfig(BaseLeapConfig):
+
+ def __init__(self, *args, **kwargs):
+ # sanity check
+ assert self.slug is not None
+ assert self.spec is not None
+ assert issubclass(self.spec, configuration.Configuration)
+
+ self._config = self.spec()
+ self._config.parse_args(list(args))
+
+ # mandatory baseconfig interface
+
+ def save(self, to=None):
+ if to is None:
+ to = self.filename
+ self._config.serialize(to)
+
+ def load(self, fromfile=None):
+ # load should get a much more generic
+ # argument. it could be, f.i., from_uri,
+ # and call to Fetcher
+
+ if fromfile is None:
+ fromfile = self.filename
+ self._config.deserialize(fromfile)
+
+ def get_config(self):
+ return self._config.config
+
+ # public methods
+
+ def get_filename(self):
+ return self._slug_to_filename()
+
+ @property
+ def filename(self):
+ return self.get_filename()
+
+ def _slug_to_filename(self):
+ # is this going to work in winland if slug is "foo/bar" ?
+ folder, filename = os.path.split(self.slug)
+ # XXX fix import
+ config_file = eip_config.get_config_file(filename, folder)
+ return config_file
diff --git a/src/leap/base/configuration.py b/src/leap/base/configuration.py
deleted file mode 100644
index 243e2e2..0000000
--- a/src/leap/base/configuration.py
+++ /dev/null
@@ -1,11 +0,0 @@
-"""
-Configuration Base Class
-"""
-
-
-class Configuration(object):
- """
- I have no idea how configuration
- (txt vs. sqlite) will be done, but let's stub it now.
- """
- pass
diff --git a/src/leap/base/connection.py b/src/leap/base/connection.py
index 8cd7843..9cdc33f 100644
--- a/src/leap/base/connection.py
+++ b/src/leap/base/connection.py
@@ -5,13 +5,13 @@ from __future__ import (division, unicode_literals, print_function)
import logging
-from leap.base.configuration import Configuration
+from leap.base.config import JSONLeapConfig
from leap.base.authentication import Authentication
logger = logging.getLogger(name=__name__)
-class Connection(Configuration, Authentication):
+class Connection(JSONLeapConfig, Authentication):
def __init__(self, *args, **kwargs):
self.connection_state = None
self.desired_connection_state = None