def _handle_directory(directory, handler, torrent_name): """ This is the main directory processing function. It's called by the _choose_handler function with the proper handling command for the files to process (copy/move). It searches for files in the directories matching the known extensions and moves the to the relevant path in the destination (/path/category/torrent_name) :param directory: :param handler: :param torrent_name: """ for directory_path, subdirectories, filenames in os.walk(directory): logger.info("Processing Directory %s" % directory_path) for filename in filenames: category_path = get_categorized_path(os.path.join(torrent_name, filename)) if category_path is not None: original_path = os.path.join(directory_path, filename) destination_dir = os.path.join(category_path, torrent_name) # Creates target directory (of category path) _create_extraction_path(destination_dir) destination_path = os.path.join(destination_dir, filename) try: # Move\Copy all relevant files to their location (keep original files for uploading) handler(original_path, destination_path) logger.info('%s %s to %s' % (handler.__name__, original_path, destination_path)) subprocess.check_output(['chmod', config.EXTRACTION_FILES_MASK, '-R', destination_dir]) except OSError as e: logger.exception("Failed to %s %s : %s" % (handler.__name__, original_path, e))
def process_file(handler, torrent_name, filepath): filename = os.path.basename(filepath) category_path = get_categorized_path(os.path.join(torrent_name, filename)) if category_path is not None: destination_dir = os.path.join(category_path, torrent_name) # Creates target directory (of category path) _create_extraction_path(destination_dir) destination_path = os.path.join(destination_dir, filename) try: # Move\Copy all relevant files to their location (keep original files for uploading) handler(filepath, destination_path) logger.info('%s %s to %s' % (handler.__name__, filepath, destination_path)) subprocess.check_output(['chmod', config.EXTRACTION_FILES_MASK, '-R', destination_dir]) except OSError as e: logger.exception("Failed to %s %s : %s" % (handler.__name__, filepath, e))
def _handle_directory(directory, handler, torrent_name): """ This is the main directory processing function. It's called by the _choose_handler function with the proper handling command for the files to process (copy/move). It searches for files in the directories matching the known extensions and moves the to the relevant path in the destination (/path/category/torrent_name) :param directory: :param handler: :param torrent_name: """ for directory_path, subdirectories, filenames in os.walk(directory): logger.info("Processing Directory %s" % directory_path) for filename in filenames: category_path = get_categorized_path( os.path.join(torrent_name, filename)) if category_path is not None: original_path = os.path.join(directory_path, filename) destination_dir = os.path.join(category_path, torrent_name) # Creates target directory (of category path) _create_extraction_path(destination_dir) destination_path = os.path.join(destination_dir, filename) try: # Move\Copy all relevant files to their location (keep original files for uploading) handler(original_path, destination_path) logger.info( '%s %s to %s' % (handler.__name__, original_path, destination_path)) subprocess.check_output([ 'chmod', config.EXTRACTION_FILES_MASK, '-R', destination_dir ]) except OSError as e: logger.exception("Failed to %s %s : %s" % (handler.__name__, original_path, e))
def process_file(handler, torrent_name, file_path): filename = os.path.basename(file_path) category_path = get_categorized_path(os.path.join(torrent_name, filename)) if category_path is not None: destination_dir = os.path.join(category_path, torrent_name) # Creates target directory (of category path) _create_extraction_path(destination_dir) destination_path = os.path.join(destination_dir, filename) try: # Move\Copy all relevant files to their location (keep original files for uploading) handler(file_path, destination_path) logger.info('%s %s to %s' % (handler.__name__, file_path, destination_path)) if sys.platform != 'win32': subprocess.check_output([ 'chmod', config.EXTRACTION_FILES_MASK, '-R', destination_dir ]) except OSError as e: logger.exception("Failed to %s %s : %s" % (handler.__name__, file_path, e))
pattern = re.compile(glob) for root, dirs, files in os.walk(path): for f in files: if pattern.search(f): fullpath = os.path.join(root,f) filename, filextention = os.path.splitext(fullpath) yield fullpath if __name__== "__main__": stats = {} mem_used = {} for origpath in gen_files("/mnt/usb/Downloads/complete/Orphan.Black.S01.720p.HDTV.x264-FF/_extracted/unpacked_1/", "mkv"): destpath = categorize.get_categorized_path(origpath) postprocess._create_extraction_path(os.path.dirname(destpath)) try: # Move\Copy all relevant files to their location (keep original files for uploading) print "move %s to %s" %(origpath, destpath) shutil.move(origpath, destpath) logger.info('%s %s to %s' % ("shutil.move", origpath, destpath)) subprocess.check_output(['chmod', config.EXTRACTION_FILES_MASK, '-R', os.path.dirname(destpath)]) except OSError as e: logger.exception("Failed to %s %s : %s" % ("shutil.move", origpath, e)) except IOError as e: logger.exception("Failed to %s %s : %s" % ("shutil.move", origpath, e)) try: