mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Some extra checks to make sure only useful strings are written.
This commit is contained in:
parent
501b642796
commit
753a410e57
@ -1,5 +1,10 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
"""
|
||||||
|
This script exists mostly to pull out literal strings in a program in order to
|
||||||
|
spell-check them.
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import symbol
|
import symbol
|
||||||
@ -22,19 +27,26 @@ def getText(filename):
|
|||||||
finally:
|
finally:
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
|
goodChars = string.letters + string.whitespace
|
||||||
|
prefixes = ('r"', "r'", '$Id')
|
||||||
def main():
|
def main():
|
||||||
out = file('strings.txt', 'w')
|
|
||||||
for filename in sys.argv[1:]:
|
for filename in sys.argv[1:]:
|
||||||
s = getText(filename)
|
s = getText(filename)
|
||||||
node = parser.ast2list(parser.suite(s), True)
|
node = parser.ast2list(parser.suite(s), True)
|
||||||
for (lineno, string) in strings(node):
|
for (lineno, s) in strings(node):
|
||||||
if string.startswith("r'") or string.startswith('r"'):
|
if s.translate(string.ascii, string.printable):
|
||||||
continue
|
continue
|
||||||
string = eval(string)
|
for prefix in prefixes:
|
||||||
if len(string) <= 3:
|
if s.startswith(prefix):
|
||||||
continue
|
continue
|
||||||
out.write('%s: %s: %s\n' % (filename, lineno, string))
|
s = eval(s)
|
||||||
out.close()
|
s = s.replace('%s', ' ')
|
||||||
|
s = s.replace('%r', ' ')
|
||||||
|
if len(s.translate(string.ascii, goodChars))/len(s) < 0.2:
|
||||||
|
continue
|
||||||
|
if len(s) <= 3:
|
||||||
|
continue
|
||||||
|
print '%s: %s: %s' % (filename, lineno, s)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user