Skip to content

Commit 5351dd2

Browse files
committed
Renames
1 parent fed631a commit 5351dd2

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

scripts/check-urls.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import contextlib
22
import fileinput
3-
import signal
43
import os
54
import re
65
import sys
7-
import threading
86
import typing
97
import urllib.parse
108

119
from github_job_summary import JobSummary
1210
from subdomains import Subdomains
13-
from curl_wrapper import EXIT_CODES as CURL_EXIT_CODES
11+
from curl_wrapper import CurlExitCodes
1412
from url_checker import UrlChecker
1513

1614
"""
@@ -22,14 +20,14 @@
2220

2321
JOIN_TIMEOUT_SEC = 120
2422

25-
CURL_EXIT_CODES_AND_HTTP_CODES: dict[str, tuple[int, int | None]] = {
26-
"https://api.aspose.cloud/connect/token": (CURL_EXIT_CODES.HTTP_RETURNED_ERROR, 400),
27-
"https://api.aspose.cloud/v3.0": (CURL_EXIT_CODES.HTTP_RETURNED_ERROR, 404),
28-
"https://api.aspose.cloud/v4.0": (CURL_EXIT_CODES.HTTP_RETURNED_ERROR, 404),
29-
"https://api.aspose.cloud/v4.0/": (CURL_EXIT_CODES.HTTP_RETURNED_ERROR, 404),
30-
"https://id.aspose.cloud/connect/token": (CURL_EXIT_CODES.HTTP_RETURNED_ERROR, 400),
23+
EXIT_CODE_EXPECTATIONS: dict[str, tuple[int, int | None]] = {
24+
"https://api.aspose.cloud/connect/token": (CurlExitCodes.HTTP_RETURNED_ERROR, 400),
25+
"https://api.aspose.cloud/v3.0": (CurlExitCodes.HTTP_RETURNED_ERROR, 404),
26+
"https://api.aspose.cloud/v4.0": (CurlExitCodes.HTTP_RETURNED_ERROR, 404),
27+
"https://api.aspose.cloud/v4.0/": (CurlExitCodes.HTTP_RETURNED_ERROR, 404),
28+
"https://id.aspose.cloud/connect/token": (CurlExitCodes.HTTP_RETURNED_ERROR, 400),
3129
# TODO: Temporary fix
32-
"https://dashboard.aspose.cloud/applications": (CURL_EXIT_CODES.HTTP_RETURNED_ERROR, 404),
30+
"https://dashboard.aspose.cloud/applications": (CurlExitCodes.HTTP_RETURNED_ERROR, 404),
3331
}
3432

3533
REGEX_TO_IGNORE: list[re.Pattern[str]] = [
@@ -159,7 +157,7 @@ def text_extractor(files: list[str]) -> typing.Generator[tuple[str, str], None,
159157

160158
def main(files: list[str]) -> int:
161159
url_checker = UrlChecker(
162-
expectations=CURL_EXIT_CODES_AND_HTTP_CODES,
160+
expectations=EXIT_CODE_EXPECTATIONS,
163161
)
164162

165163
with url_checker.start() as checker:
@@ -174,8 +172,8 @@ def main(files: list[str]) -> int:
174172
if res.ok:
175173
JOB_SUMMARY.add_success(res.url)
176174
else:
177-
files = EXTRACTED_URLS_WITH_FILES.get(res.url, [])
178-
JOB_SUMMARY.add_error(f"Broken URL '{res.url}': {res.stderr}Files: {files}")
175+
src_files = EXTRACTED_URLS_WITH_FILES.get(res.url, [])
176+
JOB_SUMMARY.add_error(f"Broken URL '{res.url}': {res.stderr}Files: {src_files}")
179177

180178
JOB_SUMMARY.finalize("Checked {total} failed **{failed}**\nGood={success}")
181179
if JOB_SUMMARY.has_errors:

scripts/curl_wrapper.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
DEFAULT_USER_AGENT = "Googlebot/2.1 (+http://www.google.com/bot.html)"
1010

1111

12-
class EXIT_CODES:
12+
class CurlExitCodes:
13+
"""
14+
See: https://curl.se/libcurl/c/libcurl-errors.html
15+
"""
16+
1317
OK = 0
1418
COULDNT_RESOLVE_HOST = 6
1519
HTTP_RETURNED_ERROR = 22
@@ -18,7 +22,6 @@ class EXIT_CODES:
1822
class CurlWrapper:
1923
"""
2024
Encapsulates a single curl execution with timeouts and helpers.
21-
See: https://curl.se/libcurl/c/libcurl-errors.html
2225
"""
2326

2427
CURL_STDERR_HTTP_RE = re.compile(r"^curl: \(22\) The requested URL returned error: (?P<http_code>\d+)")

scripts/url_checker.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import contextlib
22
import sys
3+
import threading
34
import time
45
from dataclasses import dataclass
56
from queue import Queue, Empty
6-
from typing import Callable, Optional, Iterable
77
from types import TracebackType
8-
import threading
8+
from typing import Callable, Optional
99

10-
from curl_wrapper import CurlWrapper, EXIT_CODES
10+
from curl_wrapper import CurlWrapper, CurlExitCodes
1111

1212

1313
@dataclass
@@ -47,17 +47,17 @@ def __init__(
4747
def add_url(self, url: str) -> None:
4848
self.queue.put_nowait(url)
4949

50-
def close(self) -> None:
50+
def _close(self) -> None:
5151
if not self._closed:
5252
self._closed = True
5353
self.queue.put_nowait(None)
5454

55-
def stop(self) -> None:
55+
def _stop(self) -> None:
5656
self.stop_event = True
5757
with contextlib.suppress(Exception):
5858
self.queue.put_nowait(None)
5959

60-
def run(self) -> None:
60+
def _run(self) -> None:
6161
queue_is_empty = False
6262
while not queue_is_empty or any(self.workers):
6363
# Graceful stop: cancel running curls
@@ -105,7 +105,7 @@ def run(self) -> None:
105105
def start(self) -> "UrlChecker":
106106
if self._thread is not None:
107107
return self
108-
self._thread = threading.Thread(target=self.run, daemon=True)
108+
self._thread = threading.Thread(target=self._run, daemon=True)
109109
self._thread.start()
110110
return self
111111

@@ -119,20 +119,20 @@ def __exit__(
119119
tb: TracebackType | None,
120120
) -> None:
121121
# Ensure we signal end of input and wait for completion
122-
self.close()
122+
self._close()
123123
self.wait()
124124

125125
def wait(self, join_timeout_sec: float | None = None) -> None:
126126
# Ensure end-of-input signaled before waiting
127-
self.close()
127+
self._close()
128128
t = self._thread
129129
if t is None:
130130
return
131131
if join_timeout_sec is not None:
132132
t.join(timeout=join_timeout_sec)
133133
if t.is_alive():
134134
# Try to stop gracefully and inform user
135-
self.stop()
135+
self._stop()
136136
print(
137137
f"URL checker did not finish within {join_timeout_sec}s; exiting early.",
138138
file=sys.stderr,
@@ -155,7 +155,7 @@ def _process_finished(self, task: CurlWrapper) -> None:
155155
stderr_out = ""
156156
else:
157157
# If curl reports HTTP error (22), attempt to parse HTTP code to compare
158-
if task.ret_code == EXIT_CODES.HTTP_RETURNED_ERROR and expected_http_code:
158+
if task.ret_code == CurlExitCodes.HTTP_RETURNED_ERROR and expected_http_code:
159159
match = CurlWrapper.CURL_STDERR_HTTP_RE.match(task.stderr)
160160
assert match, "Unexpected output: %s" % task.stderr
161161
http_code_val = int(match.groupdict()["http_code"])

0 commit comments

Comments
 (0)