Beispiel #1
0
    def build(self, sections_iterator, index_file):
        '''Build up IndexedWorldData from the data in the given sections.
        '''
        indexed_field_names = ('name', 'sp-name', 'source-rpm', 'filename')
        indexed_fields = [ ('pdk', f) for f in indexed_field_names ]
        index_writer = IndexWriter(index_file)
        index_writer.init()
        try:
            for section_name, section in sections_iterator:
                section_iterator = section.iter_package_info()
                for ghost, header, blob_id, locator in section_iterator:
                    if ghost:
                        type_string = ghost.type
                    else:
                        type_string = None

                    addresses = index_writer.add(type_string, header,
                                                 blob_id, locator)
                    if ghost:
                        index_keys = []
                        for field in indexed_fields:
                            try:
                                value = ghost[field]
                            except KeyError:
                                continue
                            key = (section_name, field, value)
                            index_keys.append(key)
                        index_writer.index(index_keys, addresses)

                    ent_id_key = ('ent-id', blob_id)
                    channel_key = section_name
                    index_writer.index([ ent_id_key, channel_key ],
                                       addresses)
            index_writer.terminate()
            del index_writer
            # Next time index_file is accessed, it will be reloaded,
            # therefore actually reading the new file we just wrote!
            del self.index_file

        except MissingChannelDataError:
            message = 'Missing cached data. ' + \
                      'Consider running pdk channel update. ' + \
                      '(%s)' % section_name
            raise SemanticError(message)
Beispiel #2
0
    def build(self, sections_iterator, index_file):
        '''Build up IndexedWorldData from the data in the given sections.
        '''
        indexed_field_names = ('name', 'sp-name', 'source-rpm', 'filename')
        indexed_fields = [('pdk', f) for f in indexed_field_names]
        index_writer = IndexWriter(index_file)
        index_writer.init()
        try:
            for section_name, section in sections_iterator:
                section_iterator = section.iter_package_info()
                for ghost, header, blob_id, locator in section_iterator:
                    if ghost:
                        type_string = ghost.type
                    else:
                        type_string = None

                    addresses = index_writer.add(type_string, header, blob_id,
                                                 locator)
                    if ghost:
                        index_keys = []
                        for field in indexed_fields:
                            try:
                                value = ghost[field]
                            except KeyError:
                                continue
                            key = (section_name, field, value)
                            index_keys.append(key)
                        index_writer.index(index_keys, addresses)

                    ent_id_key = ('ent-id', blob_id)
                    channel_key = section_name
                    index_writer.index([ent_id_key, channel_key], addresses)
            index_writer.terminate()
            del index_writer
            # Next time index_file is accessed, it will be reloaded,
            # therefore actually reading the new file we just wrote!
            del self.index_file

        except MissingChannelDataError:
            message = 'Missing cached data. ' + \
                      'Consider running pdk channel update. ' + \
                      '(%s)' % section_name
            raise SemanticError(message)
Beispiel #3
0
    def test_write_then_read(self):
        writer = IndexWriter('a')
        writer.init()

        address = writer.add('full', 'time', 3)
        writer.index([ ('a', 'b') ], address)

        address = writer.add(2, 7, 5)
        writer.index([ ('a', 'b'), ('z', 'c') ], address)
        writer.terminate()

        reader = IndexFile('a')
        self.assert_equal(['time', 7], list(reader.get(('a', 'b'), 1)))
        self.assert_equal([7], list(reader.get(('z', 'c'), 1)))
        self.assert_equal([], list(reader.get(('l', 'm'), 1)))

        self.assert_equal([ ('full', 'time', 3), (2, 7, 5) ],
                          list(reader.get_all(('a', 'b'))))
        self.assert_equal([ (2, 7, 5) ], list(reader.get_all(('z', 'c'))))
        self.assert_equal([], list(reader.get_all(('l', 'm'))))

        self.assert_equal(2, reader.count(('a', 'b')))
        self.assert_equal(1, reader.count(('z', 'c')))
        self.assert_equal(0, reader.count(('l', 'm')))
Beispiel #4
0
    def test_write_then_read(self):
        writer = IndexWriter('a')
        writer.init()

        address = writer.add('full', 'time', 3)
        writer.index([('a', 'b')], address)

        address = writer.add(2, 7, 5)
        writer.index([('a', 'b'), ('z', 'c')], address)
        writer.terminate()

        reader = IndexFile('a')
        self.assert_equal(['time', 7], list(reader.get(('a', 'b'), 1)))
        self.assert_equal([7], list(reader.get(('z', 'c'), 1)))
        self.assert_equal([], list(reader.get(('l', 'm'), 1)))

        self.assert_equal([('full', 'time', 3), (2, 7, 5)],
                          list(reader.get_all(('a', 'b'))))
        self.assert_equal([(2, 7, 5)], list(reader.get_all(('z', 'c'))))
        self.assert_equal([], list(reader.get_all(('l', 'm'))))

        self.assert_equal(2, reader.count(('a', 'b')))
        self.assert_equal(1, reader.count(('z', 'c')))
        self.assert_equal(0, reader.count(('l', 'm')))