473,396 Members | 2,013 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,396 software developers and data experts.

inheritance needed in program configuration - config module or python oo?



Inheritance needed in app configuration
=============================

I have an ftp server that a number of vendors connect into to upload a
file to their directory. In OO terms, we would have

class OurFTP:
server = "ftpserver.com"

class Vendor1(OurFTP)
user, pass, directory = ("blah","blah","blah")

etc, etc

And thus when I write a Python script to go check their uploads, I need
to create a VendorN object and use the user, pass and directory from
VendorN but use the server attribute from the parent class

Now in pure OO, this is a piece of cake. However, I thought I would use
ConfigObj to configure my app because it is clean and widely used and
the authors are active people. But I don't know how to get a local
config to inherit global values.

In other words, I have a file called global.ini with the server address
in it and then each vendor has a file called local.ini with their user,
pass, directory info.

And I need to form an FTP connection URL based on this. But I really
dont want to write my code such that I explicitly hardcode where the
ftpserver is coming from. Again, in pure OO it is very simple to call a
method and have it dispatch to either the current object or it's
parent, but I am not sure that ConfigObj or any config module allows
such power.

I am starting to think that I better just do my configuration
information in Python classes to get the genericity that I want.

Program Code
===========

Just in case you want to see what I'm doing, here's the relevant
section of code:

config = ConfigObj("local.ini")
gconfig = ConfigObj("../generic.ini")
"""Curry function by Bruno Desthuilliers
http://groups.google.com/group/comp....1e388ff0bb4e9c

curry() will be part of py2.5
"""

def curry(fun, *args):
def _curried(*moreargs):
return fun(*(args + moreargs))
_curried.func_name = "curried(%s) of %r" % (", ".join(args), fun)
return _curried

def getkey(k1,k2):
return config[k1][k2]

#
--------------------------------------------------------------------------
# Fetch DMS file from KE FTP
#
--------------------------------------------------------------------------
ftp_cfg_keys = "filepattern user pass cwd".split()
ftp_lambda = curry(getkey, 'ftp_in')
ftp_cmd_vals = map(ftp_lambda, ftp_cfg_keys)
print ftp_cmd_vals
# the !!! should be filled in with the globally configured FTP server
# but I refuse to play telepathic guru and point to the source directly
# if I have to write this over and use pure Python OO instead of a
# config module then so be it
ftp_cmd = "mget %s | ftp -i ftp://%s:%s@!!!!/%s" % tuple(ftp_cmd_vals)
print ftp_cmd
os.system(ftp_cmd)
sys.exit()
Aside
====

When it comes to HTML generation, every form of mini-language that I've
seen does not appeal to me. I use DOM to rewrite HTML. I hate the
limitations of mini-languages and prefer full-strength programming
languages. Now it is appearing that application configuration is yet
one more place to avoid mini-language convenience and simply use a
programming language for the task.

Sep 2 '06 #1
2 1759
In <11**********************@74g2000cwt.googlegroups. com>, metaperl wrote:
And I need to form an FTP connection URL based on this. But I really
dont want to write my code such that I explicitly hardcode where the
ftpserver is coming from. Again, in pure OO it is very simple to call a
method and have it dispatch to either the current object or it's
parent, but I am not sure that ConfigObj or any config module allows
such power.
What about simply merging the two `ConfigObj` instances with the `merge()`
method?

Ciao,
Marc 'BlackJack' Rintsch
Sep 2 '06 #2
metaperl wrote:
Inheritance needed in app configuration
=============================
[snip]
When it comes to HTML generation, every form of mini-language that I've
seen does not appeal to me. I use DOM to rewrite HTML. I hate the
limitations of mini-languages and prefer full-strength programming
languages. Now it is appearing that application configuration is yet
one more place to avoid mini-language convenience and simply use a
programming language for the task.
You could try my hierarchical config module:

http://www.red-dove.com/python_config.html

which is intended for configuring hierarchies of application
components.

Best regards,

Vinay Sajip

Sep 5 '06 #3

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

Similar topics

8
by: Dan Perl | last post by:
Here is a problem I am having trouble with and I hope someone in this group will suggest a solution. First, some code that works. 3 classes that are derived from each other (A->B->C), each one...
2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
5
by: Aaron | last post by:
Hi, I'm interested in creating a large number of configuration files which I have no experience doing in python. The fields will be static for the most part. But design changes and I might want...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
33
by: Joe Fallon | last post by:
1. I have a Base class that has a certain amount of functionality. 2. Then I have a CodeSmith generated class that inherits from the Base class and adds functionality. 3. Since I want to be able...
9
by: gerry | last post by:
Is there any way to prevent web.config inheritance in nested web applications ? Here is the scenario, a 3rd party asp.net web application installed on an asp.net intranet site :...
0
by: nejucomo | last post by:
Hi folks, Quick Synopsis: A test script demonstrates a memory leak when I use pythonic extensions of my builtin types, but if I use the builtin types themselves there is no memory leak. ...
5
by: jvdb | last post by:
Hi there, I am quite new on python programming and need some help on solving my problem.. I have to make a (python) program which deletes files from directories. I don't think deleting, etc....
0
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I have a web.config custom configuration section using asp.net 2.0 configuration APIs. My custom configuration section inherits from System.Configuration.ConfigurationSection. I have a IIS root...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...

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.