-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
52 lines (34 loc) · 1.34 KB
/
__init__.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
"""
Traverse a folder looking for TODO files and merge into a single TODO file
"""
import sys
import os
from glob2 import glob
import argparse
def concat_todo_files(todo_files, include_header=False):
combined = ""
for todo in todo_files:
if include_header:
combined += f"\n{todo}\n\n"
file_content = open(todo, "r").read() + "\n"
combined += file_content
return combined
def list_todo_files(parent, basename="TODO.md"):
"""List any files named {basename} in this directory or any of its
subdirectories """
glob_str = os.path.join(parent, os.path.join("**", f"{basename}"))
return sorted(glob(glob_str))
def main():
parser = argparse.ArgumentParser("btodo - make a big TODO file")
parser.add_argument("dir", type=str, help="the root directory")
parser.add_argument("--name",
type=str,
default="TODO.md",
help="the name of the file to combine")
parser.add_argument("--include-header", action="store_true",
help="prepend the relative file path to each section")
args = parser.parse_args(sys.argv[1:])
todo_files = list_todo_files(args.dir, basename=args.name)
print(concat_todo_files(todo_files, include_header=args.include_header))
if __name__ == "__main__":
main()