def create_tar_archive(config, session_id, device_code, tar_xml_doc): ref_file_name = session_id+'-'+device_code+'-referenced-items.xml' tar_name = session_id+'-'+device_code+'.tar' tar_path = ltoUtil.get_tar_build_dir(config)+'/'+tar_name block_size_bytes = int(config.get('Tape', 'block_size_bytes')) blocking_factor = block_size_bytes/512 filelist = [] for file in os.listdir(ltoUtil.get_tar_build_dir(config)): filelist.append(file) filelist.remove(ref_file_name) filelist.sort() filelist_str = ref_file_name+' '+string.join(filelist, ' ') print '\nCreating tar archive: '+tar_path p = subprocess.Popen('tar -cvR -b '+str(blocking_factor)+' --format='+ltoUtil.get_tar_format(config)+' -C '+ltoUtil.get_tar_build_dir(config)+' -f '+tar_path+' '+filelist_str, shell=True, stdout=subprocess.PIPE) stdout_value = p.stdout.readlines() del stdout_value[0] for line in stdout_value: update_block_xml_attributes(tar_xml_doc, line, config) update_tar_xml_root_attributes(config, tar_xml_doc, tar_name)
def generate_par2_tar(config, new_filepath): par2_redundancy = config.getint('Par2', 'redundancy') par2_numfiles = config.getint('Par2', 'num_files') par2_memory = config.getint('Par2', 'memory') fn = ltoUtil.get_filename(new_filepath) path = ltoUtil.get_path(new_filepath) print 'Generating PAR2 files for '+fn+'\n' p = subprocess.Popen('par2 create -r'+str(par2_redundancy)+' -m'+str(par2_memory)+' -n'+str(par2_numfiles)+' '+new_filepath, shell=True) sts = os.waitpid(p.pid, 0) par2files = [] for f in os.listdir(path): if str(f).startswith(fn) and str(f).endswith('.par2'): par2files.append(f) par2filesstr = string.join(par2files, ' ') p = subprocess.Popen('tar -c --format='+ltoUtil.get_tar_format(config)+' -C '+path+' -f '+new_filepath+'.par2.tar '+par2filesstr, shell=True) sts = os.waitpid(p.pid, 0) for p in par2files: os.remove(os.path.join(path, p))