Exemple #1
0
    def runTest(self):

        connection = sqlite3.connect(":memory:")
        connection.row_factory = sqlite3.Row

        v, v2 = [], []
        table_config.create(connection)
        for name, value in table_config.dictionarize(connection).items():
            v.append((name, value))
        table_config.create(connection)
        for name, value in table_config.dictionarize(connection).items():
            v2.append((name, value))
        self.assertEquals(v, v2)

        table_config.update(connection, {"uuid": ""}.iteritems())
        result = table_config.dictionarize(connection)
        #
        # The version number changes as time passes and we don't
        # want to keep the test uptodate.
        #
        del result['version']
        self.assertEquals(result, {"uuid": ""})

        table_config.update(connection, {}.iteritems(), clear=True)
        self.assertEquals(table_config.dictionarize(connection), {})

        table_config.create(connection)
        print(table_config.jsonize(connection))
Exemple #2
0
 def merge_api(self, dictlike, database=None):
     # enforce all-or-nothing
     logging.debug("config: reading properties from /api/config")
     map(lambda t: self.merge_kv(t, dry=True), dictlike.iteritems())
     map(self.merge_kv, dictlike.iteritems())
     if database:
         table_config.update(database, dictlike.iteritems())
    def runTest(self):

        connection = sqlite3.connect(":memory:")
        connection.row_factory = sqlite3.Row

        v, v2 = [], []
        table_config.create(connection)
        for name, value in table_config.dictionarize(connection).items():
            v.append((name, value))
        table_config.create(connection)
        for name, value in table_config.dictionarize(connection).items():
            v2.append((name, value))
        self.assertEquals(v, v2)

        table_config.update(connection, {"uuid": ""}.iteritems())
        result = table_config.dictionarize(connection)
        #
        # The version number changes as time passes and we don't
        # want to keep the test uptodate.
        #
        del result['version']
        self.assertEquals(result, {"uuid": ""})

        table_config.update(connection, {}.iteritems(), clear=True)
        self.assertEquals(table_config.dictionarize(connection), {})

        table_config.create(connection)
        print(table_config.jsonize(connection))
Exemple #4
0
    def test_failure(self):
        ''' Make sure test_settings() returns 1 for a bad database '''

        connection = sqlite3.connect(':memory:')
        table_config.create(connection)
        table_config.update(connection, {
                                         'privacy.informed': 1,
                                         'privacy.can_collect': 1,
                                         'privacy.can_publish': 0
                                        }.iteritems())

        self.assertEqual(privacy.test_settings(connection), 1)
Exemple #5
0
    def test_failure(self):
        ''' Make sure test_settings() returns 1 for a bad database '''

        connection = sqlite3.connect(':memory:')
        table_config.create(connection)
        table_config.update(
            connection, {
                'privacy.informed': 1,
                'privacy.can_collect': 1,
                'privacy.can_publish': 0
            }.iteritems())

        self.assertEqual(privacy.test_settings(connection), 1)
Exemple #6
0
def update_settings(connection, settings):

    ''' Update database privacy settings and exit '''

    for name in settings.keys():
        if name not in ('privacy.informed', 'privacy.can_collect',
                    'privacy.can_publish'):
            sys.stderr.write('WARNING unknown setting: %s\n' % name)
            del settings[name]
    table_config.update(connection, settings.items())
    # Live with that or provide a patch
    sys.stdout.write('*** Database changed.  Please, restart Neubot.\n')

    return 0
Exemple #7
0
def main(args):

    try:
        options, arguments = getopt.getopt(args[1:], "f:")
    except getopt.GetoptError:
        sys.stderr.write(USAGE)
        sys.exit(1)

    for key, value in options:
        if key == "-f":
            DATABASE.set_path(value)

    DATABASE.connect()

    if not arguments:
        sys.stdout.write('%s\n' % DATABASE.path)

    elif arguments[0] == "regen_uuid":
        if DATABASE.readonly:
            sys.exit('ERROR: readonly database')

        table_config.update(DATABASE.connection(),
          {"uuid": utils.get_uuid()}.iteritems())

    elif arguments[0] == "prune":
        if DATABASE.readonly:
            sys.exit('ERROR: readonly database')

        table_speedtest.prune(DATABASE.connection())

    elif arguments[0] == "delete_all":
        if DATABASE.readonly:
            sys.exit('ERROR: readonly database')

        table_speedtest.prune(DATABASE.connection(), until=utils.timestamp())
        DATABASE.connection().execute("VACUUM;")

    elif arguments[0] in ("show", "dump"):
        d = { "config": table_config.dictionarize(DATABASE.connection()),
             "speedtest": table_speedtest.listify(DATABASE.connection()) }
        if arguments[0] == "show":
            compat.json.dump(d, sys.stdout, indent=4)
        elif arguments[0] == "dump":
            compat.json.dump(d, sys.stdout)

    else:
        sys.stdout.write(USAGE)
        sys.exit(0)
    def runTest(self):

        connection = sqlite3.connect(":memory:")
        connection.row_factory = sqlite3.Row

        v, v2 = [], []
        table_config.create(connection)
        table_config.walk(connection, v.append)
        table_config.create(connection)
        table_config.walk(connection, v2.append)
        self.assertEquals(v, v2)

        table_config.update(connection, {"uuid": ""}.iteritems())
        self.assertEquals(table_config.dictionarize(connection),
                          {"version": "4.0", "uuid": ""})

        table_config.update(connection, {}.iteritems(), clear=True)
        self.assertEquals(table_config.dictionarize(connection), {})

        table_config.create(connection)
        print(table_config.jsonize(connection))
Exemple #9
0
    def test_legacy(self):
        ''' Make sure test_settings() returns 1 for a legacy database '''

        #
        # This case should not happen, still I want to be sure
        # an error would be reported in this case.
        #

        connection = sqlite3.connect(':memory:')
        table_config.create(connection)
        table_config.update(connection, {
                                         'privacy.informed': 1,
                                         'privacy.can_collect': 1,
                                         'privacy.can_publish': 1
                                        }.iteritems())

        # Go back to version 4.1 of the database
        connection.execute(''' UPDATE config SET name="privacy.can_share"
                               WHERE name="privacy.can_publish" ''')

        self.assertEqual(privacy.test_settings(connection), 1)
Exemple #10
0
    def test_legacy(self):
        ''' Make sure test_settings() returns 1 for a legacy database '''

        #
        # This case should not happen, still I want to be sure
        # an error would be reported in this case.
        #

        connection = sqlite3.connect(':memory:')
        table_config.create(connection)
        table_config.update(
            connection, {
                'privacy.informed': 1,
                'privacy.can_collect': 1,
                'privacy.can_publish': 1
            }.iteritems())

        # Go back to version 4.1 of the database
        connection.execute(''' UPDATE config SET name="privacy.can_share"
                               WHERE name="privacy.can_publish" ''')

        self.assertEqual(privacy.test_settings(connection), 1)
Exemple #11
0
def main(args):

    ''' Will initialize privacy settings '''

    CONFIG.register_descriptions({
        'privacy.init_informed': "You've read privacy policy",
        'privacy.init_can_collect': 'We can collect your IP address',
        'privacy.init_can_share': 'We can share your IP address',
        'privacy.overwrite': 'Overwrite old settings',
                                 })

    common.main('privacy', 'Initialize privacy settings', args)
    conf = CONFIG.copy()

    if not conf['privacy.informed'] or conf['privacy.overwrite']:
        dictonary = {
                     'privacy.informed': conf['privacy.init_informed'],
                     'privacy.can_collect': conf['privacy.init_can_collect'],
                     'privacy.can_share': conf['privacy.init_can_share'],
                    }
        table_config.update(DATABASE.connection(), dictonary.iteritems())

    DATABASE.connection().commit()
Exemple #12
0
 def store_database(self, database):
     table_config.update(database, self.conf.iteritems(), clear=True)