[Libreoffice-commits] core.git: bin/find-unused-defines.py

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon Aug 30 07:37:20 UTC 2021


 bin/find-unused-defines.py |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

New commits:
commit 3a4b788c1b8461a83a54589fc783f7e0355e6a79
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Sun Aug 29 17:21:37 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Aug 30 09:36:48 2021 +0200

    convert this script to python3
    
    Change-Id: I4e496ab11f4ee2576b2f7e88d02f884b3b19c91a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121229
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/bin/find-unused-defines.py b/bin/find-unused-defines.py
index aafcc3fec13c..53db9d1d532a 100755
--- a/bin/find-unused-defines.py
+++ b/bin/find-unused-defines.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 
 # Search for unused constants in header files.
 #
@@ -98,13 +98,21 @@ def in_exclusion_set( a ):
             return True;
     return False;
 
+
+# Hack to turn off unicode decoding errors, which sometimes happens in the output and I really don't
+# care
+import codecs
+def strict_handler(exception):
+    return u"", exception.end
+codecs.register_error("strict", strict_handler)
+
 # find defines, excluding the externals folder
-a = subprocess.Popen("git grep -hP '^#define\\s+\\w\\w\\w\\w+\\s*' -- \"[!e][!x][!t]*\" | sort -u", stdout=subprocess.PIPE, shell=True)
+a = subprocess.Popen("git grep -hP '^#define\\s+\\w\\w\\w\\w+\\s*' -- \"[!e][!x][!t]*\" | sort -u", stdout=subprocess.PIPE, shell=True, encoding='UTF-8')
 
 name_re = re.compile(r"#define\s+(\w+)")
 with a.stdout as txt:
     for line in txt:
-        idName = name_re.match(line).group(1)
+        idName = name_re.match(str(line)).group(1)
         if idName.startswith("INCLUDED_"): continue
         # the various _START and _END constants are normally unused outside of the .hrc and .src files, and that's fine
         if idName.endswith("_START"): continue
@@ -115,7 +123,7 @@ with a.stdout as txt:
         if idName.startswith("__com"): continue # these are the include/header macros for the UNO stuff
         if in_exclusion_set(idName): continue
         # search for the constant
-        b = subprocess.Popen(["git", "grep", "-w", idName], stdout=subprocess.PIPE)
+        b = subprocess.Popen(["git", "grep", "-w", idName], stdout=subprocess.PIPE, encoding='UTF-8')
         found_reason_to_exclude = False
         with b.stdout as txt2:
             cnt = 0


More information about the Libreoffice-commits mailing list