hconf ist ein kleines Modul zum Erstellen bzw. Verwalten von Konfigurationen, dass ich ursprünglich für einige meiner Projekte entwickelt habe.



hconf is a little module to manage simple configurations I made for myself. Maybe you need this...




Classes:

    Hconf

        + __init__(fieldDefinition, path, serialer=Serialer)

        + existPath()                                                     return True if the path exists

        + load()                                                          Loads the hconf

        + save()                                                          Saves the hconf

        + SET(key, value)                                                 Sets the field -key- to the value -value-

        + GET(key)                                                        Returns the value of the field -key-

        + GET_ALL()                                                       Returns a dict with all fields {key:value}

        (+ invalidVersionFound(myVersion, foundVersion, foundValues)      This function is called if while loading the Hconf a version found with an other version-code (normaly this func. im empty. You have to override in an own class)

                                                                              -myVersion- is the excepted version -foundVersion- is the in the Hconf found version -foundValues- are the vaues found in the Hconf

                                                                              if this function returns True the pöd hconf is converted successfull. You have to save the hconf if you change sth. with self.SET()

    FieldDefinition

        + __init__(version=1)

        + addField(field)                                                 adds a field to the Hconf-FileDefinition

    

    Field

        + __init__(key, default=None, types=[])                           the types-list contains all datatypes this field can have. If there's no entry all types are excepted.

    

    Serial

        + _serial(o)                                                      this function has to be overridden. -o- contains a dict which hs to be 'converted' to a string which has to be returned

        + _unserial(o)                                                    this function has to be overridden. -o- contains a 'converted' string which has to be 'unconverted' to a dict which has to be returned

    

    cPickleSerial  <- Serial                                              this class is a serialer which uses cPickle and not pickle. This is much faster if you want to convert big or many data







Exceptions:

    _base_                                                                all exceptions contains the functions of this class

        + getTraceback()

        + getMsg()




    CannotSaveHconf  <- _base_                                            this exception is raised if there was an error while saveing Hconf

    CannotLoadHconf  <- _base_                                            this exception is raised if there was an error while loading Hconf

    InvalidKey       <- _base_, __builtin__.KeyError                      this exception is raised if an invalid key was tried to set or get

                                                                              you can catch this with the built-in KeyError

    InvalidFieldType <- _base_, __builtin__.TypeError                     this exception is raised if you tried to give an field an invalid value