6.13. Application configuration
6.13.1 AppConfig()
Karrigell provides a way to save/restore simple data for your application. The main use is application configuration. For example, Mailing List demo saves/restore SMTP server name usingAppConfig()
.
AppConfig() accepts 1 parameter : The name of your application.
Because one server can run more than one application, name of application is needed to save/restore data to/from separate files.
Of course, one application can use more than one name for its own use.
Creating an AppConfig object :
import k_app_config
app_config = k_app_config.AppConfig ("test")
Saving a data is as simple as writing it :
app_config.data = "test"
Restoring a data is also very simple :
data = app_config.data
To delete a data :
del(app_config.data)
You can save/restore every object that is pickable.
6.13.2 Example
import k_app_config def GetSmtpServer (): app_config = k_app_config.AppConfig ("mailing list") try : return app_config.smtp_server except AttributeError : app_config.smtp.server = "my.smtp.server.com"
In this example, if no smtp_server member is found, a default one is set.
Of course, in real life, in case of AttributeError, one have to redirect to a page requesting admin to input smtp server name (see mailing list demo).