示例#1
0
    def getTable(self, runner, cddbdiscid, mbdiscid, device, offset):
        """Retrieve the Table either from the cache or the drive.

        :param runner:
        :type runner:
        :param cddbdiscid:
        :type cddbdiscid:
        :param mbdiscid:
        :type mbdiscid:
        :param device:
        :type device:
        :param offset:
        :type offset:
        :returns:
        :rtype: L{table.Table}
        """
        tcache = cache.TableCache()
        ptable = tcache.get(cddbdiscid, mbdiscid)
        itable = None
        tdict = {}

        # Ignore old cache, since we do not know what offset it used.
        if type(ptable.object) is dict:
            tdict = ptable.object

            if offset in tdict:
                itable = tdict[offset]

        if not itable:
            logger.debug('getTable: cddbdiscid %s, mbdiscid %s not '
                         'in cache for offset %s, reading table' %
                         (cddbdiscid, mbdiscid, offset))
            t = cdrdao.ReadTableTask(device)
            itable = t.table
            tdict[offset] = itable
            ptable.persist(tdict)
            logger.debug('getTable: read table %r' % itable)
        else:
            logger.debug('getTable: cddbdiscid %s, mbdiscid %s in cache '
                         'for offset %s' % (cddbdiscid, mbdiscid, offset))
            logger.debug('getTable: loaded table %r' % itable)

        assert itable.hasTOC()

        self.result.table = itable

        logger.debug('getTable: returning table with mb id %s' %
                     itable.getMusicBrainzDiscId())
        return itable
示例#2
0
    def getTable(self, runner, cddbdiscid, mbdiscid, device, offset, toc_path):
        """
        Retrieve the Table either from the cache or the drive.

        :rtype: table.Table
        """
        tcache = cache.TableCache()
        ptable = tcache.get(cddbdiscid, mbdiscid)
        itable = None
        tdict = {}

        # Ignore old cache, since we do not know what offset it used.
        if isinstance(ptable.object, dict):
            tdict = ptable.object

            if offset in tdict:
                itable = tdict[offset]

        if not itable:
            logger.debug(
                'getTable: cddbdiscid %s, mbdiscid %s not in cache '
                'for offset %s, reading table', cddbdiscid, mbdiscid, offset)
            t = cdrdao.ReadTOCTask(device, toc_path=toc_path)
            t.description = "Reading table"
            runner.run(t)
            itable = t.toc.table
            tdict[offset] = itable
            ptable.persist(tdict)
            logger.debug('getTable: read table %r', itable)
        else:
            logger.debug(
                'getTable: cddbdiscid %s, mbdiscid %s in cache '
                'for offset %s', cddbdiscid, mbdiscid, offset)
            logger.debug('getTable: loaded table %r', itable)

        assert itable.hasTOC()

        self.result.table = itable

        logger.debug('getTable: returning table with mb id %s',
                     itable.getMusicBrainzDiscId())
        return itable