Skip to content

Instantly share code, notes, and snippets.

@robbintt
Created September 8, 2015 00:49
Show Gist options
  • Save robbintt/60d6f72ffe80c753b571 to your computer and use it in GitHub Desktop.
Save robbintt/60d6f72ffe80c753b571 to your computer and use it in GitHub Desktop.
.pyc vs .py checker
"""
Check .pyc files against .py files in a directory and all its descendants to see if any pyc files do not have their accompanying py files.
To get input for this, run the command:
find . -regex .*pyc? > checker.txt
Check if the line ends in pyc.
If it does, check if there is a line that is the same without the c.
If not, print the pyc line.
"""
# open the checker.txt file
filename = "checker.txt"
with open(filename) as f:
record = f.readlines()
# this is a test
# simple failing sample data
#record = ["this is a failed test.pyc"]
# change to list comprehension if preferred
clean_record = list()
# clean up the whitespace in each line
for line in record:
clean_record.append(line.strip())
record = clean_record
pyc_only_lines = list()
for line in record:
if line[-3:] == "pyc" and line[:-1] not in record:
print "====="
print line
pyc_only_lines.append(line)
print "= = = = = = "
print "Checked {} records.".format(len(record),)
print "{} .pyc only records found.".format(len(pyc_only_lines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment