Update cmd tools to use python3
authorMagnus Hagander <[email protected]>
Wed, 6 Feb 2019 19:09:15 +0000 (20:09 +0100)
committerMagnus Hagander <[email protected]>
Wed, 6 Feb 2019 19:10:42 +0000 (20:10 +0100)
This includes changing to requests for check_patches_in_archives.py,
like previously done for the internal APIs.

tools/commitfest/check_patches_in_archives.py
tools/commitfest/update_archive_threads.py
tools/mail/send_queued_mail.py

index f3c8a906e605c143a7e8b5d8fe7064feac1dffb7..5e601752084ad7555dfac141cc814cd246f179f3 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # check_patches_in_archives.py
 #
@@ -9,8 +9,7 @@
 
 import os
 import sys
-import socket
-import httplib
+import requests
 import magic
 import logging
 
@@ -33,7 +32,6 @@ if __name__ == "__main__":
                         level=debug and logging.DEBUG or logging.INFO,
                         stream=sys.stdout)
 
-    socket.setdefaulttimeout(settings.ARCHIVES_TIMEOUT)
     mag = magic.open(magic.MIME)
     mag.load()
 
@@ -48,30 +46,23 @@ if __name__ == "__main__":
         url = "/message-id/attachment/%s/attach" % a.attachmentid
         logging.debug("Checking attachment %s" % a.attachmentid)
 
-        if settings.ARCHIVES_PORT != 443:
-            h = httplib.HTTPConnection(host=settings.ARCHIVES_SERVER,
-                                       port=settings.ARCHIVES_PORT,
-                                       strict=True,
-                                       timeout=settings.ARCHIVES_TIMEOUT)
-        else:
-            h = httplib.HTTPSConnection(host=settings.ARCHIVES_SERVER,
-                                        port=settings.ARCHIVES_PORT,
-                                        strict=True,
-                                        timeout=settings.ARCHIVES_TIMEOUT)
-        h.request('GET', url, headers={
-            'Host': settings.ARCHIVES_HOST,
-        })
-        resp = h.getresponse()
-        if resp.status != 200:
-            logging.error("Failed to get %s: %s" % (url, resp.status))
-            continue
+        resp = requests.get(
+            "http{0}://{1}:{2}{3}".format(settings.ARCHIVES_PORT == 443 and 's' or '',
+                                          settings.ARCHIVES_SERVER,
+                                          settings.ARCHIVES_PORT,
+                                          url),
+            headers={
+                'Host': settings.ARCHIVES_HOST,
+            },
+            timeout=settings.ARCHIVES_TIMEOUT,
+        )
 
-        contents = resp.read()
-        resp.close()
-        h.close()
+        if resp.status_code != 200:
+            logging.error("Failed to get %s: %s" % (url, resp.status_code))
+            continue
 
         # Attempt to identify the file using magic information
-        mtype = mag.buffer(contents)
+        mtype = mag.buffer(resp.content)
         logging.debug("Detected MIME type is %s" % mtype)
 
         # We don't support gzipped or tar:ed patches or anything like
index 59064f64304e7564d005e7747cb011c5106b02e5..9738f25a6f95681efcfbfc889976ac18728287ce 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Update all attached mail threads from the archives.
 #
index 54848c9df1ed8365c78577b0648605e1296ea467..d500f049225dd274264849e91fae9e009dc9f984 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Script to send off all queued email.
 #