Created
February 10, 2016 20:27
-
-
Save moshekarmel1/a105652a20026ba96090 to your computer and use it in GitHub Desktop.
This file contains 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
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