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.')
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)