def append_tar_media_xml_element(doc, filepath, domain, media_id): mediaElement = doc.createElement(domain) mediaElement.setAttribute('_id', media_id) mediaElement.setAttribute('md5', ltoUtil.get_md5_hash(filepath)) mediaElement.setAttribute('size', str(ltoUtil.get_filesize(filepath))) mediaElement.setAttribute('filename', ltoUtil.get_filename(filepath)) doc.documentElement.appendChild(mediaElement) par2TarElement = doc.createElement('par2Tar') par2TarElement.setAttribute('md5', ltoUtil.get_md5_hash(filepath+'.par2.tar')) par2TarElement.setAttribute('size', str(ltoUtil.get_filesize(filepath+'.par2.tar'))) par2TarElement.setAttribute('filename', ltoUtil.get_filename(filepath)+'.par2.tar') mediaElement.appendChild(par2TarElement)
def create_tape_index(tape_xml_doc, config): tars = [] for t in os.listdir(ltoUtil.get_tape_build_dir(config)): if t.endswith('.tar'): tars.append(t) tars.sort() block_size_bytes = int(config.get('Tape', 'block_size_bytes')) index_size_mb = int(config.get('Tape', 'index_size_mb')) index_size_bytes = index_size_mb * 1024*1024 current_block = index_size_bytes/block_size_bytes +1 for index, tar in enumerate(tars): tar_name = tar[0:-4] position = index+2 size = ltoUtil.get_filesize(os.path.join(ltoUtil.get_tape_build_dir(config), tar)) blocks = int(size/block_size_bytes) tar_xml_path = os.path.join(ltoUtil.get_tape_build_dir(config), tar_name+'.xml') append_tar_element_to_tape_xml_doc(tape_xml_doc, tar_xml_path, position, current_block) current_block += blocks + 1
def media_file_types_check(config, category, path): category_filetypes = config.get('CategoryFileTypes', category).split(',') media_file_count = 0 total_file_size = 0 non_category_files = [] for dirpath, dirnames, filenames in os.walk(path): for file in filenames: if media_in_domain(file, 'video', config) or media_in_domain(file, 'audio', config) or media_in_domain(file, 'image', config): if not media_in_category(file, category, config): non_category_files.append(os.path.join(dirpath, file)) else: media_file_count += 1 total_file_size += ltoUtil.get_filesize(os.path.join(dirpath, file)) free_bytes = ltoUtil.get_freespace(ltoUtil.get_tar_build_dir(config)) if (len(non_category_files) > 0): print 'WARNING: The following unexpected media files were found in the folder: '+path+'\n' for f in non_category_files: print f print '\nExpecting only '+string.upper(string.join(category_filetypes, ','))+' files for "'+category+'" category.' print '\nNOTE: This situation should only occur if when one device has generated multiple media formats. (e.g. a video camera taking stills/audio as well as video)' print 'Usually this indicates that the files have been misplaced, in which case the user should manually remove them before re-running the script.\n' proceed = raw_input('Do you still want to proceed, including these files in the archive? [y/n]: ') if proceed == 'y': return else: print ltoUtil.get_script_name()+' script terminated.' sys.exit(2) elif media_file_count == 0: print 'No recognised media files were found in: '+path print ltoUtil.get_script_name()+' script terminated.' sys.exit(2) elif total_file_size > free_bytes - (1024*1024): print 'The total file size of the media files to be archived ('+ltoUtil.format_bytes_to_gbs(total_file_size)+') exceeds the free space available in '+ltoUtil.get_tar_build_dir(config)+' ('+ltoUtil.format_bytes_to_gbs(free_bytes)+').' print ltoUtil.get_script_name()+' script terminated.' sys.exit(2)
def update_tar_xml_root_attributes(config, doc, tar_name): doc.documentElement.setAttribute('md5', ltoUtil.get_md5_hash(ltoUtil.get_tar_build_dir(config)+'/'+tar_name)) doc.documentElement.setAttribute('size', str(ltoUtil.get_filesize(ltoUtil.get_tar_build_dir(config)+'/'+tar_name)))