def main(): args_parser = argparse.ArgumentParser() parser = argparse.ArgumentParser() parser.add_argument("path", nargs='+', help="Path where to look for duplicates.") parser.add_argument("-u", "--uniques", action="store_true", help="Find unique files.") parser.add_argument("-k", "--keep", action="append", required=True, help='Paths to keep.') parser.add_argument("-f", "--force", help='Force deletion.') parser.add_argument( "--non-strict", action="store_true", default=False, # Strict mode by default help="Strict mode. Fails if there are nonreadable entries in the path." ) # parser.add_argument( # "-v", # "--verbosity", # help="Verbosity level (default: WARN)", # default='WARN', # choices=['DEBUG','INFO','WARN','ERROR','CRITICAL'], # type=lambda level: level.upper() # ) # # logging.basicConfig( # level=args.verbosity, # format=args.log_format, # filename=args.log # ) args = parser.parse_args() strict_walk = not args.non_strict where = args.path protected = args.keep dry_run = True cleanup_files(where, selected=keep(*protected), dry_run=dry_run, strict_walk=strict_walk)
def _run_test(self, cluster, expected, *keep_path): try: keep_func = keep(*keep_path) result = set(keep_func(cluster)) except WalkError as e: result = e logger, test_name = _getLogger(self) title = '==================== {} ===================='.format(test_name) logger.debug(title) logger.debug(' keep_path: {}'.format(keep_path)) logger.debug(' cluster: {}'.format(cluster)) logger.debug(' expected disposable: {}'.format(expected)) logger.debug(' result disposable: {}'.format(result)) logger.debug(''.join('=' for _ in range(len(title)))) _assertEqual(self, expected, result)
def _run_test(self, cluster, expected, *keep_path): try: keep_func = keep(*keep_path) result = set(keep_func(cluster)) except WalkError as e: result = e logger, test_name = _getLogger(self) title = '==================== {} ===================='.format( test_name) logger.debug(title) logger.debug(' keep_path: {}'.format(keep_path)) logger.debug(' cluster: {}'.format(cluster)) logger.debug(' expected disposable: {}'.format(expected)) logger.debug(' result disposable: {}'.format(result)) logger.debug(''.join('=' for _ in range(len(title)))) _assertEqual(self, expected, result)
def main(): args_parser = argparse.ArgumentParser() parser = argparse.ArgumentParser() parser.add_argument("path", nargs='+', help="Path where to look for duplicates.") parser.add_argument("-u", "--uniques", action="store_true", help="Find unique files.") parser.add_argument("-k", "--keep", action="append", required=True, help='Paths to keep.') parser.add_argument("-f", "--force", help='Force deletion.') parser.add_argument( "--non-strict", action="store_true", default=False, # Strict mode by default help="Strict mode. Fails if there are nonreadable entries in the path." ) # parser.add_argument( # "-v", # "--verbosity", # help="Verbosity level (default: WARN)", # default='WARN', # choices=['DEBUG','INFO','WARN','ERROR','CRITICAL'], # type=lambda level: level.upper() # ) # # logging.basicConfig( # level=args.verbosity, # format=args.log_format, # filename=args.log # ) args = parser.parse_args() strict_walk = not args.non_strict where = args.path protected = args.keep dry_run = True cleanup_files( where, selected = keep(*protected), dry_run = dry_run, strict_walk = strict_walk )