BA
/
BaBoRo_test2
Backup 1
mbed-os/tools/misc/find_c_includes.py@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | #!/usr/bin/env python |
borlanic | 0:02dd72d1d465 | 2 | |
borlanic | 0:02dd72d1d465 | 3 | import os |
borlanic | 0:02dd72d1d465 | 4 | import re |
borlanic | 0:02dd72d1d465 | 5 | |
borlanic | 0:02dd72d1d465 | 6 | def main(path='.', pattern=r'#include\s+"([^"]*\.(?:c|cpp))"'): |
borlanic | 0:02dd72d1d465 | 7 | pattern = re.compile(pattern) |
borlanic | 0:02dd72d1d465 | 8 | |
borlanic | 0:02dd72d1d465 | 9 | for root, dirs, files in os.walk(path, followlinks=True): |
borlanic | 0:02dd72d1d465 | 10 | for file in files: |
borlanic | 0:02dd72d1d465 | 11 | with open(os.path.join(root, file)) as f: |
borlanic | 0:02dd72d1d465 | 12 | for line in f.read().splitlines(): |
borlanic | 0:02dd72d1d465 | 13 | m = re.search(pattern, line) |
borlanic | 0:02dd72d1d465 | 14 | if m: |
borlanic | 0:02dd72d1d465 | 15 | print os.path.relpath(os.path.join(root, m.group(1))) |
borlanic | 0:02dd72d1d465 | 16 | |
borlanic | 0:02dd72d1d465 | 17 | |
borlanic | 0:02dd72d1d465 | 18 | if __name__ == "__main__": |
borlanic | 0:02dd72d1d465 | 19 | import sys |
borlanic | 0:02dd72d1d465 | 20 | main(*sys.argv[1:]) |
borlanic | 0:02dd72d1d465 | 21 |