Ejemplo n.º 1
0
def copy_queue_file(tmpdir, name):
    
    rfpath = os.path.join(RepositoryRoot, 'QUEUES', name)
    if not ryw.is_valid_file(rfpath, 'copy_queue_file'):
        ryw.give_bad_news('copy_queue_file: queue file invalid: ' + rfpath,
                          logging.error)
        return (0, '')
    
    freeKB = ryw.free_MB(tmpdir) * 1024
    success,bytes = ryw.get_file_size(rfpath)
    if not success:
        return (0, '')
    kB = math.ceil(bytes / 1024.0)

    if pretty_much_out_of_space(kB, freeKB):
        ryw.give_bad_news(
            'user_error: nearly out of space while uploading queue, KB: ' + repr(kB), logging.error)
        return (0, '')

    #appendedName = name + '_selection'
    appendedName = 'saved_selection'
    tmpFileName = os.path.join(tmpdir, appendedName)
    try:
        shutil.copyfile(rfpath, tmpFileName)
    except:
        ryw.give_bad_news('copy_queue_file: failed to copy queue file: ' +
                          rfpath + ' -> ' + tmpFileName,
                          logging.critical)
        return (0, '')

    return (bytes, appendedName)
Ejemplo n.º 2
0
def check_local_file(form, fieldName = 'repeat_local_filename'):
    if not form.has_key(fieldName):
        return (True, False, None, False)

    localName = form.getfirst(fieldName, '')
    if localName == '':
        return (True, False, None, False)

    success,isFile,isDir = ryw.is_valid_file_or_dir(
        localName, msg='check_local_file')
    if not success:
        return (False, False, None, False)
    localName = os.path.normpath(localName)

    if isFile:
        success,bytes = ryw.get_file_size(localName)
        if not success:
            return (False, False, None, False)
        if bytes == 0:
            ryw.give_bad_news('check_local_file: zero-sized file: '+
                              localName, logging.error)
            return (False, False, None, False)
        return (True, True, localName, False)

    return (True, True, localName, True)
Ejemplo n.º 3
0
def re_extract(dataPath, fileName, meta):
    if meta.has_key('ffmpeg'):
        del meta['ffmpeg']
    if meta.has_key('time_length'):
        del meta['time_length']
    if meta.has_key('time_length_seconds'):
        del meta['time_length_seconds']

    ryw_ffmpeg.try_exec(RepositoryRoot, meta, dataPath, fileName)

    success,bytes = ryw.get_file_size(os.path.join(dataPath, fileName))
    if success:
        meta['bytes'] = bytes
        meta['kB'] = math.ceil(bytes / 1024.0)
Ejemplo n.º 4
0
def copy_local_file_for_upload(form, tmpdir, uploadFileName,
                               localFound, localPath, localDir,
                               isCopyingExcerpt = False):
    if not localFound:
        return (True, False, 0)

    if localDir:
        dirKB = ryw_disc.getRecursiveSizeInKB(localPath)
        bytes = dirKB * 1024
        if bytes == 0:
            ryw.give_bad_news(
                'copy_local_file_for_upload: 0-sized local directory: '+
                localPath, logging.error)
            return (False, False, 0)
    else:
        success,bytes = ryw.get_file_size(localPath)
        if not success:
            return (False, False, 0)

    #if uploadFileName != truncateLocalName:
    #    ryw.give_bad_news(
    #        'copy_local_file_for_upload: repeated local file name does<BR>' +
    #        ' not match the name of the local file to be uploaded.<BR>' +
    #        uploadFileName + '<BR>' + localName,
    #        logging.error)
    #    return (False, False, 0)
    
    freeKB = ryw.free_MB(tmpdir) * 1024
    kB = math.ceil(bytes / 1024.0)

    if pretty_much_out_of_space(kB, freeKB):
        ryw.give_bad_news(
            'copy_local_file_for_upload: nearly out of space ' +
            'while uploading queue, KB: ' + repr(kB), logging.error)
        return (False, False, 0)

    tmpFileName = os.path.join(tmpdir, uploadFileName)
    try:
        if localDir:
            ryw.give_news2('<BR>Copying local directory: ' + localPath,
                           logging.info)
            if isCopyingExcerpt:
                #
                # don't want the "excerpts" directory to contain
                # just a lone directory inside in the common case.
                # copy the content into the "excerpts" directory directly.
                # "tmpdir" in this case is the "excerpts" directory.
                # su.copytree tolerates an existing destination directory
                # and doesn't wipe out what's already in it.
                #
                tmpFileName = os.path.normpath(tmpdir)
                su.copytree(localPath, tmpFileName)
            else:
                shutil.copytree(localPath, tmpFileName)
        else:
            ryw.give_news2('<BR>Copying local file: ' + localPath,
                           logging.info)
            shutil.copyfile(localPath, tmpFileName)
            #shutil.copyfile(
            #    os.path.join(RepositoryRoot, 'Tmp-in', 'foo.txt'),
            #    tmpFileName)
    except:
        ryw.give_bad_news('copy_local_file_for_upload: ' +
                          'failed to copy data: ' +
                          localPath + ' -> ' + tmpFileName,
                          logging.critical)
        return (False, False, 0)

    logging.debug('copy_local_file_for_upload: ' +
                  'succeeded copying local data: ' +
                  localPath + ' -> ' + tmpFileName, logging.info)
    return (True, True, bytes)