Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
15 changes: 12 additions & 3 deletions fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -391,6 +391,7 @@ def syntax():
cq.py [options] <output directory>
-a : check all files, including binaries (i.e. files containing invalid utf-8 chars)
-c <checks regex> : only run checks matching the regex, e.g. 'php'
-d <directory to scan>: specify the directory you want to scan
-p : print progress
-v : quite verbose
-vv : annoyingly verbose
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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))