[gimp-web] tools: add a new "update-mirrors.py" tool.



commit 6f598481d57795838d016ae5930628e091341e79
Author: Jehan <jehan girinstud io>
Date:   Wed Jul 21 19:18:21 2021 +0200

    tools: add a new "update-mirrors.py" tool.
    
    This new tool looks up the actual mirror list on download.gimp.org,
    a.k.a. master.gnome.org and update our local list, which will be used by
    gimp-check-mirrors.py.
    
    As a consequence it can only be used by contributors with SSH access to
    download.gimp.org.

 tools/downloads/update-mirrors.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
---
diff --git a/tools/downloads/update-mirrors.py b/tools/downloads/update-mirrors.py
new file mode 100755
index 00000000..a9713d04
--- /dev/null
+++ b/tools/downloads/update-mirrors.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+
+import argparse
+import os
+import paramiko
+import sys
+
+# TODO: we will also want to update content/downloads/mirrors2.json as
+# it was decided to follow the same list. But first we have to contact
+# existing mirrors to propose to follow GNOME process, not directly
+# remove them from the list, which would not be too nice.
+parser = argparse.ArgumentParser(description='Update the list of mirrors as per download.gimp.org 
configuration.')
+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://. This script 
will override the existing file.')
+parser.add_argument('--ssh-user', metavar='<ssh-user>', default=None, required=True,
+                    help='Your SSH user to download.gimp.org aka master.gnome.org server.')
+
+args = parser.parse_args()
+
+if args.ssh_user is None:
+  sys.stderr.write('No SSH user provided\n')
+  sys.exit(os.EX_NOUSER)
+
+ssh = paramiko.SSHClient()
+ssh.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
+ssh.load_system_host_keys()
+cmd = "cat /etc/httpd/download.gimp.org.map |grep '^mirrors' | sed 's$^mirrors\\s*\([^\s]\)$https://\\1$' | 
sed 's$|$\\nhttps://$g'"
+ssh.connect('download.gimp.org', username=args.ssh_user)
+# It will use your keys automatically.
+ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd)
+mirrors=ssh_stdout.read()
+
+with open(args.mirrorsfile, 'wb') as f:
+  f.write(mirrors)
+  f.write(b'https://download.gimp.org/pub/gimp/\n')
+
+print("Mirrors updated in {}. Please double-check before committing the change.".format(args.mirrorsfile))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]