mewlo.mpacks.core.database.mdbsettings module

mdbsettings.py This file contains classes to support hierarchical settings. We really don’t do anything fancy here – in fact some of it is a bit ugly and could use rewriting. Essentially we are just maintaining a hierarchical dictionary with some support functions to ease access.

ATTN: this code has become a bit kludgey and could use some rewriting.

class mewlo.mpacks.core.database.mdbsettings.MewloSettingsDb(mewlosite, debugmode)[source]

Bases: mewlo.mpacks.core.setting.msettings.MewloSettings

The MewloSettingsDb class provides a Settings-object interface to settings that are backed in a database. We have some desires for it:

  • For efficiency, we need to support the idea of loading and caching values in memory.
  • But because of distributed/multi-process applications, we may not be able to rely on using cached values.
  • But the machinery should be there in case we can use database-functionality to be informed about when db has changed and needs to be reloaded.
  • We want to support hierarchical serialized data containing multiple types, transparently.
Other details:
  • Each MewloSettingsDb object is tied to a specific table via a db model class (which it can construct dynamically).
Strategy:
  • All requests will be handled by the normal code for using an in-memory dictionary to store and retrieve values.
  • We will keep the in-memory dictionary synchronized with a database table behind the scenes.
  • We must allow that other processes may be trying to modify the data at the same time as us, so we only trust our cached values IFF the database supports a way of telling when a row was last written
  • Furthermore, some operations require a read and then write of a row, and we would like to lock the table/row during such operations.
buildset_dbmodelclass()[source]

Can be overridden by derived classes, by default uses class var.

db_get_lastmodificationtime(keyname)[source]

Return datetime-compatible time of last database table modification, or None if we can’t determine.

db_get_lastmodificationtime_latest()[source]

Return the most datetime-compatible time of most recent database table modification, or None if we can’t determine.

db_loadallkeys()[source]

Load all database rows and unserialize into self.settingdict.

db_loadkey(keyname)[source]

Load a specific key (row) from the database table and unserialize it into self.settingdict[keyname].

db_lock(keynames)[source]

Lock the db, while we read it, run a function, and then write out new values.

db_remove_allkeys()[source]

Remove all keys (rows) from the database table.

db_remove_key(keyname)[source]

Remove a specific key (row) from the database table.

db_savekey(keyname)[source]

Serialize and then save self.settingdict[keyname] into the appropriate database row.

db_unlock()[source]

Unlock the db after previous lock.

dbmodelclass = None
dumps(indent=0)[source]

Return a string (with newlines and indents) that displays some debugging useful information about the object.

get()[source]

Get all.

get_subsubvalue(keyname, keysubname, keysubsubname, defaultval=None)[source]

Lookup value from our settings dictionary at a certain root section, and return it or default if not found.

get_subvalue(keyname, keysubname, defaultval=None)[source]

Lookup value from our settings dictionary at a certain root section, and return it or default if not found.

get_sync_timestamp(keyname)[source]

Return datetime-compatible timestamp of when section was last loaded/saved, or None if we can’t determine.

get_synctime()[source]

We get the sync time before we do an operation, to be conservative.

get_value(keyname, defaultval=None)[source]

Lookup value from our settings dictionary and return it or default if not found.

is_alreadysynced(keyname)[source]

Return True if we are confident that the database is unchanged since our last sync (i.e. if we know our in-memory dictionary is up to date).

is_alreadysynced_all()[source]

Return true if all keys are sync’d already.

merge_settings(settingstoadd)[source]

Just merge in a new dictionary into our main dictionary.

merge_settings_key(keyname, settingstoadd)[source]

Merge in a new dictionary into our main dictionary at a specific root section (creating root section if needed).

merge_settings_subkey(keyname, subkeyname, settingstoadd)[source]

Merge in a new dicitonary into our main dictionary at a specific root section (creating root section if needed).

remove_all()[source]

Clear contents of settings.

remove_key(keyname)[source]

Clear contents of one key.

remove_subkey(keyname, keysubname)[source]

Clear contents of one subkey.

set(newsettings)[source]

Set and overwrite a value at a section, replacing whatever was there.

set_key(keyname, value)[source]

Set and overwrite a value at a section, replacing whatever was there.

startup_prep(stageid, eventlist)[source]

This is invoked by site strtup, for each stage specified in startup_stages_needed() above.

sync_load_all()[source]

Load entire settings (overwriting and removing now-empties).

sync_load_keys(keynames)[source]

Load one or more sections (row) into memory.

sync_save_keys(keynames)[source]

Save one “section” to the database (overwriting whatever is there – including removing values no longer references). We probably treat each section as a row, so this means a row.

update(newsettings)[source]

Update and overwrite a value at a section, replacing whatever was there.

update_sync_timestamp(keyname, synctime)[source]

Update our internal record of when we last sync’d with database.

update_sync_timestamp_all(synctime)[source]

Update our internal record of when we last sync’d with database.

value_exists(keyname, keysubname=None)[source]

Return true if the item existing in our settings dictionary (at specific root section if specified).

class mewlo.mpacks.core.database.mdbsettings.MewloSettingsDb_Dynamic(mewlosite, debugmode, dbmodelclassname=None, dbmodeltablename=None, dbmodelclass=None)[source]

Bases: mewlo.mpacks.core.database.mdbsettings.MewloSettingsDb

Derived version of MewloSettingsDb which dynamically creates a database model class on the fly to use, or which can have one passed into it An example of how you might use this, from old site construct:

# database classes DEF_DBCLASSNAME_PackSettings = ‘DbModel_Settings_Pack’ DEF_DBTABLENAME_PackSettings = ‘settings_pack’ self.createappendcomp(‘packsettings’, mdbsettings.MewloSettingsDb_Dynamic, dbmodelclassname=mconst.DEF_DBCLASSNAME_PackSettings, dbmodeltablename=mconst.DEF_DBTABLENAME_PackSettings) or self.createappendcomp(‘packsettings’, mdbsettings.MewloSettingsDb_Dynamic, dbmodelclass=mdbsettings_pack.MewloDbModel_Settings_Pack)
buildset_dbmodelclass()[source]

Can be overridden by derived classes, by default uses class var.

Table Of Contents

Previous topic

mewlo.mpacks.core.database.mdbmodel_settings module

Next topic

mewlo.mpacks.core.database.mdbsettings_pack module

This Page