コード例 #1
0
def get_paths1(objroot, objID, version):
    assert(objroot)
    prefix = objectstore.nameversiontoprefix(objroot, objID, version)
    pair   = os.path.split(os.path.normpath(prefix))
    parent = pair[0]
    paths  = objectstore.name_version_to_paths_aux(objroot, objID, version)
    paths  = list(paths)
    paths.append(parent)
    return paths
コード例 #2
0
def add_to_object_store(values, data, objectstoreroot, objectid, version,
                        auxDir, cloneVersion=False):
    """put (DATA, META, DONE) in the object store."""

    ##################################################
    # check free disk space.
    ##################################################
    if not cloneVersion and \
       not ryw_uploadObj.check_free_space(values, objectstoreroot):
        return (False, None, None, None, None, None)
    
    ##################################################
    # acquire prefix.
    ##################################################
    try:
        prefix = objectstore.nameversiontoprefix(objectstoreroot, objectid,
                                                 version)
    except:
        ryw.give_bad_news(
            'fatal_error: add_to_object_store: objectstore.nameversiontoprefix() failed.',
            logging.critical)
        return (False, None, None, None, None, None)
    
    datapath = prefix + '_DATA'
    metapath = prefix + '_META'
    donepath = prefix + '_DONE'
    auxpath  = prefix + '_AUXI'

    ##################################################
    # create parent directory.
    ##################################################
    parent = None
    try:
        parent = su.createparentdirpath(prefix)
        logging.debug('add_to_object_store: created parent dir: ' + parent)
    except:
        ryw.give_bad_news(
            'fatal_error: add_to_object_store: su.createparentdirpath() failed.',
            logging.critical)
        return (False, parent, None, None, None, None)
    
    if os.path.exists(donepath):
        ryw.give_news(
            'add_to_object_store: destination object already exists: ' +
            donepath, logging.warning)
        return (True, parent, datapath, metapath, auxpath, donepath)

    datapath = os.path.abspath(os.path.normpath(datapath))
    if (not cloneVersion):
        data = os.path.abspath(os.path.normpath(data))
        logging.debug('add_to_object_store: ' + datapath + ' ' +
                      metapath + ' ' + donepath + '.  source: ' + data)
    auxpath = os.path.abspath(os.path.normpath(auxpath))


    ##################################################
    # move data into the object store.
    ##################################################
    if cloneVersion:
        try:
            os.mkdir(datapath)
            ryw.db_print_info_browser('add_to_object_store: mkdir: ' +
                                      datapath, 29)
        except:
            ryw.give_bad_news(
                'fatal_error: add_to_object_store: cloneVersion mkdir: ' +
                datapath, logging.critical)
            return (False, parent, datapath, None, None, None)

        #
        # now deal with cloning a list, if necessary.
        #
        isList = ryw_meta.isList(values)
        if isList:
            baseName = os.path.basename(data)
            dirName = os.path.dirname(data)
            ryw.db_print2('UploadObject.add_to_object_store: basename: ' +
                          baseName, 44)
            ryw.db_print2('UploadObject.add_to_object_store: dirname: ' +
                          dirName, 44)
            destPath = os.path.join(datapath, baseName)
            srcChapterPath = os.path.join(dirName,
                                          ChapterList.CHAPTER_LIST_NAME)
            destChapterPath = os.path.join(datapath,
                                           ChapterList.CHAPTER_LIST_NAME)
            try:
                shutil.copyfile(data, destPath)
                ryw.db_print_info_browser(
                    'add_to_object_store: ' +
                    data + ' --> ' + destPath, 36)
                if os.path.exists(srcChapterPath):
                    shutil.copyfile(srcChapterPath, destChapterPath)
                    ryw.db_print_info_browser(
                        'UploadObject.add_to_object_store: ' +
                        srcChapterPath + ' --> ' + destChapterPath, 44)
                else:
                    ryw.db_print_info_browser(
                        'UploadObject.add_to_object_store: no chapter file.',
                        44)
            except:
                ryw.give_bad_news(
                    'add_to_object_store: failed to copy selection file.',
                    logging.critical)
                return (False, parent, datapath, None, None, None)
        
    elif os.path.isdir(data):
        try:
            mymove(data, datapath)
            logging.debug('add_to_object_store: moved dir: ' + data + ' ' +
                          datapath)
        except:
            ryw.give_bad_news(
                'fatal_error: add_to_object_store: move dir failed: ' +
                data + ' ' + datapath,
                logging.critical)
            return (False, parent, datapath, None, None, None)
        
    else:
        try:
            os.mkdir(datapath)
            mymove(data, os.path.join(datapath, os.path.basename(data)))
            logging.debug('add_to_object_store: moved file: ' + data + ' ' +
                          os.path.join(datapath, os.path.basename(data)))
        except:
            ryw.give_bad_news(
                'fatal_error: add_to_object_store: move file failed: ' +
                data + ' ' + datapath,
                logging.critical)
            return (False, parent, datapath, None, None, None)

    ##################################################
    # put metadata in the object store.
    ##################################################
    try:
        su.pickdump(values, metapath)
        logging.debug('add_to_object_store: written metapath: ' + metapath)
    except:
        ryw.give_bad_news(
            'fatal_error: add_to_object_store: su.pickdump() failed.',
            logging.critical)
        return (False, parent, datapath, metapath, None, None)

    ##################################################
    # put aux files in the object store.
    ##################################################
    try:
        if auxDir and os.path.exists(auxDir) and os.path.isdir(auxDir):
            mymove(auxDir, auxpath)
            logging.debug('add_to_object_store: moved auxpath: ' + auxpath)
    except:
        ryw.give_bad_news(
            'add_to_object_store: moving aux directory failed: ' + auxDir +
            ' -> ' + auxpath, logging.critical)
        return (False, parent, datapath, metapath, auxpath, None)


    ##################################################
    # put DONE flag in the object store.
    ##################################################
    try:
        f = open(donepath, 'w')
        f.close()
        logging.debug('add_to_object_store: written donepath: ' + donepath)
    except:
        ryw.give_bad_news(
            'fatal_error: add_to_object_store: write DONE file failed.',
            logging.critical)
        return (False, parent, datapath, metapath, auxpath, donepath)

    # TODO: In case of ANY failure, upload request copied to a REJECTED folder which can be looked upon later.

    return (True, parent, datapath, metapath, auxpath, donepath)