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.
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?
On 8/23/05, Richard Smith smithbone@gmail.com wrote:
This patch against r70 that adds the ability to override the names of the default system and user config files.
Oh and I realize that since you are in 'pre' status that you may not want to mess with this until after the 2.3.0 release. That's fine since I still need to rework a few more things before I'm ready for the multiple ui patch.
Are you going to create a 2.3.x branch?
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()
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
I'm not so sure that blocking waiting for input is a good idea. What about when the user starts it from a gui shortcut with IO thats been redirected somewhere. It would then appear to hang.
I just removed trailing whitespaces, I hope this didn't create too much problems for you.
Ah thats probally why I couldn't see anything. I'll try to clean future patches.
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.
I expected that. I'm in no rush.
| 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.
My goal here was to change as little as possible of what you had yet allow for using a config file that is names differently. But I can re-factor a bit if you like. You are suggesting refactoring to remove the Global?
+def processconfig(defconfigfile = "/etc/pytonerc"):
| I would call this siteconfigfile
I was trying to keep it obvious that is was a default for the configfile option. But sure thats fine.