help with designing an app. based on ConfigParser

Alexandre CONRAD aconrad.tlv at magic.fr
Thu Apr 6 08:41:46 EDT 2006


Hello list !

I'm using the ConfigParser module to use configuration files (what else 
would it be for ?). But I have a dilema: I'd like to setup multiple 
"update server" for my application with update "priority".

At first, I thought about adding a new section in my actual existing 
config file such as:

   [UPDATE SERVERS]

and have options like that:

   server10 = ftp://user:pass@server10.com/remote/dir
   server20 = ftp://user:pass@server20.com/remote/dir

That way, I would simply parse all servers in the "UPDATE SERVERS" 
section and sort them so I could get the priority (lowest number is 
higgest prio).

But, with this option, I don't know how to download files to a specific 
local directory. Then I thought about adding some "local10", "local20" 
options that would have the same number as the server, but ... baah, it 
starts beeing a pain when you want to maintain and update the server 
list. Also I would like to set multiple kind of update servers, like 
http, rsync, having to parse split up the URL is also a pain.

So instead of having all the data in a URL and having to parse it, I 
thought I might specify an option for each params and then build the 
needed URL. Like

   proto = ftp
   ip = 0.0.0.0
   port = 21
   remote_dir = /remote/dir

And I could add extra info that would make my life simplier that I 
couldn't have in the URL:

   enable = True
   priority = 15
   local_dir = /local/dir
   args = ""

That way, if I need to do an rsync, I can look for specific rsync 
options if available.

But now, how do I hold multiple servers ? In this case, I thought about 
having multiple sections such as

   [SERVER 01]
   [SERVER 02]
   [SERVER 03]

But it's not very efficient when I want to parse the WHOLE config file 
to find which servers are available and retrive their options. (plus, 
"01", "02", "03" would be useless, just for anti-conflict section naming)

if section.startswith("SERVER"):
     ...

So I told my self, the best way would be able to have a "sub-section". I 
could then look for all servers (aka sub-sections) inside [UPDATE 
SERVERS] and retrieve the needed info. But AFAIK, it's not possible 
having sub-sections with ConfigParser. So I'm here to ask if anyone has 
an efficient trick for that ? Maybe an other module based on 
ConfigParser exists that would allow sub-sections ?

I might be looking for something too complicated and maybe some simplier 
alternative exists which doesn't cross my mind right now. (no, don't 
tell me to use XML for my config file, it has to be easely modifiable by 
the user using the most basic bloc-note).

Regards,
-- 
Alexandre CONRAD - TLV
Research & Development
tel : +33 1 30 80 55 05
fax : +33 1 30 80 55 06
6, rue de la plaine
78860 - SAINT NOM LA BRETECHE
FRANCE




More information about the Python-list mailing list