forked from osquery/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetfiles.py
executable file
·54 lines (45 loc) · 1.51 KB
/
getfiles.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# Copyright (c) 2014-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import json
import os
import sys
try:
import argparse
except ImportError:
print("Cannot import argparse.")
exit(1)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=(
"List files from compile_commands.json."
))
parser.add_argument(
"--build", metavar="PATH",
help="Path to osquery build (./build/<sys>/) directory"
)
parser.add_argument(
"--base", metavar="PATH", default="",
help="Real path of source base."
)
args = parser.parse_args()
commands_path = os.path.join(args.build, "compile_commands.json")
if not os.path.exists(commands_path):
print("Cannot find '%s'" % (commands_path))
exit(1)
with open(commands_path, 'r') as fh: content = fh.read()
data = json.loads(content)
for file in data:
if file['file'].find("_tests.cpp") > 0 or file['file'].find("_benchmark") > 0:
continue
if file['file'].find("gtest") > 0:
continue
print(file['file'].replace(args.base, ""))
pass