-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathworkspace.py
36 lines (23 loc) · 815 Bytes
/
workspace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
SRC_SUFFIX = ['.c', '.cpp', '.cc', '.cxx']
class Workspace:
def __init__(self, include_paths):
self.include_paths = include_paths
def calculate(self):
paths = []
for path in self.include_paths:
if os.path.isdir(path):
paths.extend(self._walk(path))
elif self.should_include(path):
paths.append(path)
return paths
def should_include(self, name):
return name.lower().endswith(tuple(SRC_SUFFIX))
def _walk(self, path):
paths = []
for root, _directories, files in os.walk(path):
for name in files:
if self.should_include(name):
path = os.path.join(root, name)
paths.append(path)
return paths