Beispiel #1
0
    def _update_settings():
        # Settings in current thread are in old state
        # If we detect, that shared object has updated config we replace it
        process = multiprocessing.current_process()
        thread = threading.currentThread()
        log.mpcore.info("Checking for config updates in process '%s' with PID %s using thread '%s'..."
                          % (str(process.name), process.pid, thread.getName()))

        prevUpdate = Settings.configData['update']
        lastUpdate = MultiprocessingCoreExtension.shared_config_data['update']
        if (prevUpdate < lastUpdate):
            process = multiprocessing.current_process()
            thread = threading.currentThread()
            log.mpcore.info("Process '%s' with PID %s received new config, updating using thread '%s'..."
                          % (str(process.name), process.pid, thread.getName()))
            #Core.settings.parse_settings(Core.shared_config_data['data'], Settings.descriptors)
            Settings.set_config_data(MultiprocessingCoreExtension.shared_config_data['data'], update_shared = False)
Beispiel #2
0
    def post_configure(self, core):
        Settings.save = self.save
        log.core.debug('Settings.save method overriden')
        storageUri = Settings.core.settings_storage_uri
        recovery = Settings.recovery or Settings.core.recovery
        self.backend = None
        if not recovery:
            log.settings.info("Initializing Settings Storage..")
            rex = re.compile(r"^(\w+)\+(.*)$")
            match = rex.match(storageUri)
            if match:
                backendId = match.group(1)
                uri = match.group(2)
                spellName = "agatsuma_settings_backend_%s" % backendId
                spell = SpellByStr(spellName)
                if spell:
                    self.backend = spell.instantiate_backend(uri)
                else:
                    raise Exception("Settings backend improperly configured: spell '%s' not found" % spellName)
            else:
                raise Exception("Incorrect settings storage URI")
        else:
            log.settings.warning("Running in recovery mode, settings in storage are ignored")

        if self.backend:
            log.settings.info("Updating writable settings from storage '%s'..." % self.backend.__class__.__name__)
            updated = 0
            for groupName in Settings.settings:
                group = Settings.settings[groupName]
                newGroup = copy.deepcopy(group)
                updatedInGroup = 0
                for setting in group:
                    if not setting in Settings.readonly_settings[groupName]:
                        curVal = group[setting]
                        newVal = self.backend.get("%s.%s" % (groupName, setting), curVal)
                        if newVal != curVal:
                            newGroup[setting] = newVal
                            updated += 1
                            updatedInGroup += 1
                    if updatedInGroup:
                        Settings.settings[groupName] = newGroup
            if updated:
                Settings.set_config_data(Settings.settings)
            log.settings.info("Settings updated from storage: %d" % updated)