Exemple #1
0
    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()
Exemple #2
0
    def __init__(self, manager, loginname, password, options):
        Base.__init__(self, manager.core)

        if "activated" in options:
            activated = from_string(options["activated"], "bool")
        else:
            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]

        # default account attributes
        AccountInfo.__init__(self, self.__name__, loginname, Account.valid, Account.validuntil, Account.trafficleft,
            Account.maxtraffic, Account.premium, activated, 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()
Exemple #3
0
    def __init__(self, manager, loginname, password, options):
        Base.__init__(self, manager.core)

        if "activated" in options:
            activated = from_string(options["activated"], "bool")
        else:
            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]

        # default account attributes
        AccountInfo.__init__(self, self.__name__, loginname, Account.valid,
                             Account.validuntil, Account.trafficleft,
                             Account.maxtraffic, Account.premium, activated,
                             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()
Exemple #4
0
    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()
Exemple #5
0
    def set(self, section, option, value, sync=True):
        """set value"""

        data = self.config[section].config[option]
        value = from_string(value, data.type)

        # only save when different to default values
        if value != data.default or (option in self.values[section] and value != self.values[section][option]):
            self.values[section][option] = value
            if sync:
                if self.changeCB: self.changeCB(section, option, value)
                self.save()
Exemple #6
0
    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
Exemple #7
0
    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
Exemple #8
0
    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
Exemple #9
0
    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
Exemple #10
0
    def set(self, section, option, value, sync=True, user=None):
        """ set config value  """

        changed = False
        if section in self.parser and (not user or (user and user.isAdmin())):
            changed = self.parser.set(section, option, value, sync)
        else:
            # associated id
            user = primary_uid(user)
            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
                self.saveValues(user, section)

        if changed: self.core.evm.dispatchEvent("configChanged", section, option, value)
        return changed
Exemple #11
0
    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
Exemple #12
0
    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
Exemple #13
0
    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
Exemple #14
0
    def addConfigSection(self, section, name, desc, long_desc, config, base=False):
        """Adds a section to the config. `config` is a list of config tuples as used in plugin api defined as:
        Either (name, type, verbose_name, default_value) or
                (name, type, verbose_name, short_description, default_value)
        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 tooltip / 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))

        if base:
            if section not in self.baseSections: self.baseSections.append(section)
        elif section in self.baseSections:
            return # would overwrite base section

        data = SectionTuple(gettext(name), gettext(desc), gettext(long_desc), d)
        self.config[section] = data

        if section not in self.values:
            self.values[section] = {}