Hi Richard!
On 23.08.05, Richard Smith wrote:
This patch against r70 that adds the ability to override the names of the default system and user config files.
For example dancebox is started with ./dancebox.py rather than ./pytone.py and the config files are /etc/dancebox.conf and ~/.dancebox/*
This is a small step toward my seperate UI modules patch.
It also adds an error message if pytone can't find any of the config files where previously it just told you that you needed at least one basedir statement in the config file.
Ok, that sounds reasonable. Even better would be to ask the user for the basedir (one should check that this is a proper directory) and write a default config file containing
[database.main] dbenvdir = ~/.pytone/main basename = basedir = ...
I always planed to do that...
Joerg:
When I did an svn update I had conflicts with every part of my playspeed mods. But looking at them in (most) cases I couldn't really see any difference. Was there some sort of space or tab issue or something with my patch?
I just removed trailing whitespaces, I hope this didn't create too much problems for you.
Here come some comments (marked by a leading |) on your patch.
Jörg
PS: We should really wait for the inclusion of the separate UI patch until the 2.3.0 version has been released. The following patch could go in though. I'll create a 2.3 branch when the 2.3.0 version has been released.
Index: trunk/src/config.py =================================================================== --- trunk/src/config.py (revision 70) +++ trunk/src/config.py (working copy) @@ -701,11 +701,22 @@ # configparser used for the config files configparser = None
-def setupconfigparser(): +def setupconfigparser(defconfigfile): """ initialize ConfigParser.RawConfigParser for the standard configuration files """ global configparser - cflist = ["/etc/pytonerc", userconfigfile] + cflist = [defconfigfile, userconfigfile] s = ", ".join(map(os.path.realpath, cflist)) +
| trailing white-spaces
+ confexists = False + for each in cflist: + if os.path.exists(each): + confexists = True + break; + if confexists != True: + print "Unable to find a config file. I checked:\n %s" % s + print "Please create one or use the -c option" + sys.exit(2)
log.info("Using configuration from file(s) %s" % s) configparser = ConfigParser.RawConfigParser() configparser.read(cflist) @@ -837,12 +848,17 @@ print "-r, --rebuild: rebuild all databases"
-def processcommandline(): +def processcommandline(defuserconfig = None): # we pass the information on the command line options via # global variables global userconfigfile global forcedatabaserebuild global forcedebugfile +
| trailing white-spaces
+ # Allow the caller to overide the default config if needed + if defuserconfig != None: + userconfigfile = os.path.expanduser(defuserconfig) +
| If you want to pass a default user config file, why don't you | pass it together with the site-wide config file to | the setupconfigparser method.
try: # keep rest of arguments for other use global args @@ -915,8 +931,8 @@ raise RuntimeError("invalid format for alsa option '%s'" % aooption)
-def processconfig(): - setupconfigparser() +def processconfig(defconfigfile = "/etc/pytonerc"):
| I would call this siteconfigfile
+ setupconfigparser(defconfigfile) processstandardconfig() finishconfig() checkoptions()