-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path__init__.py
More file actions
executable file
·193 lines (149 loc) · 4.48 KB
/
__init__.py
File metadata and controls
executable file
·193 lines (149 loc) · 4.48 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/python
"""
Copyright (c) 2020-2021 Ayoub Malek and Vanessa Sochat
This source code is licensed under the terms of the MIT license.
For a copy, see <https://opensource.org/licenses/MIT>.
"""
import sys
import argparse
import urlchecker
def get_parser():
parser = argparse.ArgumentParser(description="urlchecker python")
# Global Variables
parser.add_argument(
"--version",
dest="version",
help="suppress additional output.",
default=False,
action="store_true",
)
subparsers = parser.add_subparsers(
help="urlchecker python actions",
title="actions",
description="actions for urlchecker",
dest="command",
)
# print version and exit
subparsers.add_parser(
"version", help="show software version" # pylint: disable=unused-variable
)
# main check entrypoint
check = subparsers.add_parser(
"check", help="check urls in static files (documentation or code)"
)
# supports a clone URL or a path
check.add_argument(
"path",
help="the local path or GitHub repository to clone and check",
)
check.add_argument(
"-b",
"--branch",
help="if cloning, specify a branch to use (defaults to master)",
default="master",
)
check.add_argument(
"--subfolder",
help="relative subfolder path within path (if not specified, we use root)",
)
check.add_argument(
"--cleanup",
help="remove root folder after checking (defaults to False, no cleaup)",
default=False,
action="store_true",
)
check.add_argument(
"--force-pass",
help="force successful pass (return code 0) regardless of result",
default=False,
action="store_true",
)
check.add_argument(
"--no-print",
help="Skip printing results to the screen (defaults to printing to console).",
default=False,
action="store_true",
)
check.add_argument(
"--file-types",
dest="file_types",
help="comma separated list of file extensions to check (defaults to .md,.py)",
default=".md,.py",
)
check.add_argument(
"--files",
dest="files",
help="comma separated list of exact files or patterns to check.",
default="",
)
# Exlude patterns (previously whitelisting)
check.add_argument(
"--exclude-urls",
help="comma separated links to exclude (no spaces)",
default="",
)
check.add_argument(
"--exclude-patterns",
help="comma separated list of patterns to exclude (no spaces)",
default="",
)
check.add_argument(
"--exclude-files",
help="comma separated list of files and patterns to exclude (no spaces)",
default="",
)
# Saving
check.add_argument(
"--save",
help="Path to a csv file to save results to.",
default=None,
)
# Timeouts
check.add_argument(
"--retry-count",
help="retry count upon failure (defaults to 2, one retry).",
type=int,
default=2,
)
check.add_argument(
"--timeout",
help="timeout (minutes) to provide to the aiohttp library (defaults to 5)",
type=int,
default=5,
)
return parser
def main():
"""main is the entrypoint urlchecker-python."""
parser = get_parser()
def help(return_code=0):
"""print help, including the software version and active client
and exit with return code.
"""
version = urlchecker.__version__
print("\nurlchecker python v%s" % version)
parser.print_help()
sys.exit(return_code)
# If the user didn't provide any arguments, show the full help
if len(sys.argv) == 1:
help()
# If an error occurs while parsing the arguments, the interpreter will exit with value 2
args, extra = parser.parse_known_args()
# Show the version and exit
if args.command == "version" or args.version:
print(urlchecker.__version__)
sys.exit(0)
if args.command == "check":
from .check import main
else:
print("Unsupported command %s" % args.command)
sys.exit(0)
# Pass on to the correct parser
return_code = 0
try:
main(args=args, extra=extra)
sys.exit(return_code)
except UnboundLocalError:
return_code = 1
help(return_code)
if __name__ == "__main__":
main()