documentaiton of troggle & dup filename detection utility

This commit is contained in:
Philip Sargent 2020-03-25 13:08:13 +00:00
parent 507e9f9285
commit 51fba07d70
2 changed files with 57 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

View File

@ -0,0 +1,57 @@
#!/usr/bin/env python
"""
Recursively checks that no filenames from the current working directory
down are the same, even if they are in different subdirectories. Exits
with status 0 if no matching filenames are found, or 1 if a match is
found.
2020-03-25 PMS Copied originally from https://gist.github.com/seanh/229455
Modified to lowercase everything before checking, to detect clashes caused
by capitalisation, and to capture full path for all clashing files
"""
import sys,os
print "Checking for filename clashes...",
def sortSecond(val):
return val[1]
allfilenames = []
detect = []
clashes = []
report = []
for root, dirs, files in os.walk('.'):
if root.startswith('./.git'):
# Ignore .git directory.
continue
if root.startswith('./.hg'):
# Ignore mercurial directory.
continue
for filename in files:
if filename.endswith('~'):
# Ignore automatically created backup files.
continue
if os.path.islink(os.path.join(root,filename)):
# Don't count symlinks as filename clashes.
continue
allfilenames.append((root,filename))
if filename.lower() in detect:
clashes.append(filename.lower())
else:
detect.append(filename.lower())
print len(allfilenames), 'files found...',
if clashes == []:
print 'OK'
sys.exit(0)
else:
print len(clashes)," clash(es) found."
for r,f in allfilenames:
if f in clashes:
report.append((r,f))
# sorts the array in descending according to
# second element: the clashing filename
report.sort(key = sortSecond)
for r,f in report:
print os.path.join(r,f)
print len(clashes)," clash(es) found."
sys.exit(1)