jellyfin-web/scripts/unused.py

41 lines
1016 B
Python
Raw Normal View History

2020-01-19 18:38:53 -07:00
import os
import subprocess
import json
# load all keys in the source language
# check entire codebase for usages
# print unused keys to a text file
# TODO: dynamic string usages cause false positives
cwd = os.getcwd()
langdir = cwd + '/../src/strings'
langlst = []
langlst.append('en-us.json')
# unused keys
dep = []
def grep(key):
2020-08-26 17:38:02 -07:00
command = 'grep -r -E "(\\\"|\'|\{)%s(\\\"|\'|\})" --include=\*.{js,html} --exclude-dir=../src/strings ../src' % key
2020-01-19 18:38:53 -07:00
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.stdout.readlines()
if output:
print('DONE: ' + key)
return True
print('UNUSED: ' + key)
dep.append(key)
return False
for lang in langlst:
with open(langdir + '/' + lang) as f:
langjson = json.load(f)
for key in langjson:
grep(key)
print(dep)
print('LENGTH: ' + str(len(dep)))
2020-05-17 06:41:23 -07:00
with open('unused.txt', 'w') as out:
2020-01-19 18:38:53 -07:00
for item in dep:
out.write(item + '\n')
out.close()