473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

help with designing an app. based on ConfigParser

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:pa**@server10.com/remote/dir
server20 = ftp://user:pa**@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

Apr 6 '06 #1
1 1361

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


Apr 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Greg Krohn | last post by:
I'm trying to subclass ConfigParser so I can use a custom __read method (the custom format doesn't conform to RFC 822) when needed. Needless to say, it's not working as expected. In the...
2
by: Roy H. Berger | last post by:
If I want to subclass ConfigParser and changed the optionxform method to not return things in lower case wouldn't I just need the following code in my subclasss module? from ConfigParser import...
3
by: Stephen Boulet | last post by:
I'm having a bit of trouble getting my head around the ConfigParser module. I have a very simple configuration file; maybe the easiest thing to do would be to show that: ============ # Add a...
11
by: Manlio Perillo | last post by:
Regards. Since sections in CongiParser files are delimited by , why there is not an escape (and unescape) function for escaping &, characters to &, [ and ] ? Thanks ...
2
by: rzed | last post by:
I am working with PythonCard in one of my apps. For its purposes, it uses an .ini file that is passed to ConfigParser. For my app, I also need configuration information, but for various reasons,...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
10
by: Terry Carroll | last post by:
It looks like ConfigParser will accept a list to be writing to the *.ini file; but when reading it back in, it treats it as a string. Example: ############################### import...
5
by: mwt | last post by:
Hi - I'm having a little trouble using exceptions properly. I currently have an initialization function on a little app that looks like this: def __init__(self, config_file): self.fahdata =...
1
by: pipehappy | last post by:
Hello everyone: I came across the module ConfigParser and can use it correctly. import ConfigParser fp = open('test.cfg','w+') config = ConfigParser.ConfigParser() config.readfp(fp)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.