Пример #1
0
def main():
    """main function processing upload."""

    # initialization.
    name = WebUpload_ryw.print_header()
    form = cgi.FieldStorage()
    WebUpload_ryw.setup_logging()

    if not ryw_upload.check_required_fields(form, checkFile = False):
        ryw_upload.quick_exit(1)


    localExcerptResult = ryw_upload.check_local_file(
        form, fieldName = "local_excerpt_filename")

    # check aux file uploads: thumbnails, exerpts...
    success,auxExists,aux = ryw_upload.check_aux_file_uploads(
        form, localExcerptStuff = localExcerptResult)
    if not success:
        ryw_upload.quick_exit(1)

    tmpdir = WebUpload_ryw.attempt_make_tmpdir()
    if not tmpdir:
        ryw_upload.quick_exit(1)

    success,auxDir,auxInfo = ryw_upload.read_aux_files(
        form, aux, tmpdir, auxExists,
        localExcerptStuff = localExcerptResult)
    if not success:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)

    bytes,name = ryw_upload.copy_queue_file(tmpdir, name)
    if bytes == 0:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)
    kB = math.ceil(bytes / 1024.0)
    filename = name
        

    #
    # the rest of this stuff copied straight from WebUpload_ryw.py
    # not nice, but hey.
    #
    meta = ryw_upload.try_process_attributes(name, form, filename, kB, bytes)
    if not meta:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)
    ryw_upload.add_set_attrs(meta, 'sys_attrs', 'isList')

    meta = ryw_upload.add_aux_attributes(meta, auxInfo)

    success,metafile = ryw_upload.write_tmp_metafile(meta, tmpdir)
    if not success:
        ryw_upload.cleanup_and_exit(tmpdir, metafile, None, 1)
    
    nameToUpload,extractDir = ryw_upload.try_unzip_file(
        form, tmpdir, filename, kB)
    if not nameToUpload:
        ryw_upload.cleanup_and_exit(tmpdir, metafile, extractDir, 1)

    ryw.give_news2('<BR>Storing the list in the repository...',
                   logging.info)
    if not WebUpload_ryw.try_upload_object(meta, nameToUpload, auxDir):
        ryw_upload.cleanup_and_exit(tmpdir, metafile, extractDir, 1)

    #ryw_view.show_server_object(meta)
    searchFile = WebUpload_ryw.show_one_server_object(meta)
    #
    # Ok to do this stuff after the display, because there's no
    # way the newly added selection could be a containee of someone else.
    #
    ReverseLists.add_queue(meta, searchFile, RepositoryRoot)
    searchFile.done()

    ryw_upload.cleanup_and_exit(tmpdir, metafile, extractDir, 0)
Пример #2
0
def main():

    name = print_header()
    form = cgi.FieldStorage()
    WebUpload_ryw.setup_logging()


    #
    # get objstr.
    #
    success,objID,version = ryw.get_obj_str2(form)
    if not success:
        ryw.give_bad_news('CloneVersion: failed to get objstr.',
                          logging.critical)
        ryw_upload.quick_exit(1)

    message = 'CloneVersion: ' + objID + '#' + str(version)
    logging.info(message)
    ryw.db_print2("<BR>" + message + "<BR>", 23);


    #
    # open search file.
    #
    success,searchFile = ryw.open_search_file(
        'CloneVerson',
        os.path.join(RepositoryRoot, 'WWW', 'logs'),
        'upload.log',
        os.path.join(RepositoryRoot, 'SearchFile'),
        False)
    if not success:
        if searchFile:
            searchFile.done()
        ryw.give_bad_news('CloneVersion: ' +
                          'open search file failed. ',
                          logging.critical)
        ryw_upload.quick_exit(1)
    else:
        ryw.db_print2("search file opened." + "<BR>", 23);


    #
    # get meta and paths.
    #
    success,paths,meta = DisplaySelection.get_all_paths(
        objID, version, skipLock=False, searchFile=searchFile,
        allowNullSearchFile=False)
    if success:
        ryw.db_print_info_browser('CloneVersion: paths: ' + repr(paths), 24)
        ryw.db_print_info_browser('CloneVersion: meta: ' + repr(meta), 29)
    else:
        ryw_upload.quick_exit(1)
        
    if (searchFile):
        searchFile.done()


    #
    # we do want to clone the data if it were a list.
    #
    isList = ryw_meta.isList(meta)
    if isList:
        dataPath = paths[0]
        selName = DisplaySelection.get_sel_name(dataPath)
        if not selName:
            ryw.give_bad_news(
                'CloneVersion: isList but failed to get selection name.',
                logging.error)
            ryw_upload.quick_exit(1)
        selPath = os.path.join(dataPath, selName)
    else:
        selPath,selName = None,None
            

    #
    # change meta.
    #
    meta = change_meta(meta, name)
                                   

    #
    # deal with auxi dir.
    #
    originalAuxiDir = paths[2]
    newAuxiDir = None
    tmpdir = None
    if os.path.exists(originalAuxiDir):
        tmpdir = WebUpload_ryw.attempt_make_tmpdir()
        if not tmpdir:
            ryw_upload.quick_exit(1)
        newAuxiDir = os.path.join(tmpdir, '_AUXI')

        message = 'CloneVersion: shutil.copytree(): ' + \
                  originalAuxiDir + '  ->  ' + newAuxiDir

        try:
            shutil.copytree(originalAuxiDir, newAuxiDir)
        except:
            ryw.give_bad_news('failed: ' + message, logging.critical)
            ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)

        ryw.db_print_info_browser(message, 29)            
                              

    #
    # Now try to put a new object in the repository.
    # note that the version number will be incremented.
    #
    # "selPath" used to be just None.
    # when I added cloning list, I'm just using this to pass in the
    # path name of the selection file.
    #
    if not WebUpload_ryw.try_upload_object(meta, selPath, newAuxiDir,
                                           cloneVersion=True):
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)


    searchFile = WebUpload_ryw.show_one_server_object(meta)
    searchFile.done()
        
    ryw_upload.cleanup_and_exit(tmpdir, None, None, 0,
                                successMessage = 'clone version completed.')
Пример #3
0
def main():
    """main function processing upload."""

    # initialization.
    name = print_header()
    form = cgi.FieldStorage()
    setup_logging()

    localSuccess, localFound, localFilePath, localIsDir = ryw_upload.check_local_file(form)
    if not localSuccess:
        ryw.give_bad_news("check_local_file failed.", logging.error)
        ryw_upload.quick_exit(1)

    if not ryw_upload.check_required_fields(form, checkFile=not localFound):
        ryw_upload.quick_exit(1)

    if localFound:
        buf = None
    else:
        # just read a tiny bit to see if we have an empty upload file.
        buf = ryw_upload.attempt_read_uploaded_file(form, "local_filename")
        if not buf:
            ryw_upload.quick_exit(1)

    localExcerptResult = ryw_upload.check_local_file(form, fieldName="local_excerpt_filename")

    # check aux file uploads: thumbnails, exerpts...
    success, auxExists, aux = ryw_upload.check_aux_file_uploads(form, localExcerptStuff=localExcerptResult)
    if not success:
        ryw_upload.quick_exit(1)

    tmpdir = attempt_make_tmpdir()
    if not tmpdir:
        ryw_upload.quick_exit(1)

    success, auxDir, auxInfo = ryw_upload.read_aux_files(
        form, aux, tmpdir, auxExists, localExcerptStuff=localExcerptResult
    )
    if not success:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)

    filename = ryw_upload.decide_tmp_data_file_name(form, localPath=localFilePath, isLocalDir=localIsDir)
    if not filename:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)

    success, found, bytes = ryw_upload.copy_local_file_for_upload(
        form, tmpdir, filename, localFound, localFilePath, localIsDir
    )
    if not success:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)
    kB = math.ceil(bytes / 1024.0)

    if not found:
        ryw.give_news2("<BR>Copying remote file...", logging.info)
        kB, bytes = ryw_upload.read_uploaded_file(form, buf, tmpdir, filename, "local_filename")
    if kB == 0:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)

    meta = ryw_upload.try_process_attributes(name, form, filename, kB, bytes)
    if not meta:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)

    meta = ryw_upload.add_aux_attributes(meta, auxInfo)

    if not localIsDir:
        ryw_ffmpeg.try_exec(RepositoryRoot, meta, tmpdir, filename)

    success, metafile = ryw_upload.write_tmp_metafile(meta, tmpdir)
    if not success:
        ryw_upload.cleanup_and_exit(tmpdir, metafile, None, 1)

    if localIsDir:
        nameToUpload, extractDir = (os.path.join(tmpdir, filename), None)
    else:
        nameToUpload, extractDir = ryw_upload.try_unzip_file(form, tmpdir, filename, kB)
        if not nameToUpload:
            ryw_upload.cleanup_and_exit(tmpdir, metafile, extractDir, 1)

    ryw.give_news2("<BR>Storing the data in the repository...", logging.info)
    ryw.db_print2("<BR>" + "meta: " + repr(meta) + "<BR>", 57)
    ryw.db_print2("nameToUpload: " + nameToUpload + "<BR>", 22)
    ryw.db_print2("auxDir: " + repr(auxDir) + "<BR>", 22)
    if not try_upload_object(meta, nameToUpload, auxDir):
        ryw_upload.cleanup_and_exit(tmpdir, metafile, extractDir, 1)

    # ryw_view.show_server_object(meta)
    searchFile = show_one_server_object(meta)
    searchFile.done()

    # cgi.print_form(form)

    ryw_upload.cleanup_and_exit(tmpdir, metafile, extractDir, 0)