summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Boddie <paul@boddie.org.uk>2014-08-07 12:19:01 (GMT)
committerPaul Boddie <paul@boddie.org.uk>2014-08-07 12:19:01 (GMT)
commit12917f5ee82369cd21da413aa921fceade898050 (patch)
tree2a79cdffd45fbf962c8e3e53aa25ccbd81dbce49
parent020bf7c1a510201532655c54099d5f08fde72f68 (diff)
downloadpykolab-12917f5ee82369cd21da413aa921fceade898050.tar.gz
Tidied up the freebusy setup.
-rw-r--r--pykolab/setup/setup_freebusy.py60
1 files changed, 43 insertions, 17 deletions
diff --git a/pykolab/setup/setup_freebusy.py b/pykolab/setup/setup_freebusy.py
index 9496651..5096f65 100644
--- a/pykolab/setup/setup_freebusy.py
+++ b/pykolab/setup/setup_freebusy.py
@@ -18,9 +18,8 @@
#
from ConfigParser import RawConfigParser
-import os
-import sys
-import time
+from os.path import join, isfile
+from shutil import copy
from urlparse import urlparse
import components
@@ -46,12 +45,23 @@ def description():
return _("Setup Free/Busy.")
def execute(*args, **kw):
- if not os.path.isfile('/etc/kolab-freebusy/config.ini') and not os.path.isfile('/etc/kolab-freebusy/config.ini.sample'):
- log.error(_("Free/Busy is not installed on this system"))
+
+ prefix = "/etc/kolab-freebusy"
+ config = join(prefix, "config.ini")
+ sample = join(prefix, "config.ini.sample")
+
+ if not isfile(config) and not isfile(sample):
+ if conf.check_only:
+ utils.setup_status("freebusy", _("not installed"))
+ else:
+ log.error(_("Free/Busy is not installed on this system"))
return
- if not os.path.isfile('/etc/kolab-freebusy/config.ini'):
- os.rename('/etc/kolab-freebusy/config.ini.sample', '/etc/kolab-freebusy/config.ini')
+ if not isfile(config):
+ if conf.check_only:
+ utils.setup_status("freebusy", _("needs setup"))
+ return
+ copy(sample, config)
imap_backend = conf.get('kolab', 'imap_backend')
admin_login = conf.get(imap_backend, 'admin_login')
@@ -112,20 +122,36 @@ def execute(*args, **kw):
}
cfg_parser = RawConfigParser()
- cfg_parser.read('/etc/kolab-freebusy/config.ini')
+ cfg_parser.read(config)
- for section in freebusy_settings.keys():
- if len(freebusy_settings[section].keys()) < 1:
+ will_update = False
+
+ for section, definitions in freebusy_settings:
+ if not definitions:
cfg_parser.remove_section(section)
continue
- for key in freebusy_settings[section].keys():
- if not cfg_parser.has_section(section):
- cfg_parser.add_section(section)
+ if not cfg_parser.has_section(section):
+ cfg_parser.add_section(section)
+
+ for key, value in definitions.items():
+ current = cfg_parser.get(section, key)
- cfg_parser.set(section, key, freebusy_settings[section][key])
+ # ConfigParser does not handle quoting for certain consumers of
+ # .ini files like PHP's parse_ini_file.
+ # See also: https://bugs.php.net/bug.php?id=36045
- fp = open('/etc/kolab-freebusy/config.ini', "w+")
- cfg_parser.write(fp)
- fp.close()
+ value = "=" in value and ('"%s"' % value) or value
+
+ if current != value:
+ cfg_parser.set(section, key, value)
+ will_update = True
+
+ if conf.check_only:
+ utils.setup_status("freebusy", will_update and _("needs setup") or _("setup done"))
+ return
+ if will_update:
+ fp = open(config, "w+")
+ cfg_parser.write(fp)
+ fp.close()