help with designing an app. based on ConfigParser

Discussion in 'Python' started by Alexandre CONRAD, Apr 6, 2006.

  1. 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:/remote/dir
    server20 = ftp://user:/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
    Alexandre CONRAD, Apr 6, 2006
    #1
    1. Advertising

  2. Alexandre CONRAD

    Fuzzyman Guest

    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
    Fuzzyman, Apr 6, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Lie

    windows app vs web based app

    Robert Lie, Dec 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    647
    Kevin Spencer
    Dec 20, 2005
  2. TheRookie
    Replies:
    0
    Views:
    410
    TheRookie
    Jan 19, 2004
  3. John
    Replies:
    2
    Views:
    708
    Thomas Weidenfeller
    May 19, 2005
  4. Stephen Boulet

    Help with ConfigParser

    Stephen Boulet, May 2, 2004, in forum: Python
    Replies:
    3
    Views:
    390
    Peter Otten
    May 2, 2004
  5. Replies:
    3
    Views:
    414
Loading...

Share This Page