From 9ca8b6fcc5af367162602c39b3b4548a4281117a Mon Sep 17 00:00:00 2001 From: alema-r Date: Thu, 8 Jun 2023 11:27:07 +0200 Subject: [PATCH 1/2] Add `outdir` to the directories to skip Signed-off-by: alema-r --- cq.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cq.py b/cq.py index 20601a8..58fb2ce 100755 --- a/cq.py +++ b/cq.py @@ -22,6 +22,7 @@ regex.compile(r'/\.svn/'), regex.compile(r'/\.git/'), regex.compile('example'), + regex.compile(f'/{fn.outdir}/'), # Exclude outdir from scanned directories ] SKIP_EXTS = [ From 2d27eee674b9637d52ce967a149ce3a240c21f29 Mon Sep 17 00:00:00 2001 From: alema-r Date: Thu, 8 Jun 2023 11:43:51 +0200 Subject: [PATCH 2/2] Added `-d` flag to specify a directory to scan. Signed-off-by: alema-r --- fn.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fn.py b/fn.py index 1752b77..53f24c7 100755 --- a/fn.py +++ b/fn.py @@ -335,7 +335,7 @@ def is_binary(line): def do_checks(re_checks_todo): - if outdir == '': + if outdir == '' or scandir == '': return if a: mode = 'rb' @@ -346,7 +346,7 @@ def do_checks(re_checks_todo): for check in global_checks: do_global_check(check) - for root, subdirs, files in os.walk(os.path.abspath(".")): + for root, subdirs, files in os.walk(os.path.abspath(scandir)): for fn in files: fname = str(root) + "/" + str(fn) # exclude some files/paths based on verbosity options @@ -391,6 +391,7 @@ def syntax(): cq.py [options] -a : check all files, including binaries (i.e. files containing invalid utf-8 chars) -c : only run checks matching the regex, e.g. 'php' + -d : specify the directory you want to scan -p : print progress -v : quite verbose -vv : annoyingly verbose @@ -411,10 +412,11 @@ def syntax(): print_progress = False re_checks = '.*' outdir = '/tmp/' # Note - this is always set to something else, but - just in case it isn't, put output in /tmp. +scandir = './' # If no directory is provided we assume that the current directory is the target. def do_main(): - global a, v, vv, vvv, ns, sa, sc, outdir, print_progress, re_checks + global a, v, vv, vvv, ns, sa, sc, outdir, scandir, print_progress, re_checks argc = len(sys.argv) argv = sys.argv @@ -452,6 +454,9 @@ def do_main(): print_progress = True if i == argc - 1: outdir = argv[i] + if argv[i] == '-d': + scandir = argv[i + 1] + i += 1 if argv[i] == '-c': re_checks = argv[i + 1] i += 1 @@ -461,6 +466,10 @@ def do_main(): except: # noqa print("Outdir exists") + if not os.path.exists(scandir): + print(f"{scandir}: directory not found") + sys.exit(1) + print("Starting") do_checks(regex.compile(re_checks))