Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > help with designing an app. based on ConfigParser

Reply
Thread Tools

help with designing an app. based on ConfigParser

 
 
Alexandre CONRAD
Guest
Posts: n/a
 
      04-06-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(E-Mail Removed)/remote/dir
server20 = ftp://user(E-Mail Removed)/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

 
Reply With Quote
 
 
 
 
Fuzzyman
Guest
Posts: n/a
 
      04-06-2006

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


> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ConfigParser: Can I read(ConfigParser.get()) a configuration file anduse it to call a funciton? jamitwidme@gmail.com Python 3 06-26-2008 08:01 PM
Help with ConfigParser tony.ha@philips.com Python 3 10-02-2006 02:53 PM
Little Help with Exceptions and ConfigParser mwt Python 5 03-15-2006 12:54 PM
ConfigParser Alternative (a request to help you) Dan Gass Python 0 09-13-2004 06:12 AM
Help with ConfigParser Stephen Boulet Python 3 05-02-2004 12:22 PM



Advertisments