Exemplo n.º 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))
Exemplo n.º 2
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))
Exemplo n.º 3
0
    def test_works(self):
        ''' Make sure that update_settings() works '''

        connection = sqlite3.connect(':memory:')
        table_config.create(connection)

        privacy.update_settings(
            connection, {
                'privacy.informed': 4,
                'privacy.can_collect': 5,
                'privacy.can_publish': 6,
                'foo': 'bar',
            })

        content = table_config.dictionarize(connection)

        # Make sure foo: bar was not added
        self.assertEqual(
            sorted(content.keys()),
            sorted([
                'uuid', 'version', 'privacy.informed', 'privacy.can_collect',
                'privacy.can_publish'
            ]))

        # Make sure settings were added correctly
        self.assertEqual(content['privacy.informed'], '4')
        self.assertEqual(content['privacy.can_collect'], '5')
        self.assertEqual(content['privacy.can_publish'], '6')
Exemplo n.º 4
0
    def test_works(self):
        ''' Make sure that update_settings() works '''

        connection = sqlite3.connect(':memory:')
        table_config.create(connection)

        privacy.update_settings(connection, {
                                             'privacy.informed': 4,
                                             'privacy.can_collect': 5,
                                             'privacy.can_publish': 6,
                                             'foo': 'bar',
                                            })

        content = table_config.dictionarize(connection)

        # Make sure foo: bar was not added
        self.assertEqual(sorted(content.keys()), sorted([
                                                         'uuid', 'version',
                                                         'privacy.informed',
                                                         'privacy.can_collect',
                                                         'privacy.can_publish'
                                                        ]))

        # Make sure settings were added correctly
        self.assertEqual(content['privacy.informed'], '4')
        self.assertEqual(content['privacy.can_collect'], '5')
        self.assertEqual(content['privacy.can_publish'], '6')
Exemplo n.º 5
0
def test_settings(connection):

    ''' Test privacy settings and exit, setting properly the
        exit value '''

    settings = table_config.dictionarize(connection)
    if count_valid(settings, 'privacy.') == 3:
        return 0

    return 1
Exemplo n.º 6
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))
Exemplo n.º 7
0
def print_settings(connection, database_path):

    ''' Print privacy settings and exit '''

    sys.stdout.write('database: %s\n' % database_path)
    sys.stdout.write('settings:\n')
    dictionary = table_config.dictionarize(connection)
    for name, value in dictionary.items():
        if name.startswith('privacy.'):
            name = name.replace("privacy.", "")
            sys.stdout.write('    %-12s: %d\n' % (name,
                    utils.intify(value)))
    sys.stdout.write('\n')

    return 0
Exemplo n.º 8
0
def print_settings(connection, database_path):

    ''' Print privacy settings and exit '''

    sys.stdout.write(USAGE + '\n')
    sys.stdout.write('Current database: %s\n' % database_path)
    sys.stdout.write('Current settings:\n')
    dictionary = table_config.dictionarize(connection)
    for name, value in dictionary.items():
        if name.startswith('privacy.'):
            sys.stdout.write('    %-20s: %d\n' % (name,
                    utils.intify(value)))
    sys.stdout.write('\n')

    return 0
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def merge_database(self, database):
     logging.debug("config: reading properties from database")
     dictionary = table_config.dictionarize(database)
     for key, value in dictionary.items():
         self.merge_kv((key, value))