def createdummyobject(root, name, version): assert isvalidname(name) a, b, c = nameversiontopaths(root, name, version) su.createparentdirpath(a) os.mkdir(a) os.system('echo ss > ' + b) os.system('echo ss > ' + c)
def create_view_path(path, objectID, version): if os.path.exists(path): ryw.give_news('create_view_path: already exists: ' + path + ', ' + 'replacing with new version.', logging.warning) #return True #remove old view path and continue if not ryw.cleanup_path(path, 'create_view_path:'): ryw.give_news('create_view_path: fails to remove old view path.', logging.error) return True try: su.createparentdirpath(path) except: ryw.give_bad_news('create_view_path: failed to createparentdirpath: '+ path, logging.critical) return False try: f = open(path, 'w') f.write(objectID + '#' + str(version)) f.close() except: ryw.give_bad_news('create_view_path: failed to write leaf file: '+path, logging.critical) return False logging.debug('create_view_path: done creating path: '+path) return True
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)
def copy_objects(items, itempath, repDir, tmpImgDir, metaOnly = False): ryw.give_news2('copying requested objects... ', logging.info) # # quite a bit of the copying details should be pulled out to a piece # of common code. # if len(items) == 0: ryw.give_news2('no requested objects. ', logging.info) ryw.give_news2('<BR>', logging.info) return True success,dataRoot,auxiRoot,mapDict,counter = ryw_philips.out_init(tmpImgDir) if not success: ryw.give_bad_news('copy_objects: out_init failed.', logging.error) return True for item in items: logging.debug('copy_objects: item: ' + item) try: objname,version = item.split('#') version = int(version) logging.debug('copy_objects: got name, version: ' + objname + ' ' + repr(version)) #destpath = objectstore.nameversiontopaths( # os.path.join(repDir, 'objects'), objname, version) destpath = objectstore.name_version_to_paths_aux( os.path.join(repDir, 'objects'), objname, version) logging.debug('copy_objects: got destpath: ' + repr(destpath)) if not ryw.good_repo_paths(itempath[item]): ryw.give_bad_news('copy_objects: good_repo_paths failed.', logging.error) raise('something missing in the source paths.') su.createparentdirpath(destpath[0]) logging.debug('copy_objects: created parent dir: ' + destpath[0]) # code prior to preparing for Philips DVD player # su.copytree(itempath[item][0], destpath[0]) # logging.debug('copy_objects: done copying data: ' + destpath[0]) counter,mapDict = \ ryw_philips.out_copy(item, itempath[item][0], itempath[item][1], itempath[item][2], counter, dataRoot, auxiRoot, mapDict, onlyMeta = metaOnly) shutil.copyfile(itempath[item][1], destpath[1]) logging.debug('copy_objects: done copying metadata: ' + destpath[1]) # code prior to preparing for Philips DVD player # if os.path.exists(itempath[item][2]): # su.copytree(itempath[item][2], destpath[2]) # logging.debug('copy_objects: done copying auxi files: ' + # destpath[2]) shutil.copyfile(itempath[item][3], destpath[3]) logging.debug('copy_objects: done copying done flag: ' + destpath[3]) except: ryw.give_bad_news( 'copy_objects: failed to copy data: ' + item, logging.critical) ryw.give_bad_news( 'copy_objects: skip copying an object and continue.', logging.error) continue ryw_philips.out_done(tmpImgDir, mapDict) ryw.give_news2('done. ', logging.info) ryw.give_news2('<BR>', logging.info) return True