Skip to content

Instantly share code, notes, and snippets.

@fabito
Created August 7, 2018 17:28
Show Gist options
  • Save fabito/f5a26c7440ecbb722020b360e75c0bdd to your computer and use it in GitHub Desktop.
Save fabito/f5a26c7440ecbb722020b360e75c0bdd to your computer and use it in GitHub Desktop.
Simple python script to list all references to the cv namespace.
from pathlib import Path
from collections import namedtuple, defaultdict
import re
pattern = re.compile("cv::(\w+)")
deps = defaultdict(list)
p = Path('.')
for i in p.glob('**/*.*pp'):
print(i)
for line_number, line in enumerate(open(i)):
for match in re.finditer(pattern, line):
dep = match.groups()[0]
data = (i.name, line_number)
deps[dep].append(data)
with open('deps.txt', 'w') as deps_txt:
for d in deps:
all_refs = [refs[0] for refs in deps[d]]
unique_refs = set(all_refs)
deps_txt.write('{},"{}",{}\n'.format(d, ';'.join(unique_refs), len(all_refs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment