def _import_media(db, args):
    '''
    Import media files

    Must be called after _import_database()
    '''
    _log.info('-> Importing media...')

    media_cache = BasicFileStorage(
        args._cache_path['media'])

    # TODO: Add import of queue files
    queue_cache = BasicFileStorage(args._cache_path['queue'])

    for entry in db.MediaEntry.query.filter_by():
        for name, path in entry.media_files.items():
            _log.info('Importing: {0} - {1}'.format(
                    entry.title.encode('ascii', 'replace'),
                    name))

            media_file = mg_globals.public_store.get_file(path, mode='wb')
            media_file.write(
                media_cache.get_file(path, mode='rb').read())

    _log.info('...Media imported')
def _import_media(db, args):
    '''
    Import media files

    Must be called after _import_database()
    '''
    _log.info('-> Importing media...')

    media_cache = BasicFileStorage(
        args._cache_path['media'])

    # TODO: Add import of queue files
    queue_cache = BasicFileStorage(args._cache_path['queue'])

    for entry in db.MediaEntry.query.filter_by():
        for name, path in entry.media_files.items():
            _log.info('Importing: {0} - {1}'.format(
                    entry.title.encode('ascii', 'replace'),
                    name))

            media_file = mg_globals.public_store.get_file(path, mode='wb')
            media_file.write(
                media_cache.get_file(path, mode='rb').read())

    _log.info('...Media imported')
def _export_media(db, args):
    _log.info('-> Exporting media...')

    media_cache = BasicFileStorage(args._cache_path['media'])

    # TODO: Add export of queue files
    queue_cache = BasicFileStorage(args._cache_path['queue'])

    for entry in db.MediaEntry.query.filter_by():
        for name, path in entry.media_files.items():
            _log.info(u'Exporting {0} - {1}'.format(entry.title, name))
            try:
                mc_file = media_cache.get_file(path, mode='wb')
                mc_file.write(
                    mg_globals.public_store.get_file(path, mode='rb').read())
            except Exception as e:
                _log.error('Failed: {0}'.format(e))

    _log.info('...Media exported')
def _export_media(db, args):
    _log.info('-> Exporting media...')

    media_cache = BasicFileStorage(
        args._cache_path['media'])

    # TODO: Add export of queue files
    queue_cache = BasicFileStorage(args._cache_path['queue'])

    for entry in db.MediaEntry.query.filter_by():
        for name, path in entry.media_files.items():
            _log.info(u'Exporting {0} - {1}'.format(
                    entry.title,
                    name))
            try:
                mc_file = media_cache.get_file(path, mode='wb')
                mc_file.write(
                    mg_globals.public_store.get_file(path, mode='rb').read())
            except Exception as e:
                _log.error('Failed: {0}'.format(e))

    _log.info('...Media exported')