metavar='PATH', type=str, nargs='*', help='Files or directories to (recursively) apply the actions to') ARGS = PARSER.parse_args() # TARGETS is a list of files with an optional list of hunks, represented as # pair (start, end) of line numbers, 1 based. # element of TARGETS: (filename, None) or (filename, [(start,end)]) if ARGS.staged_files: TARGETS = hunks_from_staged_files() if not TARGETS: LOG.error( "no staged files or not calling from a repository -- exiting") sys.exit("no staged files or not calling from a repository") elif ARGS.number_commits > 0: TARGETS = hunks_from_last_commits(ARGS.number_commits) if not TARGETS: LOG.error( "no changes could be extracted for formatting -- exiting") sys.exit("no changes could be extracted for formatting") elif not ARGS.paths: LOG.error("no files or directories given -- exiting") sys.exit("no files or directories given") else:
help='Files or directories to (recursively) apply the actions to') ARGS = PARSER.parse_args() if ARGS.staged_files: PELOTON_DIR_bytes = bytes(PELOTON_DIR, 'utf-8') TARGETS = [ str(os.path.abspath(os.path.join(PELOTON_DIR_bytes, f)), 'utf-8') \ for f in subprocess.check_output( ["git", "diff", "--name-only", "HEAD", "--cached", "--diff-filter=d" ] ).split()] if not TARGETS: LOG.error( "no staged files or not calling from a repository -- exiting") sys.exit("no staged files or not calling from a repository") elif not ARGS.paths: LOG.error("no files or directories given -- exiting") sys.exit("no files or directories given") else: TARGETS = ARGS.paths for x in TARGETS: if os.path.isfile(x): LOG.info("Scanning file: %s", x) format_file(x, ARGS.update_header, ARGS.clang_format_code) elif os.path.isdir(x): LOG.info("Scanning directory %s", x) format_dir(x, ARGS.update_header, ARGS.clang_format_code) ## FOR
ARGS = PARSER.parse_args() if ARGS.staged_files: PELOTON_DIR_bytes = bytes(PELOTON_DIR, 'utf-8') TARGETS = [ str(os.path.abspath(os.path.join(PELOTON_DIR_bytes, f)), 'utf-8') \ for f in subprocess.check_output( ["git", "diff", "--name-only", "HEAD", "--cached", "--diff-filter=d" ] ).split()] if not TARGETS: LOG.error( "no staged files or not calling from a repository -- exiting" ) sys.exit("no staged files or not calling from a repository") elif not ARGS.paths: LOG.error("no files or directories given -- exiting") sys.exit("no files or directories given") else: TARGETS = ARGS.paths for x in TARGETS: if os.path.isfile(x): LOG.info("Scanning file: %s", x) format_file(x, ARGS.update_header, ARGS.clang_format_code) elif os.path.isdir(x): LOG.info("Scanning directory %s", x) format_dir(x, ARGS.update_header, ARGS.clang_format_code)