473,800 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.startsw ith("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 1384

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
2626
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 following code, I bind __read_ini to __read and override __read so it can choose between __read_ini and __read_custom. But it seems that __read_custom never gets called when I expect it to aways be called. I have a feeling this has to do with me not...
2
4305
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 * class MyConfigParser(ConfigParser): def __init__(self, defaults=None): ConfigParser.__init__(self, defaults)
3
616
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 local directory to be backed up followed # by the directory name on the FTP server. # # Example: /home/joe/digital photos = photos
11
4908
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 Manlio Perillo
2
1704
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, I'd rather use a syntax that ConfigParser can't handle. I know I can maintain two separate configuration files, and if I have to I will, but I'd rather avoid that, if possible, and a solution that suits my purposes is quite straightforward. I...
2
3901
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 http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it is a server problem but was told it is not possible, therefore assuming it is a client script problem? the script works last time...
10
11878
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 ConfigParser def whatzit(thingname, thing): print thingname, "value:", thing print thingname, "length:", len(thing)
5
6308
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 = fahdata.FAHData() self.INI = ConfigParser.ConfigParser() if os.path.exists(config_file): try: self.INI.read(config_file)
1
2020
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) config.add_section('test') config.set('test', 'haha', 'hehe')
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10276
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10035
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.