summaryrefslogtreecommitdiff
path: root/src/leap/util/config.py
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2013-01-28 18:18:22 +0000
committerIsis Lovecruft <isis@torproject.org>2013-01-28 18:18:22 +0000
commit1bed2439923405998725abbfc4527433822bcf0e (patch)
treea1f6d5e95e4649c9e786397a15d83810d8383795 /src/leap/util/config.py
parente9133ed025208f57e33bddf7b1873d8f9ddf980b (diff)
Need to switch the config to JSON following leap_client.
Diffstat (limited to 'src/leap/util/config.py')
-rw-r--r--src/leap/util/config.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/leap/util/config.py b/src/leap/util/config.py
new file mode 100644
index 0000000..ab91a60
--- /dev/null
+++ b/src/leap/util/config.py
@@ -0,0 +1,69 @@
+#! -*- encoding: utf-8 -*-
+"""
+xxx fill me in
+"""
+import os
+import yaml
+
+from leap.util import log, version
+
+config_filename = 'mx.conf'
+
+class MissingConfig(Exception):
+ """Raised when the config file cannot be found."""
+ def __init__(self, message=None, config_file=None):
+ if message:
+ return
+ else:
+ self.message = "Cannot locate config file"
+ if config_file:
+ self.message += " %s" % config_file
+ self.message += "."
+
+def getConfigFilename(dir=None, file=None):
+ """
+ xxx fill me in
+ """
+ if not dir:
+ dir = version.getRepoDir()
+ if not file:
+ file = config_filename
+ return os.path.join(dir, file)
+
+def createConfigFile(config_file=None):
+ """
+ xxx fill me in
+ """
+ if not config_file:
+ config_file = getConfigFilename()
+
+ if not os.path.isfile(config_file):
+ with open(config_file, 'w+') as conf:
+ conf.write("""
+#
+# mx.conf
+# =======
+# Configurable options for the leap_mx encrypting mail exchange.
+#
+""")
+ conf.flush()
+ else:
+ log.debug("Config file %s already present." % config_file)
+
+def loadConfigFile(config_file=None):
+ """
+ xxx fill me in
+ """
+ if not config_file:
+ config_file = getConfigFilename()
+
+ if os.path.isfile(config_file):
+ with open(config_file, 'a+') as conf:
+ config_contents = '\n'.join(conf.readlines())
+ configuration = yaml.safe_load(config_contents)
+ else:
+ createConfigFile(config_file)
+
+ ## xxx finish load config
+ ## ask kali if we're using yaml or json or what?
+ ## xxx kali says json, so ixnay on the amlya bits