Exemplo n.º 1
0
    def _test_missing_config(self, store):
        self.assertEqual(True, config.is_cfg_valid(store))

        p = config.Config('private', 'smtp_password', 'XXXX')
        p.var_group = u'outside'
        store.add(p)

        self.assertEqual(False, config.is_cfg_valid(store))

        node = config.NodeFactory(store)
        c = node.get_cfg(u'hostname')
        store.remove(c)
        store.commit()

        self.assertEqual(False, node.db_corresponds())

        # Delete all of the vars in Private Factory
        prv = config.PrivateFactory(store)

        store.execute('DELETE FROM config WHERE var_group = "private"')

        self.assertEqual(False, prv.db_corresponds())

        ntfn = config.NotificationFactory(store)

        c = config.Config('notification', 'server', 'guarda.giochi.con.occhi')
        c.var_name = u'anextravar'
        store.add(c)

        self.assertEqual(False, ntfn.db_corresponds())

        config.update_defaults(store)

        self.assertEqual(True, config.is_cfg_valid(store))
Exemplo n.º 2
0
    def _test_missing_config(self, store):
        self.assertEqual(True, config.is_cfg_valid(store))

        p = config.Config('private', 'smtp_password', 'XXXX')
        p.var_group = u'outside'
        store.add(p)

        self.assertEqual(False, config.is_cfg_valid(store))

        node = config.NodeFactory(store)
        c = node.get_cfg('public_site')
        store.remove(c)
        store.commit()

        self.assertEqual(False, node.db_corresponds())

        # Delete all of the vars in Private Factory
        prv = config.PrivateFactory(store)

        store.execute('DELETE FROM config WHERE var_group = "private"')

        self.assertEqual(False, prv.db_corresponds())

        ntfn = config.NotificationFactory(store)

        c = config.Config('notification', 'server', 'guarda.giochi.con.occhi')
        c.var_name = u'anextravar'
        store.add(c)

        self.assertEqual(False, ntfn.db_corresponds())

        config.update_defaults(store)

        self.assertEqual(True, config.is_cfg_valid(store))
Exemplo n.º 3
0
def perform_data_update(db_file):
    """
    Update the database including up-to-date application data
    :param db_file: The database file path
    """
    now = datetime_now()

    appdata = load_appdata()

    session = get_session(make_db_uri(db_file), foreign_keys=False)

    enabled_languages = [
        lang.name for lang in session.query(models.EnabledLanguage)
    ]

    removed_languages = list(
        set(enabled_languages) - set(LANGUAGES_SUPPORTED_CODES))

    if removed_languages:
        removed_languages.sort()
        removed_languages = ', '.join(removed_languages)
        raise Exception(
            "FATAL: cannot complete the upgrade because the support for some of the enabled languages is currently incomplete (%s)\n"
            % removed_languages)

    try:
        if config.ConfigFactory(session, 1).get_val('version') != __version__:
            session.query(models.Config).filter_by(var_name = 'version') \
                   .update({'value': __version__, 'update_date': now})

            session.query(models.Config).filter_by(var_name = 'latest_version') \
                   .update({'value': __version__, 'update_date': now})

            session.query(models.Config).filter_by(var_name = 'version_db') \
                   .update({'value': DATABASE_VERSION, 'update_date': now})

            for tid in [t[0] for t in session.query(models.Tenant.id)]:
                config.update_defaults(session, tid, appdata)

            db_load_defaults(session)

        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()
Exemplo n.º 4
0
def perform_data_update(db_file):
    """
    Update the database including up-to-date application data
    :param db_file: The database file path
    """
    session = get_session(make_db_uri(db_file), foreign_keys=False)

    enabled_languages = [
        lang.name for lang in session.query(models.EnabledLanguage)
    ]

    removed_languages = list(
        set(enabled_languages) - set(LANGUAGES_SUPPORTED_CODES))

    if removed_languages:
        removed_languages.sort()
        removed_languages = ', '.join(removed_languages)
        raise Exception(
            "FATAL: cannot complete the upgrade because the support for some of the enabled languages is currently incomplete (%s)\n"
            "Read about how to handle this condition at: https://github.com/globaleaks/GlobaLeaks/wiki/Upgrade-Guide#lang-drop"
            % removed_languages)

    try:
        cfg = config.ConfigFactory(session, 1)

        stored_ver = cfg.get_val('version')

        if stored_ver != __version__:
            # The below commands can change the current store based on the what is
            # currently stored in the DB.
            for tid in [t[0] for t in session.query(models.Tenant.id)]:
                appdata = load_appdata()
                config.update_defaults(session, tid, appdata)

            db_load_defaults(session)

            cfg.set_val('version', __version__)
            cfg.set_val('latest_version', __version__)
            cfg.set_val('version_db', DATABASE_VERSION)

        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()
Exemplo n.º 5
0
def db_perform_data_update(store):
    prv = PrivateFactory(store)

    stored_ver = prv.get_val('version')
    t = (stored_ver, __version__)

    # Catch all failures
    if stored_ver != __version__:
        prv.set_val('version', __version__)

        appdata = db_update_appdata(store)
        config.update_defaults(store)
        l10n.update_defaults(store, appdata)
        db_fix_fields_attrs(store)

    ok = config.is_cfg_valid(store)
    if not ok:
        m = 'Error: the system is not stable, update failed from %s to %s' % t
        raise DatabaseIntegrityError(m)
Exemplo n.º 6
0
def perform_data_update(db_file):
    engine = get_engine(make_db_uri(db_file), foreign_keys=False)
    session = sessionmaker(bind=engine)()

    enabled_languages = [
        lang.name for lang in session.query(models.EnabledLanguage)
    ]

    removed_languages = list(
        set(enabled_languages) - set(LANGUAGES_SUPPORTED_CODES))

    if removed_languages:
        removed_languages.sort()
        removed_languages = ', '.join(removed_languages)
        raise Exception(
            "FATAL: cannot complete the upgrade because the support for some of the enabled languages is currently incomplete (%s)\n"
            "Read about how to handle this condition at: https://github.com/globaleaks/GlobaLeaks/wiki/Upgrade-Guide#lang-drop"
            % removed_languages)

    try:
        prv = ConfigFactory(session, 1, 'node')

        stored_ver = prv.get_val(u'version')

        if stored_ver != __version__:
            # The below commands can change the current store based on the what is
            # currently stored in the DB.
            for tid in [t[0] for t in session.query(models.Tenant.id)]:
                appdata = load_appdata()
                config.update_defaults(session, tid, appdata)

            db_update_defaults(session)
            db_fix_fields_attrs(session)

            prv.set_val(u'version', __version__)
            prv.set_val(u'latest_version', __version__)

        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()
Exemplo n.º 7
0
def db_perform_data_update(store):
    prv = PrivateFactory(store)

    stored_ver = prv.get_val('version')
    t = (stored_ver, __version__)

    if stored_ver != __version__:
        prv.set_val('version', __version__)

        # The below commands can change the current store based on the what is
        # currently stored in the DB.
        appdata = db_update_appdata(store)
        l10n.update_defaults(store, appdata)
        config.update_defaults(store)
        db_fix_fields_attrs(store)

    ok = config.is_cfg_valid(store)
    if not ok:
        m = 'Error: the system is not stable, update failed from %s to %s' % t
        raise Exception(m)
Exemplo n.º 8
0
def db_perform_data_update(store):
    prv = PrivateFactory(store)

    stored_ver = prv.get_val('version')
    t = (stored_ver, __version__)

    if stored_ver != __version__:
        prv.set_val('version', __version__)

        # The below commands can change the current store based on the what is
        # currently stored in the DB.
        appdata = db_update_appdata(store)
        l10n.update_defaults(store, appdata)
        config.update_defaults(store)
        db_fix_fields_attrs(store)

    ok = config.is_cfg_valid(store)
    if not ok:
        m = 'Error: the system is not stable, update failed from %s to %s' % t
        raise Exception(m)
Exemplo n.º 9
0
def perform_data_update(db_file):
    session = get_session(make_db_uri(db_file), foreign_keys=False)

    enabled_languages = [lang.name for lang in session.query(models.EnabledLanguage)]

    removed_languages = list(set(enabled_languages) - set(LANGUAGES_SUPPORTED_CODES))

    if removed_languages:
        removed_languages.sort()
        removed_languages = ', '.join(removed_languages)
        raise Exception("FATAL: cannot complete the upgrade because the support for some of the enabled languages is currently incomplete (%s)\n"
                        "Read about how to handle this condition at: https://github.com/globaleaks/GlobaLeaks/wiki/Upgrade-Guide#lang-drop" % removed_languages)

    try:
        cfg = ConfigFactory(session, 1)

        stored_ver = cfg.get_val(u'version')

        if stored_ver != __version__:
            # The below commands can change the current store based on the what is
            # currently stored in the DB.
            for tid in [t[0] for t in session.query(models.Tenant.id)]:
                appdata = load_appdata()
                config.update_defaults(session, tid, appdata)

            db_update_defaults(session)

            db_fix(session)

            cfg.set_val(u'version', __version__)
            cfg.set_val(u'latest_version', __version__)
            cfg.set_val(u'version_db', DATABASE_VERSION)

        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()