def __init__(self, manager, loginname, password, options): Base.__init__(self, manager.core) if "activated" in options: self.activated = from_string(options["activated"], "bool") else: self.activated = Account.activated for opt in self.known_opt: if opt not in options: options[opt] = "" for opt in options.keys(): if opt not in self.known_opt: del options[opt] self.loginname = loginname self.options = options self.manager = manager self.lock = RLock() self.timestamp = 0 self.login_ts = 0 # timestamp for login self.cj = CookieJar(self.__name__) self.password = password self.error = None self.init()
def set(self, section, option, value, sync=True): """set value""" data = self.config[section].config[option] value = from_string(value, data.type) old_value = self.get(section, option) # only save when different values if value != old_value: if section not in self.values: self.values[section] = {} self.values[section][option] = value if sync: self.save() return True return False
def set(self, section, option, value, sync=True, user=None): """ set config value """ changed = False if section in self.parser and user is None: changed = self.parser.set(section, option, value, sync) else: data = self.config[section].config[option] value = from_string(value, data.type) old_value = self.get(section, option) # Values will always be saved to db, sync is ignored if value != old_value: changed = True self.values[user, section][option] = value if sync: self.saveValues(user, section) if changed: self.core.evm.dispatchEvent("config:changed", section, option, value) return changed
def addConfigSection(self, section, name, desc, long_desc, config): """Adds a section to the config. `config` is a list of config tuples as used in plugin api defined as: The order of the config elements is preserved with OrderedDict """ d = OrderedDict() for entry in config: if len(entry) == 5: conf_name, type, conf_desc, conf_verbose, default = entry else: # config options without description conf_name, type, conf_desc, default = entry conf_verbose = "" d[conf_name] = ConfigData(gettext(conf_desc), type, gettext(conf_verbose), from_string(default, type)) data = SectionTuple(gettext(name), gettext(desc), gettext(long_desc), d) self.config[section] = data
def update(self, password=None, options=None): """ updates the account and returns true if anything changed """ self.login_ts = 0 self.valid = True #set valid, so the login will be retried if "activated" in options: self.activated = from_string(options["avtivated"], "bool") if password: self.password = password self.relogin() return True if options: # remove unknown options for opt in options.keys(): if opt not in self.known_opt: del options[opt] before = self.options self.options.update(options) return self.options != before