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

metaperl metaperl at
Sat Sep 2 13:10:28 CEST 2006

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 = ""

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

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


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.

More information about the Python-list mailing list