Created
January 14, 2011 22:51
-
-
Save corbinbs/780445 to your computer and use it in GitHub Desktop.
Python snippet to scan a directory for Drools rule files and report on the total number of rules found. Probably could expand this to count other things...
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
import re | |
import os | |
def count_rules(dir, exts=['.drl', '.dslr']): | |
rulecount = 0 | |
for root, dirs, files in os.walk(dir): | |
for file in files: | |
if len([file for ext in exts if file.endswith(ext)]) > 0: | |
filename = os.path.join(root, file) | |
f = open(filename, "r") | |
filetext = "".join(f.readlines()) | |
f.close() | |
rules = re.findall('rule ".+?".+?\nend', filetext, re.DOTALL) | |
rulecount += len(rules) | |
return rulecount | |
#Call count_rules with the parent directory that contains all of the rules... | |
print count_rules('/tmp/testrules') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment