From 74cc3b79b74d33ab4d91d77e2e2f0ac4dbd097ff Mon Sep 17 00:00:00 2001 From: Jean Raby Date: Mon, 10 Sep 2012 20:43:58 +0000 Subject: [PATCH] Scripts/openchange_cleanup.py: use plistlib to read sogo defaults instead of ugly hack Monotone-Parent: 1fbe308ad552ffa7e4c43a1a33f14a64aacf1f62 Monotone-Revision: 97e02e31cb9e8ce215a0d0d092e79db5cc210a3c Monotone-Author: jraby@inverse.ca Monotone-Date: 2012-09-10T20:43:58 Monotone-Branch: ca.inverse.sogo --- Scripts/openchange_cleanup.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Scripts/openchange_cleanup.py b/Scripts/openchange_cleanup.py index 197f39ae5..40b54d76c 100755 --- a/Scripts/openchange_cleanup.py +++ b/Scripts/openchange_cleanup.py @@ -3,6 +3,7 @@ import getopt import imaplib import ldb +import plistlib import os import re import shutil @@ -13,6 +14,7 @@ imaphost = '127.0.0.1' imapport = 143 sambaprivate = '/var/lib/samba/private' mapistorefolder = "%s/mapistore" % (sambaprivate) +sogoDefaultsFile = "/home/sogo/GNUstep/Defaults/.GNUstepDefaults" # - takes a username and optionally its password # - removes the entry in samba's ldap tree via ldbedit (NOTYET) @@ -182,19 +184,19 @@ def postgresqlCleanup(dbhost, dbport, dbuser, dbpass, dbname, username): print "table '%s' emptied" % tablename def getOCSFolderInfoURL(): - # hack - # this doesn't work in py2.6 ... - #defaultsout = subprocess.check_output(["defaults", "read", "sogod", "OCSFolderInfoURL"]) - defaultsout = subprocess.Popen(["defaults", "read", "sogod", "OCSFolderInfoURL"], stdout=subprocess.PIPE).communicate()[0] + global sogoDefaultsFile + sogoDefaults = plistlib.readPlist(sogoDefaultsFile) + try: + OCSFolderInfoURL = sogoDefaults['sogod']['OCSFolderInfoURL'] + except KeyError: + OCSFolderInfoURL = "" - OCSFolderInfoURL = defaultsout.split()[-1] - return OCSFolderInfoURL + return OCSFolderInfoURL def sqlCleanup(username): - try: - OCSFolderInfoURL = getOCSFolderInfoURL() - except subprocess.CalledProcessError: - "Couldn't fetch OCSFolderInfoURL, the socfs_%s table should be truncated manually" % (username) + OCSFolderInfoURL = getOCSFolderInfoURL() + if (OCSFolderInfoURL is None): + raise Exception("Couldn't fetch OCSFolderInfoURL or it is not set. the socfs_%s table should be truncated manually" % (username)) # postgresql://sogo:sogo@127.0.0.1:5432/sogo/sogo_folder_info m = re.search("(.+)://(.+):(.+)@(.+):(\d+)/(.+)/(.+)", OCSFolderInfoURL)