def out_init(tmpImgDir): dataRoot = os.path.join(tmpImgDir, dataDirName) auxiRoot = os.path.join(tmpImgDir, auxiDirName) if not ryw.try_mkdir(dataRoot, 'out_init: '): return (False, None, None, None, 0) if not ryw.try_mkdir(auxiRoot, 'out_init: '): return (False, None, None, None, 0) logging.debug('out_init: created data and auxi roots: ' + dataRoot + ' ' + auxiRoot) mapDict = {} counter = 0 return (True, dataRoot, auxiRoot, mapDict, counter)
def addRobotWriteRequest(name, items, itempath, currentSize, tmpStoreName, tmpDirOption = '', onlyMeta = False): logging.debug('addRobotWriteRequest: entered...') success,resources,robotJobsDir,tmpOutDir,searchFile,viewRoot,firstRoot, \ robotPresent = get_resources(tmpDirOption = tmpDirOption) if not success: return (False, None, None) if not onlyMeta and not check_free_disk_space(currentSize, tmpOutDir): return (False, None, None) tmpImgDir,objPrefix = ryw_upload.attempt_just_make_tmpdir( tmpOutDir, 'Im_'+name[:3]+'_', '') if not tmpImgDir: return (False, None, None) ryw.give_news2('<BR>outgoing data image name: ' + tmpImgDir, logging.info) if not write_recipient_file(tmpImgDir, name): cleanup_image(tmpImgDir) return (False, None, None) repDir = os.path.join(tmpImgDir, 'repository') if not ryw.try_mkdir(repDir, 'addRobotWriteRequest'): cleanup_image(tmpImgDir) return (False, None, None) # noObjStore: # not copy_objectstore(firstRoot, repDir, tmpStoreName) or \ # not copy_view(repDir, viewRoot) or \ if not write_user_credentials(repDir, name) or \ not copy_scripts(repDir) or \ not copy_search_file(searchFile, repDir) or \ not copy_reverse_lists(repDir) or \ not copy_objects(items, itempath, repDir, tmpImgDir, metaOnly = onlyMeta) or \ not generate_html(items, itempath, repDir, tmpImgDir) or \ not copy_autorunfiles(tmpImgDir): cleanup_image(tmpImgDir) return (False, None, None) ryw.give_news(' ', logging.info) ryw.give_news('done copying all data, now invoking the robot.', logging.info) # success,jrq = write_robot_job_file(robotJobsDir, tmpImgDir, objPrefix, robotPresent = robotPresent) # if not success: # cleanup_image(tmpImgDir) # ryw.cleanup_path(jrq, 'addRobotWriteRequest:') # return (False, None, None) return (True, tmpImgDir, "blah")
def copy_script_dir(repDir, srcDirName, dstDirName): logging.debug('copy_script_dir: ' + srcDirName + ' -> ' + dstDirName) dstDirPath = os.path.join(repDir, dstDirName) if not ryw.try_mkdir(dstDirPath, 'copy_script_dir:'): return False srcDirPath = os.path.join(RepositoryRoot, srcDirName) try: scripts = os.listdir(srcDirPath) except: ryw.give_bad_news('copy_script_dir: os.listdir failed.', logging.critical) return False for s in scripts: if s != 'update.py' and s != 'CVS' and s != 'cvs': logging.debug('copy_script_dir: copying... ' + s) src = os.path.join(srcDirPath, s) dst = os.path.join(dstDirPath, s) try: if os.path.isdir(src): sDir = os.path.join(srcDirName, s) dDir = os.path.join(dstDirName, s) if not copy_script_dir(repDir, sDir, dDir): ryw.give_bad_news( \ 'copy_script_dir: recursion failed: ' + \ repDir + ' ' + sDir + ' -> ' + dDir, \ logging.error) return False else: shutil.copyfile(src, dst) except: ryw.give_bad_news('copy_script_dir: failed to copy ' + s, logging.critical) return False logging.debug('copy_script_dir: done.') return True
def generate_html(items,itempath, repDir, tmpImgDir): ryw.give_news2('generating static html pages... ', logging.info) htmlDir = os.path.join(repDir, "html") if not ryw.try_mkdir(htmlDir, 'addRobotWriteRequest:generate_html'): return False try: f = open(os.path.join(htmlDir,"index.html"),"w") f.write(""" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Objects on this disk</title> """) f.write(ryw_view.css_str()) f.write(""" </head> <body> """) f.write(ryw_view.logo_str_for_disc()) f.write(""" <h3>Objects on Disk</h3><p>(you are on this page either because you are browsing the disc directly or were directed to it due to an error while merging it.) <BR> """) write_page(items,itempath,f, tmpImgDir) f.write(ryw_view.end_print_str()) f.write(ryw_view.footer2_str()) f.write(""" </body> </html> """) f.close() srcIconsDir = os.path.join(RepositoryRoot, "WWW", "icons") dstIconsDir = os.path.join(htmlDir, "icons") su.copytree(srcIconsDir, dstIconsDir) parentDir, repdirname = os.path.split(repDir) f = open(os.path.join(parentDir,"index.html"), "w") f.write(""" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title> Repository folders on this disk </title> <meta http-equiv="refresh" content="1;URL=.\%s\html\index.html"> </head> <body> loading page containing list of things on this disk.... </body> </html> """ % (repdirname,)) f.close() except: ryw.give_bad_news('addRobotWriteRequest: generate_html files: failed to write file: ',logging.critical) return False ryw.give_news2('done. ', logging.info) ryw.give_news2('<BR>', logging.info) return True