From 9ad22b61327ba408f2980815ac9f576c3845b7e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <celestin.matte@gmail.com>
Date: Mon, 14 Aug 2023 14:49:36 +0200
Subject: [PATCH 1/2] Convert tools/ scripts to python3

---
 loader/tools/edit_raw.py | 18 +++++++++---------
 loader/tools/fix_from.py | 36 ++++++++++++++++++------------------
 2 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/loader/tools/edit_raw.py b/loader/tools/edit_raw.py
index 13e98c1..46d678b 100755
--- a/loader/tools/edit_raw.py
+++ b/loader/tools/edit_raw.py
@@ -7,8 +7,8 @@ import tempfile
 import difflib
 
 from optparse import OptionParser
-from ConfigParser import ConfigParser
-from StringIO import StringIO
+from configparser import ConfigParser
+from io import StringIO
 
 import psycopg2
 
@@ -24,7 +24,7 @@ if __name__ == "__main__":
     (opt, args) = optparser.parse_args()
 
     if (len(args)):
-        print "No bare arguments accepted"
+        print("No bare arguments accepted")
         optparser.print_usage()
         sys.exit(1)
 
@@ -39,10 +39,10 @@ if __name__ == "__main__":
     curs = conn.cursor()
 
     if not (opt.msgid or opt.id):
-        print "Need -m or -i!"
+        print("Need -m or -i!")
         sys.exit(1)
     if opt.msgid and opt.id:
-        print "Can't specify both -m and -i!"
+        print("Can't specify both -m and -i!")
         sys.exit(1)
 
     if opt.msgid:
@@ -67,14 +67,14 @@ if __name__ == "__main__":
         f2.close()
 
         if not opt.nodiff:
-            print "\n".join(difflib.unified_diff(s.getvalue().decode(opt.charset).splitlines(),
+            print("\n".join(difflib.unified_diff(s.getvalue().decode(opt.charset).splitlines(),
                                                  s2.decode(opt.charset).splitlines(),
                                                  fromfile='old',
                                                  tofile='new',
-                                                 lineterm=''))
+                                                 lineterm='')))
 
         while True:
-            a = raw_input('Save this to db?').lower()
+            a = input('Save this to db?').lower()
             if a == 'y' or a == 'yes':
                 curs.execute("INSERT INTO messages_edited SELECT * FROM messages WHERE id=%(id)s", {
                     'id': id,
@@ -86,7 +86,7 @@ if __name__ == "__main__":
                 conn.commit()
                 break
             elif a == 'n' or a == 'no':
-                print "Ok, not saving"
+                print("Ok, not saving")
                 break
 
     finally:
diff --git a/loader/tools/fix_from.py b/loader/tools/fix_from.py
index 52efec9..4a73900 100755
--- a/loader/tools/fix_from.py
+++ b/loader/tools/fix_from.py
@@ -5,8 +5,8 @@ import sys
 import re
 import difflib
 
-from ConfigParser import ConfigParser
-from StringIO import StringIO
+from configparser import ConfigParser
+from io import StringIO
 
 import psycopg2
 
@@ -43,7 +43,7 @@ if __name__ == "__main__":
 
             # Double check...
             if bodytxt.decode('utf8') == ap.bodytxt:
-                print "Message already fixed: %s" % msgid
+                print("Message already fixed: %s" % msgid)
                 curs.execute("ROLLBACK TO SAVEPOINT msg")
                 continue
 
@@ -70,47 +70,47 @@ if __name__ == "__main__":
             ap.analyze()
 
             if ap.bodytxt != bodytxt.decode('utf8'):
-                print "Failed to fix %s!" % msgid
+                print("Failed to fix %s!" % msgid)
 
                 # Generate diff to show what we changed
-                print "CHANGED:"
-                print "\n".join(difflib.unified_diff(s.getvalue(),
+                print("CHANGED:")
+                print("\n".join(difflib.unified_diff(s.getvalue(),
                                                      fixed,
                                                      fromfile='old',
                                                      tofile='new',
                                                      n=2,
-                                                     lineterm=''))
-                print "----"
+                                                     lineterm='')))
+                print("----")
                 # Generate a diff to show what's left
-                print "REMAINING:"
-                print "\n".join(difflib.unified_diff(bodytxt.decode('utf8').splitlines(),
+                print("REMAINING:")
+                print("\n".join(difflib.unified_diff(bodytxt.decode('utf8').splitlines(),
                                                      ap.bodytxt.splitlines(),
                                                      fromfile='old',
                                                      tofile='new',
                                                      n=2,
-                                                     lineterm=''))
-                print "--------------"
+                                                     lineterm='')))
+                print("--------------")
                 while True:
-                    a = raw_input('Save this change anyway?').lower()
+                    a = input('Save this change anyway?').lower()
                     if a == 'y' or a == 'yes':
-                        print "Ok, saving!"
+                        print("Ok, saving!")
                         curs.execute("RELEASE SAVEPOINT msg")
                         break
                     elif a == 'n' or a == 'no':
-                        print "Ok, rolling back!"
+                        print("Ok, rolling back!")
                         curs.execute("ROLLBACK TO SAVEPOINT msg")
                         break
                     elif a == 'yq':
-                        print "Ok, committing and then exiting"
+                        print("Ok, committing and then exiting")
                         curs.execute("RELEASE SAVEPOINT msg")
                         conn.commit()
                         conn.close()
                         sys.exit(0)
             else:
-                print "Fixed %s!" % msgid
+                print("Fixed %s!" % msgid)
                 curs.execute("RELEASE SAVEPOINT msg")
             s.close()
 
-    print "Committing all that's there..."
+    print("Committing all that's there...")
     conn.commit()
     conn.close()
-- 
2.41.0

