#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
USAGE : Just run script with path to tmTheme file as sole command line arg
OUTPUT : occurences -- scope
"""
import sys
from collections import Counter
import xml.etree.ElementTree as ET
with open(sys.argv[1], 'rt') as f:
tree = ET.parse(f)
root = tree.getroot()
c = Counter()
node_list = tree.findall('.//array/dict/')
# print(node_list)
for i, node in enumerate(node_list):
# print(i, node.text)
text = node.text
if not text:
continue
elif node.text != 'scope':
continue
elif '#' in text:
continue
scope_str = node_list[i + 1].text
if not scope_str:
continue
scopes = [n.strip() for n in scope_str.split(',') if n]
c += Counter(scopes)
print("Found {} individual scopes in total.".format(len(c)))
print("Dupe scope list:\n")
for k, v in c.items():
if v > 1:
print("{:20.2f} -- {}".format(v, k))