def cleanup_list(wdir, skip_nzb): """ Remove all files whose extension matches the cleanup list, optionally ignoring the nzb extension """ if cfg.cleanup_list(): try: files = os.listdir(wdir) except: files = () for filename in files: path = os.path.join(wdir, filename) if os.path.isdir(path): cleanup_list(path, skip_nzb) else: if on_cleanup_list(filename, skip_nzb): try: logging.info("Removing unwanted file %s", path) remove_file(path) except: logging.error(T('Removing %s failed'), clip_path(path)) logging.info("Traceback: ", exc_info=True) if files: try: remove_dir(wdir) except: pass
def cleanup_list(wdir, skip_nzb): """ Remove all files whose extension matches the cleanup list, optionally ignoring the nzb extension """ if cfg.cleanup_list(): try: files = os.listdir(wdir) except: files = () for file in files: path = os.path.join(wdir, file) if os.path.isdir(path): cleanup_list(path, skip_nzb) else: if on_cleanup_list(file, skip_nzb): try: logging.info("Removing unwanted file %s", path) os.remove(path) except: logging.error(Ta('Removing %s failed'), path) logging.info("Traceback: ", exc_info = True) if files: try: remove_dir(wdir) except: pass
def test_on_cleanup_list(self): assert misc.on_cleanup_list("test.exe") assert misc.on_cleanup_list("TEST.EXE") assert misc.on_cleanup_list("longExeFIlanam.EXe") assert not misc.on_cleanup_list("testexe") assert misc.on_cleanup_list("test.nzb") assert not misc.on_cleanup_list("test.nzb", skip_nzb=True) assert not misc.on_cleanup_list("test.exe.lnk")