(bug 64882) Port templatecount.py from compat

Change-Id: Ifa71350cfc841f221d2486c03dc0fde10ab91346
Merge "(bug 64882) Port templatecount.py from compat"