Created
July 18, 2019 17:08
-
-
Save netchampfaris/7b29cb580cca5ce689c9b1357cdbe832 to your computer and use it in GitHub Desktop.
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 os | |
import fnmatch | |
import re | |
import pandas as pd | |
method_count_map = {} | |
def run(): | |
scan_path = '/Users/netchampfaris/frappe-bench/apps/erpnext' | |
ignore_patterns = ['*/node_modules/*', '*/.git/*'] | |
file_pattern = '*.js' | |
method_match_regex = r"(frappe[\w.]*?)\(" | |
for root, _, files in os.walk(scan_path): | |
if any(map(lambda x: fnmatch.fnmatch(root, x), ignore_patterns)): | |
continue | |
for file in files: | |
if fnmatch.fnmatch(file, file_pattern): | |
fullpath = os.path.join(root, file) | |
parse_method(method_match_regex, fullpath) | |
def parse_method(pattern, file): | |
content = '' | |
with open(file, 'r') as f: | |
content = f.read() | |
result = re.findall(pattern, content) | |
for method in result: | |
update_method_count(method) | |
def update_method_count(method): | |
global method_count_map | |
method_count_map.setdefault(method, 0) | |
method_count_map[method] += 1 | |
def print_table(): | |
global method_count_map | |
d = pd.DataFrame(list(method_count_map.items()), columns=['Method', 'Count']) | |
d.sort_values('Count', inplace=True, ascending=False) | |
print(d) | |
if __name__ == "__main__": | |
run() | |
print_table() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment