Skip to content

Commit

Permalink
Write settings to db if no plugin settings exist
Browse files Browse the repository at this point in the history
  • Loading branch information
greghaynes committed May 27, 2010
1 parent 0ebf9ca commit 510bead
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/pyscripts/xsbs/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
from elixir import Entity, Field, String, Text
from elixir import Entity, Field, String, Text, session

# Set this to wherever your configuration files lie. Must end in a /
configuration_path = 'Config/'
Expand All @@ -15,21 +15,27 @@ class ConfigOption(Entity):
name = Field(String(30))
value = Field(Text)

def loadPluginConfig(dict, plugin):
def loadPluginConfig(cfg_dict, plugin):
'''Accepts a dictionary and plugin name.
All stored values for the plugin will be loaded into dict[section][option] = value.
This allows you to pass a dictionary pre-loaded with default values. '''
options = ConfigOption.query.filter_by(plugin=plugin).all()
for option in options:
try:
sectdict = dict[option.section]
except KeyError:
dict[options.section] = {}
sectdict = dict[option.section]
sectdict[option.name] = option.value
if len(options) == 0:
for section, sectdict in cfg_dict.items():
for option, value in sectdict.items():
db_opt = ConfigOption(plugin=plugin, section=section, option=option, value=value)
session.commit()
else:
for option in options:
try:
sectdict = cfg_dict[option.section]
except KeyError:
cfg_dict[options.section] = {}
sectdict = cfg_dict[option.section]
sectdict[option.name] = option.value

def pluginNames():
return []
return session.query(ConfigOption.plugin)

def pluginSections(plugin_name):
return []
Expand Down

0 comments on commit 510bead

Please sign in to comment.