managing properties/configurations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Venkatraman.S.

    managing properties/configurations

    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.(Kindl y avoid the advice to
    teach Python to the non-programmers :D ).

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

    def checkCutoff(sel f,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
  • Venkatraman.S.

    #2
    Re: managing properties/configurations

    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(sel f,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

    Comment

    • A.T.Hofkamp

      #3
      Re: managing properties/configurations

      On 2008-05-16, Venkatraman.S. <venkat83@gmail .comwrote:
      Or a better example would be:
      Indeed, this is concrete enough to make some suggestions.
      I have the params in a config file and import this module:
      myconfig.py
      a=10
      b=30
      c=31
      d=40
      The big problem imho with coding such stuff directly in Python is that you have
      no way to extract the data from the code to display it to your users without
      exposing them to Python code.

      Why not instead throw this in a ConfigParser file like below, and load the data
      values from it (each time they have changed?)

      [score]
      a=10
      b=30
      c=31
      d=40

      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.
      import myconfig
      def checkCutoff(sel f,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.
      Maybe reload the file each time you run the program?


      Sincerely,
      Albert

      Comment

      • Venkatraman.S.

        #4
        Re: managing properties/configurations

        On May 16, 7:45 am, "A.T.Hofkam p" <h...@se-162.se.wtb.tue. nlwrote:

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

        Comment

        • A.T.Hofkamp

          #5
          Re: managing properties/configurations

          On 2008-05-16, Venkatraman.S. <venkat83@gmail .comwrote:
          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.
          If you have trustable time stamps at your file system, you could check the time
          stamp before loading.
          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?
          Many unix deamons use SIGHUP signal to reload configs.
          Maybe that would be an option?


          Sincerely,
          Albert

          Comment

          Working...