Пример #1
0
def update_defaults(session, tid):
    session.query(Config).filter(
        Config.tid == tid, not_(Config.var_name.in_(
            ConfigDescriptor.keys()))).delete(synchronize_session='fetch')

    ConfigFactory(session, tid, 'node').clean_and_add()
    ConfigFactory(session, tid, 'notification').clean_and_add()

    # Set the system version to the current aligned cfg
    ConfigFactory(session, tid, 'node').set_val(u'version', __version__)
Пример #2
0
    def update_defaults(self):
        actual = set([c[0] for c in self.session.query(Config.var_name).filter(Config.tid == self.tid)])
        allowed = set(ConfigDescriptor.keys())
        extra = list(actual - allowed)

        if extra:
            self.session.query(Config).filter(Config.tid == self.tid, Config.var_name.in_(extra)).delete(synchronize_session='fetch')

        missing = list(allowed - actual)
        for key in missing:
            self.session.add(Config({'tid': self.tid, 'var_name': key, 'value': get_default(ConfigDescriptor[key].default)}))
Пример #3
0
    def update_defaults(self):
        actual = set([c[0] for c in self.session.query(Config.var_name).filter(Config.tid == self.tid)])
        allowed = set(ConfigDescriptor.keys())
        extra = list(actual - allowed)

        if extra:
            self.session.query(Config).filter(Config.tid == self.tid, Config.var_name.in_(extra)).delete(synchronize_session='fetch')

        missing = list(allowed - actual)
        for key in missing:
            self.session.add(Config({'tid': self.tid, 'var_name': key, 'value': get_default(ConfigDescriptor[key].default)}))
Пример #4
0
def fix_tenant_config(session, tid):
    '''
    The function add new defined variables and remove variables not anymore defined
    '''
    actual = set([c[0] for c in session.query(Config.var_name).filter(Config.tid == tid)])
    allowed = set(ConfigDescriptor.keys())
    extra = list(actual - allowed)

    if extra:
        session.query(Config).filter(Config.tid == tid, Config.var_name.in_(extra)).delete(synchronize_session='fetch')

    missing = list(allowed - actual)
    for key in missing:
        session.add(Config(tid, key, get_default(ConfigDescriptor[key].default)))

    return len(missing), len(extra)
Пример #5
0
    def clean_and_add(self):
        actual = set([
            c[0] for c in self.session.query(Config.var_name).filter(
                Config.tid == self.tid)
        ])
        allowed = set(ConfigDescriptor.keys())
        extra = list(actual - allowed)

        if extra:
            self.session.query(Config).filter(
                Config.tid == self.tid,
                Config.var_name.in_(extra)).delete(synchronize_session='fetch')

        missing = list(allowed - actual)
        for key in missing:
            self.session.add(
                Config(self.tid, key, ConfigDescriptor[key].default))

        return len(missing), len(extra)
Пример #6
0
def update_defaults(session, tid, appdata):
    session.query(Config).filter(
        Config.tid == tid, not_(Config.var_name.in_(
            ConfigDescriptor.keys()))).delete(synchronize_session='fetch')

    ConfigFactory(session, tid, 'node').clean_and_add()
    ConfigFactory(session, tid, 'notification').clean_and_add()

    # Set the system version to the current aligned cfg
    ConfigFactory(session, tid, 'node').set_val(u'version', __version__)

    langs = EnabledLanguage.list(session, tid)

    session.query(ConfigL10N).filter(
        ConfigL10N.tid == tid,
        not_(
            ConfigL10N.var_name.in_(NodeL10NFactory.keys +
                                    NotificationL10NFactory.keys))).delete(
                                        synchronize_session='fetch')

    NodeL10NFactory(session, tid).update_defaults(langs, appdata['node'])
    NotificationL10NFactory(session,
                            tid).update_defaults(langs, appdata['templates'])