diff options
-rw-r--r-- | src/leap/util/config.py | 69 |
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 |