managing properties/configurations

V

Venkatraman.S.

Hi,

Am sure many would have stumbled on this situation while developing an
application in Python which is highly driven by configuration/
properties.

I have an application (obviously written in Python) wherein the
properties change frequently and the program needs to work according
to the new rules. Since , python is scripting language the idea of a
Properties file(analogous to Java) doesnt make sense to me. However,
at the same time i am looking for some mechanism by which the hot-
patches(i.e, properties can be changed) can be applied easily.

Since the patches(mostly properties change) will be mostly be done by
non-programmers, i do not want them to touch the Py codes,but at the
same time alter the behaviour suitably.(Kindly avoid the advice to
teach Python to the non-programmers :D ).

The following is a *very simple example* of the case wherein the
properties(namely 10,30,31,40) are 'hardcoded' - i want this to be
'away' from the code.

def checkCutoff(self,up,down):
.............do some processing........
if (10 <= score <= 30):
result="Bad"
elif (31 <= score <= 40):
result="Good"
.............do some processing........
return result

If i have to have this as a separate script that stores all the
properties, then how do I make the program fetch the new values
without restarting.

Also, i would be interested in providing a GUI for manging the
properties so that the changes can be applied even more easily - but
at any time i do not want to bring down the program and then
restart(all are hot patches).

Regards,
Venkat
 
V

Venkatraman.S.

Or a better example would be:

I have the params in a config file and import this module:
myconfig.py
a=10
b=30
c=31
d=40

import myconfig
def checkCutoff(self,up,down):
.............do some processing........
if (a <= score <= b):
result="Bad"
elif (c <= score <= d):
result="Good"
.............do some processing........
return result

Now when i 'manually' make some changes to the value of a,b,c,d then
the the checkCutoff func should refer to the new values.

-Venkat
 
V

Venkatraman.S.

Thanks
By picking better names, the config gets much more readable.

The big advantage here is that a config file is something readable and editable
without appearing it to be Python.
If this is too low level for your users, you can use it as a data exchange
format between the processing application and the frontend application where
users can change the values.

The problem being, if i change the config file, then the configobj has
to reload this file again. I do not want to 'refresh' the config obj
per transaction but only when the config params change.
Maybe reload the file each time you run the program?

The program is never-ending and do not think in terms of websites here
- probably something like a server/middleware which can never be
brought down.

I was thinking along the terms of an Interrupt driven program, which
when getting a custom interrupts reloads the file - any potential
loopholes/falls that anyone can anticipate?

Regards,
Venkat
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top