-
Notifications
You must be signed in to change notification settings - Fork 2
/
app_context.py
59 lines (38 loc) · 1.25 KB
/
app_context.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
55
56
57
58
59
import os
import json
from glob import glob
from absl import flags, app
def not_dirs(files):
return filter(lambda x: not os.path.isdir(x), files)
def not_markdown(files):
return filter(lambda x: not x.lower().endswith('.md'), files)
def not_current(files):
return filter(lambda x: x != __file__, files)
def not_hidden(files):
return filter(lambda x: not any(part.startswith('.') for part in x.split(os.sep)), files)
def norm(files):
return map(os.path.normpath, files)
def filter_files(files):
files = norm(files)
files = not_dirs(files)
files = not_markdown(files)
files = not_current(files)
files = list(files)
return files
def scan_files():
cur_dir = os.path.dirname(__file__)
files = glob(f'{cur_dir}/**', recursive=True)
files = filter_files(files)
return files
def main(argv):
files = scan_files()
context = []
for file_path in files:
with open(file_path, 'r') as f:
context.append({'Path': file_path.strip(), 'Content': f.read().strip()})
with open(FLAGS.output, 'w') as f:
json.dump(context, f, indent=3)
if __name__ == '__main__':
flags.DEFINE_string('output', None, 'Output file path', required=True)
FLAGS = flags.FLAGS
app.run(main)