Last active
August 10, 2017 01:27
-
-
Save yosshy/fd0f458378babf95f82532cb45810401 to your computer and use it in GitHub Desktop.
Jinja2 variable collector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import pprint | |
import re | |
import sys | |
RE = re.compile(r"{{ *(.*?) *}}") | |
VARS = {} | |
def find_vars(filename): | |
with open(filename) as f: | |
for line in f.readlines(): | |
for m in RE.finditer(line): | |
for var in m.groups(): | |
VARS[var] = VARS.get(var, 0) + 1 | |
def main(): | |
for filename in sys.argv[1:]: | |
find_vars(filename) | |
for var in sorted(VARS.keys()): | |
print(var, VARS[var]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment