From 5962b3398ab9f472776e2418f00163125d1c4cc2 Mon Sep 17 00:00:00 2001
From: Giorgos Korfiatis <gkorf@grnet.gr>
Date: Thu, 22 Oct 2015 16:57:00 +0300
Subject: [PATCH] Read default settings from resources/defaults.conf

---
 agkyra.spec                    |  1 +
 agkyra/config.py               | 42 +++++++++++++++-------------------
 agkyra/resources/defaults.conf | 24 +++++++++++++++++++
 3 files changed, 44 insertions(+), 23 deletions(-)
 create mode 100644 agkyra/resources/defaults.conf

diff --git a/agkyra.spec b/agkyra.spec
index 0380c92..bfe8bf4 100644
--- a/agkyra.spec
+++ b/agkyra.spec
@@ -41,6 +41,7 @@ a.datas += extra_datas(os.path.join(HERE, 'agkyra'), os.path.join('resources', '
 a.datas += extra_datas(os.path.join(HERE, 'agkyra'), os.path.join('resources', 'nwgui'))
 a.datas += extra_datas(os.path.join(HERE, 'agkyra'), os.path.join('resources', 'ui_data'))
 a.datas += extra_datas(os.path.join(HERE, 'agkyra'), os.path.join('resources', 'cacert.pem'))
+a.datas += extra_datas(os.path.join(HERE, 'agkyra'), os.path.join('resources', 'defaults.conf'))
 
 pyz = PYZ(a.pure)
 exe = EXE(pyz,
diff --git a/agkyra/config.py b/agkyra/config.py
index 0756e0a..bdd0521 100644
--- a/agkyra/config.py
+++ b/agkyra/config.py
@@ -28,6 +28,8 @@ The operations of a sync are similar to the operations of a cloud, as they are
 implemented in kamaki.cli.config
 """
 import os
+import sys
+import imp
 import stat
 from re import match
 from ConfigParser import Error
@@ -57,30 +59,24 @@ config.CONFIG_PATH = CONFIG_PATH
 config.CONFIG_ENV = ''
 
 SYNC_PREFIX = 'sync'
+
+if getattr(sys, 'frozen', False):
+    # we are running in a |PyInstaller| bundle
+    BASEDIR = sys._MEIPASS
+else:
+    # we are running in a normal Python environment
+    BASEDIR = os.path.dirname(os.path.realpath(__file__))
+
+RESOURCES = os.path.join(BASEDIR, 'resources')
+defaults_file = os.path.join(RESOURCES, 'defaults.conf')
+imp.load_source('default_settings', defaults_file)
+from default_settings import DEFAULT_GLOBAL, DEFAULT_CLOUDS, DEFAULT_SYNCS
+DEFAULT_GLOBAL['agkyra_dir'] = AGKYRA_DIR
+
 config.DEFAULTS = {
-    'global': {
-        'agkyra_dir': AGKYRA_DIR,
-        'sync_on_start': 'on',
-        'language': 'en'
-    },
-    CLOUD_PREFIX: {
-        # <cloud>: {
-        #     'url': '',
-        #     'token': '',
-        #     'ignore_ssl': True or False overwrites ca_certs,
-        #     'ca_certs': /path/to/ca/certificate/buddle
-        #     whatever else may be useful in this context
-        # },
-        # ... more clouds
-    },
-    SYNC_PREFIX: {
-        # <sync>: {
-        #     'cloud': '',
-        #     'container': '',
-        #     'directory': ''
-        # },
-        # ... more syncs
-    },
+    'global': DEFAULT_GLOBAL,
+    CLOUD_PREFIX: DEFAULT_CLOUDS,
+    SYNC_PREFIX: DEFAULT_SYNCS,
 }
 
 
diff --git a/agkyra/resources/defaults.conf b/agkyra/resources/defaults.conf
new file mode 100644
index 0000000..bd03ddf
--- /dev/null
+++ b/agkyra/resources/defaults.conf
@@ -0,0 +1,24 @@
+DEFAULT_GLOBAL = {
+    "sync_on_start": "on",
+    "language": "en"
+}
+
+DEFAULT_CLOUDS = {
+    # <cloud>: {
+    #     "url": "",
+    #     "token": "",
+    #     "ignore_ssl": True or False overwrites ca_certs,
+    #     "ca_certs": /path/to/ca/certificate/buddle
+    #     whatever else may be useful in this context
+    # },
+    # ... more clouds
+}
+
+DEFAULT_SYNCS = {
+    # <sync>: {
+    #     "cloud": "",
+    #     "container": "",
+    #     "directory": ""
+    # },
+    # ... more syncs
+}
-- 
GitLab