[gimp-web] tools: some improvements to the gimp-check-mirrors script
- From: Michael Schumacher <schumaml src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-web] tools: some improvements to the gimp-check-mirrors script
- Date: Thu, 18 Feb 2021 10:40:17 +0000 (UTC)
commit 5222902491187dec1d68f2b735ec5932ccec21bf
Author: Michael Schumacher <schumaml gmx de>
Date: Wed Feb 17 17:42:33 2021 +0100
tools: some improvements to the gimp-check-mirrors script
- downloads mirrors file default is now found by default
- uri is a positional argument, not an optional one
- redirects are handled and the HTTP status code of the redirection target is shown
- whitespace cleanup
- remnants of asynchronous code have been removed
tools/downloads/gimp-check-mirrors.py | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
---
diff --git a/tools/downloads/gimp-check-mirrors.py b/tools/downloads/gimp-check-mirrors.py
index b569a936..e097081d 100755
--- a/tools/downloads/gimp-check-mirrors.py
+++ b/tools/downloads/gimp-check-mirrors.py
@@ -9,18 +9,19 @@ import concurrent.futures
# argparse for mirrorsfile and uri
parser = argparse.ArgumentParser(description='Check if GIMP download mirrors have a file from
download.gimp.org.')
-parser.add_argument('--mirrorsfile', metavar='<file>', default=os.path.abspath(__file__) +
'downloads.http.txt',
- help='A file with one download mirror per line, either https:// or http://. Is expected
to point to the equivalent of https://download.gimp.org/pub/gimp/, as some mirrors only have that directory
structure.')
-parser.add_argument('--uri', metavar='<uri>',
- help='URI pointing to the file on download.gimp.org, e.g.
https://download.gimp.org/pub/gimp/v2.10/gimp-2.10.20.tar.bz2')
+parser.add_argument('--mirrorsfile', metavar='<file>', default=os.path.dirname(__file__) +
'/downloads.http.txt',
+ help='A file with one download mirror per line, either https:// or http://. Each line is
expected to point to the equivalent of https://download.gimp.org/pub/gimp/, as some mirrors only have that
directory structure.')
+parser.add_argument(dest='uris', metavar='<uri>', nargs='+',
+ help='One or more URIs pointing to the file on download.gimp.org, e.g.
https://download.gimp.org/pub/gimp/v2.10/gimp-2.10.20.tar.bz2')
args = parser.parse_args()
-#print(vars(args))
# get local path
-dgo_uri = args.uri
-dgo_uri_local = dgo_uri.replace('https://download.gimp.org/pub/gimp/', '')
-dgo_uri_local = dgo_uri_local.replace('https://download.gimp.org/mirror/pub/gimp/', '')
+for uri in args.uris:
+ dgo_uri = uri
+ dgo_uri_local = dgo_uri.replace('https://download.gimp.org/pub/gimp/', '')
+ dgo_uri_local = dgo_uri_local.replace('https://download.gimp.org/mirror/pub/gimp/', '')
+pass
def load_url(url, timeout):
with requests.head(url, timeout=timeout) as conn:
@@ -29,16 +30,12 @@ def load_url(url, timeout):
# read mirrors file
# fileinput.
#with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
-with fileinput.input(files=(args.mirrorsfile), mode='r') as f:
+with fileinput.input(files=(args.mirrorsfile), mode='r') as f:
for line in f:
- mirror_uri = line.strip() + dgo_uri_local
-
- # future_to_url = executor.submit(load_url, request, 60)
+ mirror_uri = line.strip() + dgo_uri_local
- # for future in concurrent.futures.as_completed(future_to_url):
try:
- #data= future.result()
- response = requests.head(url=mirror_uri, timeout=10)
+ response = requests.head(url=mirror_uri, timeout=10, allow_redirects=True)
print(str(response.status_code) + ' : ' + mirror_uri)
except HTTPError as error:
print(str(error.code) + ' : ' + mirror_uri)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]