-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobber.py
More file actions
46 lines (34 loc) · 1.05 KB
/
globber.py
File metadata and controls
46 lines (34 loc) · 1.05 KB
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
import os
import sys
from pathlib import Path
def parse_directory(directory: str, filetype: str) -> list:
filelist: list = list()
for file in Path(directory).rglob(filetype):
file_directory: str = file.__str__()
if "subprojects" in file_directory:
continue
if "build" in file_directory:
continue
filelist.append(file)
return filelist
def glob(args: list) -> None:
directory: str = sys.argv[1]
# Unpack all of the filetypes we need to look for
filetypes: list = [i for i in sys.argv[2:] if i != ""]
files: list = list()
# Parse the directories recursively looking for filetypes
# and extend the files list by the returned list
for filetype in filetypes:
files.extend(parse_directory(directory, filetype))
for file in files:
print(file)
def main():
args: int = len(sys.argv)
if args < 3:
print("not enough arguments supplied!")
print(f"usage: python {os.path.basename(__file__)} path_to_glob file_types")
return 1;
glob(args)
return 0
if __name__ == "__main__":
main()