-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (54 loc) · 1.62 KB
/
main.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
60
61
62
63
64
65
66
67
import argparse
from search import file_name_search
def get_arguments():
parser = argparse.ArgumentParser(
description="Recursively traverse the directory for finding \
a given regex pattern in files")
parser.add_argument(
'dir_path',
help='directory'
)
parser.add_argument(
'regex_pattern',
help='regex_pattern'
)
# group = parser.add_mutually_exclusive_group()
# parser.add_argument(
# '-f',
# '--file_name',
# dest='accumulate',
# action='store_const',
# const=file_name_search,
# default=complete_search,
# help='search only text pattern in the files of directory'
# )
# parser.add_argument(
# '-t'
# '--file_text',
# dest='accumulate',
# action='store_const',
# const=text_pattern_search,
# default=complete_search,
# help='search only name of files in the directory'
# )
parser.add_argument(
'-o',
'--output',
default=None,
type=str,
help='specify custom output file output file')
return parser.parse_args()
def main():
arguments = get_arguments()
try:
dir_path = arguments.dir_path
except IOError:
print("Traverson: error: no such file or directory: '{}'"
.format(arguments.dir_path))
try:
regex_pattern = arguments.regex_pattern
except IOError:
print("Traverson: error: Enter a valid regex pettern")
file_name_search(dir_path, regex_pattern, arguments.output)
if __name__ == "__main__":
main()