2004-08-19 00:23:58 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2004-08-19 14:21:25 +02:00
|
|
|
"""
|
|
|
|
This script exists mostly to pull out literal strings in a program in order to
|
|
|
|
spell-check them.
|
|
|
|
"""
|
|
|
|
|
2004-08-19 00:23:58 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import parser
|
2004-08-19 14:23:36 +02:00
|
|
|
import string
|
|
|
|
import symbol
|
2004-08-19 00:23:58 +02:00
|
|
|
|
|
|
|
import supybot.utils as utils
|
|
|
|
|
|
|
|
def strings(node):
|
|
|
|
if node[0] == 3:
|
|
|
|
yield (node[2], node[1])
|
|
|
|
for x in node:
|
|
|
|
if isinstance(x, list):
|
|
|
|
for t in strings(x):
|
|
|
|
yield t
|
|
|
|
|
|
|
|
def getText(filename):
|
|
|
|
try:
|
|
|
|
fd = file(filename)
|
|
|
|
return fd.read()
|
|
|
|
finally:
|
|
|
|
fd.close()
|
|
|
|
|
2004-08-19 14:21:25 +02:00
|
|
|
goodChars = string.letters + string.whitespace
|
|
|
|
prefixes = ('r"', "r'", '$Id')
|
2004-08-19 00:23:58 +02:00
|
|
|
def main():
|
|
|
|
for filename in sys.argv[1:]:
|
|
|
|
s = getText(filename)
|
|
|
|
node = parser.ast2list(parser.suite(s), True)
|
2004-08-19 14:21:25 +02:00
|
|
|
for (lineno, s) in strings(node):
|
|
|
|
if s.translate(string.ascii, string.printable):
|
|
|
|
continue
|
|
|
|
for prefix in prefixes:
|
|
|
|
if s.startswith(prefix):
|
|
|
|
continue
|
|
|
|
s = eval(s)
|
|
|
|
s = s.replace('%s', ' ')
|
|
|
|
s = s.replace('%r', ' ')
|
2004-08-19 14:26:11 +02:00
|
|
|
if not s:
|
|
|
|
continue
|
2004-08-19 14:28:51 +02:00
|
|
|
if len(s.translate(string.ascii, goodChars))/len(s) > 0.8:
|
2004-08-19 01:38:05 +02:00
|
|
|
continue
|
2004-08-19 14:21:25 +02:00
|
|
|
if len(s) <= 3:
|
2004-08-19 01:38:05 +02:00
|
|
|
continue
|
2004-08-19 14:21:25 +02:00
|
|
|
print '%s: %s: %s' % (filename, lineno, s)
|
2004-08-19 00:23:58 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|