Limnoria/tools/find-strings.py

41 lines
938 B
Python
Raw Normal View History

2004-08-19 00:23:58 +02:00
#!/usr/bin/env python
import os
import sys
import symbol
import parser
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()
def main():
2004-08-19 00:28:25 +02:00
out = file('strings.txt', 'w')
2004-08-19 00:23:58 +02:00
for filename in sys.argv[1:]:
s = getText(filename)
node = parser.ast2list(parser.suite(s), True)
for (lineno, string) in strings(node):
if string.startswith("r'") or string.startswith('r"'):
continue
string = eval(string)
if len(string) <= 3:
continue
2004-08-19 00:28:25 +02:00
out.write('%s: %s: %s\n' % (filename, lineno, string))
2004-08-19 00:29:17 +02:00
out.close()
2004-08-19 00:23:58 +02:00
if __name__ == '__main__':
main()