On Tue, 2008-05-20 at 10:00 -0700, Adam Williamson wrote: > On Tue, 2008-05-20 at 12:38 +0100, Dr J A Gow wrote: > > > I would be happy to take the approach of scanning /etc, then ~/.synce, > > and if unset use the app defaults. > > > > Alternatively, packagers could put the template file in somewhere > > sensible, such as /usr/share/synce/examples or similar, where it could > > be found by users who want to customize their configuration. > > I think it's actually fine to install a copy (as discussed earlier, with > all values commented out) to ~/.synce/config.xml when first running > synce - as we all understand it's purely to hint to the user that they > can indeed use a file in that location to change sync-engine's > configuration. > > The usual behaviour is that an application creates the per-user config > file when you first make a change to the configuration within the app > itself, but this doesn't apply to sync-engine, as you can't change any > of the settings in the config file from 'within' the app. > > So given that, having it created on first run is sensible enough, and > probably better than expecting people to learn from documentation, or > guess, that they can copy the system-wide file there and edit it. The > thing I was really objecting to initially in the this thread was never > the creation of the file per se, but the fact that it had values > explicitly set by default. >
See your point, not sure what's best really. The main thing I don't like is that we copy it there with no way to update it for new options, or anything else, whereas other apps that write a config do have this capability. > BTW, for what it's worth, I currently patch sync-engine in Mandriva to > install the template config file to > self.sepath,"SyncEngine/config/config.xml" rather than > self.path,"config.xml" . John, I'm attaching a patch for you. I would've committed it myself but I'm still not that familiar with most of sync-engine, so thought it best that you had a look. 1) installs config.xml into sys.prefix/share/doc/sync-engine 2) doesn't copy the file 3) Reads the system config file first, which is expected to be in /etc if sys.prefix is /usr, or sys.prefix/etc otherwise, then reads the user file Works ok for me. I did think we should probably change the name of config.xml if it's going in /etc. Could go in a subdirectory but that seems excessive, how about synceng-conf.xml ? Mark
diff -Nur sync-engine-0.11.1.svn20080519.orig/setup.py sync-engine-0.11.1.svn20080519/setup.py --- sync-engine-0.11.1.svn20080519.orig/setup.py 2008-04-13 17:52:46.000000000 +0100 +++ sync-engine-0.11.1.svn20080519/setup.py 2008-05-21 10:44:19.000000000 +0100 @@ -16,5 +16,6 @@ package_data = { '': ['*.xsl'], }, + data_files=[('share/doc/sync-engine', ['config/config.xml'])] ) diff -Nur sync-engine-0.11.1.svn20080519.orig/SyncEngine/config.py sync-engine-0.11.1.svn20080519/SyncEngine/config.py --- sync-engine-0.11.1.svn20080519.orig/SyncEngine/config.py 2008-05-16 22:53:34.000000000 +0100 +++ sync-engine-0.11.1.svn20080519/SyncEngine/config.py 2008-05-21 10:51:24.000000000 +0100 @@ -22,6 +22,7 @@ import cPickle as pickle import os import os.path +import sys import getopt import string import logging @@ -283,16 +284,14 @@ # check if we have a config - self.config_dir = os.path.join(os.path.expanduser("~"), ".synce") - self.config_path = os.path.join(self.config_dir, "config.xml") - - if not os.path.exists(self.config_path): - if not os.path.isdir(self.config_dir): - os.mkdir(self.config_dir) - oldconf = os.path.join(self.sepath,"config/config.xml") - shutil.copy(oldconf, self.config_path) + self.config_user_dir = os.path.join(os.path.expanduser("~"), ".synce") + self.config_user_path = os.path.join(self.config_user_dir, "config.xml") + + if sys.prefix == "/usr": + self.config_system_path = os.path.join("/etc", "config.xml") + else: + self.config_system_path = os.path.join(sys.prefix, "etc", "config.xml") - self.logfile = None self.runonce = False @@ -311,7 +310,7 @@ if opt in ("-o","--once"): self.runonce = True if opt in ("-c","--config"): - self.config_dir = os.path.join(arg,".synce") + self.config_user_dir = os.path.join(arg,".synce") if opt in ("-d","--detached"): self.fork = True if opt in ("-l","--logfile"): @@ -328,21 +327,55 @@ # at the start of each connectiomn def UpdateConfig(self): - + self._UpdateSystemConfig() + self._UpdateUserConfig() + + def _UpdateSystemConfig(self): try: - f = open(self.config_path, "rb") + f = open(self.config_system_path, "rb") except: - self.logger.info("UpdateConfig - unable to open config file - using defaults") + self.logger.info("UpdateConfig - unable to open system config file - using defaults") return False try: cf = f.read() f.close() except: - self.logger.info("UpdateConfig - could not read config file - using defaults") + self.logger.info("UpdateConfig - could not read system config file - using defaults") + return False + + try: + confdoc = libxml2.parseDoc(cf) + except libxml2.parserError: + self.logger.info("UpdateConfig - error parsing system config file - using defaults") return False + + config = xml2util.FindChildNode(confdoc,"syncengine-config") + if config is not None: + self._ReadConfElements(config,"FileSync",self.config_FileSync) + self._ReadConfElements(config,"Autosync",self.config_AutoSync) + self._ReadConfElements(config,"Global",self.config_Global) + + return True - confdoc = libxml2.parseDoc(cf) + def _UpdateUserConfig(self): + try: + f = open(self.config_user_path, "rb") + except: + self.logger.info("UpdateConfig - unable to open user config file - using defaults") + return False + try: + cf = f.read() + f.close() + except: + self.logger.info("UpdateConfig - could not read user config file - using defaults") + return False + try: + confdoc = libxml2.parseDoc(cf) + except libxml2.parserError: + self.logger.info("UpdateConfig - error parsing user config file - using defaults") + return False + config = xml2util.FindChildNode(confdoc,"syncengine-config") if config is not None: self._ReadConfElements(config,"FileSync",self.config_FileSync) diff -Nur sync-engine-0.11.1.svn20080519.orig/SyncEngine/pshipmgr.py sync-engine-0.11.1.svn20080519/SyncEngine/pshipmgr.py --- sync-engine-0.11.1.svn20080519.orig/SyncEngine/pshipmgr.py 2008-03-29 19:16:24.000000000 +0000 +++ sync-engine-0.11.1.svn20080519/SyncEngine/pshipmgr.py 2008-05-21 10:44:19.000000000 +0100 @@ -225,7 +225,7 @@ self.logger.info("GetHostBindings: reading existing host bindings") - psdir = os.path.join(self.engine.config.config_dir,"partnerships") + psdir = os.path.join(self.engine.config.config_user_dir,"partnerships") bindings = [] # get all items in the dir. @@ -274,7 +274,7 @@ # we need to load the config entries for a partnership from its # bindings - psdir = os.path.join(self.engine.config.config_dir,"partnerships") + psdir = os.path.join(self.engine.config.config_user_dir,"partnerships") pspath = os.path.join(psdir,"PS" + "-" + str(id) + "-" + str(guid)) s = "" @@ -310,7 +310,7 @@ # we need to load the config entries for a partnership from its # bindings - psdir = os.path.join(self.engine.config.config_dir,"partnerships") + psdir = os.path.join(self.engine.config.config_user_dir,"partnerships") pspath = os.path.join(psdir,"PS" + "-" + str(id) + "-" + str(guid)) if os.path.isdir(pspath): @@ -661,7 +661,7 @@ self.devicesyncitems = [] # formerly sync_items self.deviceitemdbs = {} # item databases - self.psdir = os.path.join(config.config_dir,"partnerships") + self.psdir = os.path.join(config.config_user_dir,"partnerships") self.pshippath = os.path.join(self.psdir, "PS" + "-" + str(self.info.id) + "-" + str(self.info.guid)) self.configpath = os.path.join(self.pshippath, "psconfig.xml") self.infopath = os.path.join(self.pshippath, "psinfo.dat") diff -Nur sync-engine-0.11.1.svn20080519.orig/SyncEngine/rrasyncmanager.py sync-engine-0.11.1.svn20080519/SyncEngine/rrasyncmanager.py --- sync-engine-0.11.1.svn20080519.orig/SyncEngine/rrasyncmanager.py 2008-04-01 11:53:25.000000000 +0100 +++ sync-engine-0.11.1.svn20080519/SyncEngine/rrasyncmanager.py 2008-05-21 10:44:19.000000000 +0100 @@ -375,7 +375,7 @@ path = os.path.join(os.path.expanduser(self.CfgItem.cfg["BaseFilePath"]), os.path.expanduser(pship.QueryConfig("/syncpartner-config/General/LocalFilePath[position() = 1]","0"))) - self.fdb = FileDB(thread.config.config_dir,\ + self.fdb = FileDB(thread.config.config_user_dir,\ path,\ pship,\ self.CfgItem.cfg["ExtraDeleteDelay"]) @@ -1129,4 +1129,4 @@ del self.thread self.thread = None - \ No newline at end of file +
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ SynCE-Devel mailing list SynCE-Devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/synce-devel