Esempio n. 1
0
def get_obj_size(itempath):
    if not os.path.exists(itempath[1]):
        ryw.give_bad_news("get_obj_size: data path does not exist: " + itempath[0], logging.critical)
        return (False, 0)

    dataPath = os.path.normpath(itempath[1])
    parent, tail = os.path.split(dataPath)
    logging.debug("get_obj_size: parent dir is: " + parent)

    itemSize = ryw_disc.getRecursiveSizeInKB(parent)
    itemSize += 4

    logging.debug("get_obj_size: kB: " + str(itemSize))
    return (True, itemSize)
Esempio n. 2
0
def obj_store_size_inKB_not_used(tmpdir=""):
    if tmpdir:
        ryw.give_news2('temp objectstore copied to: ' + tmpdir + '<BR>',
                       logging.info)
    ryw.give_news2('computing outgoing objectstore size...',
                   logging.info)
    
    try:
        resources = su.parseKeyValueFile(os.path.join(RepositoryRoot,
                                                      'Resources.txt'))
        objectstoreroots = resources['objectstore'].split(';')
        firstRoot = objectstoreroots[0]
        if tmpdir:
                tmpOutDir = tmpdir
        else:
                tmpOutDir = resources['tmpout']
    except:
        ryw.give_bad_news('obj_store_size_inKB: get_resources failed.',
                          logging.critical)
        return (False, None, None, None)

    tmpStoreDir,objPrefix = ryw_upload.attempt_just_make_tmpdir(
        tmpOutDir, 'outgoing_obj_store_', '')
    if not tmpStoreDir:
        ryw.give_bad_news('obj_store_size_inKB: failed to make tmpdir: ' +
                          tmpOutDir, logging.critical)
        return (False, None, None, None)

    tmpStoreName = os.path.join(tmpStoreDir, 'outgoing_store')

    try:
        success = ryw_copytree.copy_tree_diff_repo(firstRoot, tmpStoreName)
        if not success:
            raise 'copy_tree_diff_repo failed.'
    except:
        ryw.give_bad_news('obj_store_size_inKB: copy_tree_diff_repo failed: '+
                          firstRoot + ' -> ' + tmpStoreName, logging.critical)
        return (False, None, None, None)

    kB = ryw_disc.getRecursiveSizeInKB(tmpStoreName)
    logging.debug('obj_store_size_inKB: ' + tmpStoreName + ' = ' + str(kB))

    ryw.give_news2 (str(kB) + ' KB<BR>', logging.info)
    return (True, kB, tmpStoreDir, tmpStoreName)
Esempio n. 3
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)
Esempio n. 4
0
def get_KB_str(dir):
    kB = ryw_disc.getRecursiveSizeInKB(dir)
    kB = str(kB)
    if kB[-1] == "L":
        kB = kB.replace("L", "")
    return kB