Skip to content

Instantly share code, notes, and snippets.

@moshekarmel1
Created February 10, 2016 20:27
Show Gist options
  • Save moshekarmel1/a105652a20026ba96090 to your computer and use it in GitHub Desktop.
Save moshekarmel1/a105652a20026ba96090 to your computer and use it in GitHub Desktop.
import sys
import xml.etree.ElementTree as ET
""" Skuint is a skuid linter to check your snippets and make sure that they are needed. """
# Change this filename to your filepath, relative to this python files location
FILENAME = 'Broker_CreateOpportunity.xml'
print(('*' * 10) + ' Running Skuint on ' + FILENAME + ' ' + ('*' * 10) + '\n')
tree = ET.parse(FILENAME)
root = tree.getroot()
snippetNames = {} # Dict Snippet name => Number of times used e.g. HelloWorld => 1
for snippet in root[2][2]: #Javascript Resources are at index 2:2
if snippet.get('location') == 'inlinesnippet':
snippetNames[snippet.get('name')] = 0
for field in root.iter('field'): #Check fields for snippets
if field.get('snippet') != None:
key = field.get('snippet')
if key in snippetNames:
snippetNames[key] = snippetNames[key] + 1
else:
snippetNames[key] = -1
for action in root.iter('action'): #Check actions for snippets
if action.get('snippet') != None:
key = action.get('snippet')
if key in snippetNames:
snippetNames[key] = snippetNames[key] + 1
else:
snippetNames[key] = -1
#Report results...
print('There are ' + str(len(snippetNames)) + ' snippets')
for k, v in snippetNames.items():
if v > 0:
print('Snippet named ' + k + ' is used ' + str(v) + ' time(s)')
elif v == 0:
print('Snippet named ' + k + ' is NEVER used!! Delete it!')
elif v < 0:
print('Snippet named ' + k + ' is referenced, but it doesn\'t exist!! Create it!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment