Python 2 was [removed from macOS in 12.3][0]. This change: - Automatically converts many files with [2to3][1] - Manually updates all [shebangs][2] to use `python3` instead of versionless `python` or `python2.7` - Manually applies a few fixes, many of which were noted by 2to3 - Manually undoes a few fixes that were automatically done by 2to3 [0]: https://www.macrumors.com/2022/01/28/apple-removing-python-2-in-macos-12-3/ [1]: https://docs.python.org/3/library/2to3.html [2]: https://en.wikipedia.org/wiki/Shebang_(Unix)
46 lines
1.0 KiB
Python
Executable File
46 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
This script can be used to grep the source to tree to see which localized strings are in use.
|
|
|
|
author: corbett
|
|
usage: ./unused_strings.py Localizable.strings source_dir
|
|
eg: ./unused_strings.py ../Signal/translations/en.lproj/Localizable.strings ../Signal/src
|
|
"""
|
|
import sys
|
|
import os
|
|
import re
|
|
|
|
|
|
def file_match(fname, pat):
|
|
try:
|
|
f = open(fname, "rt")
|
|
except IOError:
|
|
return
|
|
|
|
for i, line in enumerate(f):
|
|
if pat.search(line):
|
|
return True
|
|
f.close()
|
|
return False
|
|
|
|
|
|
def rgrep_match(dir_name, s_pat):
|
|
pat = re.compile(s_pat)
|
|
for dirpath, dirnames, filenames in os.walk(dir_name):
|
|
for fname in filenames:
|
|
fullname = os.path.join(dirpath, fname)
|
|
match=file_match(fullname, pat)
|
|
if match:
|
|
return match
|
|
return False
|
|
|
|
if __name__ == '__main__':
|
|
strings_file = sys.argv[1]
|
|
src_dir_name = sys.argv[2]
|
|
|
|
for item in open(strings_file).readlines():
|
|
grep_for = item.strip().split(' = ')[0].replace('"','')
|
|
if rgrep_match(src_dir_name, grep_for):
|
|
print(item.strip())
|
|
|