help with designing an app. based on ConfigParser

  • Thread starter Alexandre CONRAD
  • Start date
A

Alexandre CONRAD

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:p[email protected]/remote/dir
server20 = ftp://user:p[email protected]/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
 
F

Fuzzyman

Alexandre CONRAD wrote:
[snip..]
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 ?

ConfigObj allows sub-sections and is also easier to use than
ConfigParser. That says nothing about whether sub-sections are the
right answer to your problem, but at least it is possible. :)

http://www.voidspace.org.uk/python/configobj.html

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top