Exemplo n.º 1
0
def scan_device_for_files(device):
    known_files = clean_database(device)

    device.database.set_bulk_mode(True)
    device.database.setdefault('sync', {})

    for filename in fileutil.miro_allfiles(device.mount):
        short_filename = filename[len(device.mount):]
        ufilename = filename_to_unicode(short_filename)
        if os.path.normcase(ufilename) in known_files:
            continue
        if filetypes.is_video_filename(ufilename):
            item_type = 'video'
        elif filetypes.is_audio_filename(ufilename):
            item_type = 'audio'
        else:
            continue
        device.database[item_type][ufilename] = {}

    device.database.set_bulk_mode(False)
Exemplo n.º 2
0
def scan_device_for_files(device):
    # XXX is this as_idle() safe?

    # prepare paths to add
    logging.debug('starting scan on %s', device.mount)
    known_files = clean_database(device)
    item_data = []
    start = time.time()
    filenames = []
    def _stop():
        if not app.device_manager.running: # user quit, so we will too
            logging.debug('stopping scan on %s: user quit', device.mount)
            return True
        if not os.path.exists(device.mount): # device disappeared
            logging.debug('stopping scan on %s: disappeared', device.mount)
            return True
        if app.device_manager._is_hidden(device): # device no longer being
                                                  # shown
            logging.debug('stopping scan on %s: hidden', device.mount)
            return True
        return False

    for filename in fileutil.miro_allfiles(device.mount):
        short_filename = filename[len(device.mount):]
        ufilename = filename_to_unicode(short_filename)
        item_type = None
        if os.path.normcase(short_filename) in known_files:
            continue
        if filetypes.is_video_filename(ufilename):
            item_type = u'video'
        elif filetypes.is_audio_filename(ufilename):
            item_type = u'audio'
        if item_type is not None:
            item_data.append((ufilename, item_type))
            filenames.append(filename)
        if time.time() - start > 0.4:
            app.metadata_progress_updater.will_process_paths(filenames,
                                                             device)
            yield # let other stuff run
            if _stop():
                break
            start = time.time()
            filenames = []

    if app.device_manager.running and os.path.exists(device.mount):
        # we don't re-check if the device is hidden because we still want to
        # save the items we found in that case
        yield # yield after prep work

        device.database.setdefault(u'sync', {})
        logging.debug('scanned %s, found %i files (%i total)',
                      device.mount, len(item_data),
                      len(known_files) + len(item_data))

        device.database.set_bulk_mode(True)
        start = time.time()
        for ufilename, item_type in item_data:
            i = item.DeviceItem(video_path=ufilename,
                           file_type=item_type,
                           device=device)
            device.database[item_type][ufilename] = i.to_dict()
            device.database.emit('item-added', i)
            if time.time() - start > 0.4:
                device.database.set_bulk_mode(False) # save the database
                yield # let other idle functions run
                if _stop():
                    break
                device.database.set_bulk_mode(True)
                start = time.time()

        device.database.set_bulk_mode(False)
Exemplo n.º 3
0
def scan_device_for_files(device):
    # XXX is this as_idle() safe?

    # prepare paths to add
    logging.debug('starting scan on %s', device.mount)
    known_files = clean_database(device)
    item_data = []
    start = time.time()

    def _continue():
        if not app.device_manager.running:  # user quit, so we will too
            logging.debug('stopping scan on %s: user quit', device.mount)
            return False
        if not os.path.exists(device.mount):  # device disappeared
            logging.debug('stopping scan on %s: disappeared', device.mount)
            return False
        if app.device_manager._is_hidden(device):  # device no longer being
            # shown
            logging.debug('stopping scan on %s: hidden', device.mount)
            return False
        return True

    for filename in fileutil.miro_allfiles(device.mount):
        short_filename = filename[len(device.mount):]
        ufilename = filename_to_unicode(short_filename)
        item_type = None
        if os.path.normcase(short_filename) in known_files:
            continue
        if filetypes.is_video_filename(ufilename):
            item_type = u'video'
        elif filetypes.is_audio_filename(ufilename):
            item_type = u'audio'
        if item_type is not None:
            item_data.append((ufilename, item_type))
            app.metadata_progress_updater.will_process_path(filename, device)
        if time.time() - start > 0.4:
            yield  # let other stuff run
            if not _continue():
                break
            start = time.time()

    if app.device_manager.running and os.path.exists(device.mount):
        # we don't re-check if the device is hidden because we still want to
        # save the items we found in that case
        yield  # yield after prep work

        device.database.setdefault(u'sync', {})
        logging.debug('scanned %s, found %i files (%i total)', device.mount,
                      len(item_data),
                      len(known_files) + len(item_data))

        device.database.set_bulk_mode(True)
        start = time.time()
        for ufilename, item_type in item_data:
            i = DeviceItem(video_path=ufilename,
                           file_type=item_type,
                           device=device)
            device.database[item_type][ufilename] = i.to_dict()
            device.database.emit('item-added', i)
            if time.time() - start > 0.4:
                device.database.set_bulk_mode(False)  # save the database
                yield  # let other idle functions run
                if not _continue():
                    break
                device.database.set_bulk_mode(True)
                start = time.time()

        device.database.set_bulk_mode(False)