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

M

metaperl

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...4e9c?lnk=gst&q=curry&rnum=10#c31e388ff0bb4e9c

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.
 
M

Marc 'BlackJack' Rintsch

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
 
V

Vinay Sajip

metaperl said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top