script: Modify python scripts to be run as python3 30/319930/1
authorSangYoun Kwak <sy.kwak@samsung.com>
Fri, 1 Nov 2024 09:06:41 +0000 (18:06 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Tue, 5 Nov 2024 08:46:43 +0000 (17:46 +0900)
Modifications of scripts to make it run with python3:
  1. Shebang modified from python2 to python3:
      "#!/usr/bin/python2" -> "#!/usr/bin/python3"
  2. Escape sequences in the regular expressions are fixed:
      escape sequences which are not for the string literal should be
      started with '\\', not '\' to distinguish them from the escape
      sequence characters of string literal(like '\t').
  3. Add parentheses to the print functions:
      In the python2, no parentheses are used for print function.
      Thus, for example, `print("hello")` should be translated as
      `print(("hello"))`.(`print("hello")` is interpreted by the python
      2 as printing a tuple which contains a string "hello")

Change-Id: I53a62dd6154cbebf740af23aeac0d20ec2aab24c
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
script/api_filter.py
script/api_filter_gdbus.py

index 41a3968248a4a6961134ec0acd8933d37124641c..ad850a436caa8db66363032bd989ffd5058a60af 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 
 import sys, os, re
 
@@ -32,11 +32,11 @@ def processEAPI(fp, line, buf, update):
                 eol = False
             else:
                 line = fp.readline()
-        print(file, funcname, "X")
+        print((file, funcname, "X"))
     # handle whitelist API
     else:
         buf.append(line)
-        print(file, funcname, "O")
+        print((file, funcname, "O"))
 
 ##############
 # Main Start #
@@ -72,7 +72,7 @@ for efldir in efldirs.split():
                 if not line: break
 
                 # handle EAPI
-                if not line[0] == "#" and re.search("\s*EAPI.*\(.*", line):
+                if not line[0] == "#" and re.search("\\s*EAPI.*\\(.*", line):
                     processEAPI(fp, line, buf, False)
 
                 elif not line[0] == "#" and "EAPI" in line and not ";" in line and not line.lstrip()[0] == "*" and not line.lstrip()[1] == "*":
index 37208e9e170a144f6c493852f9a220a28b4ae87b..9bc092ecf1f615ae419c0779acdd02cc3afdb44e 100755 (executable)
@@ -1,23 +1,24 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
+
 import sys, os, re
 
 # use space as delimiter
 glibdirs = "glib-2.0"
 
 # g_dbus api matcher
-re_func = re.compile("(?P<rtype>\w*[\t ]*[*]{0,3})[\t ]*(?P<api>[_]?g_(test_)?[d]?bus_[\w\d]+)[\t ]+(?P<param>\()")
+re_func = re.compile("(?P<rtype>\\w*[\t ]*[*]{0,3})[\t ]*(?P<api>[_]?g_(test_)?[d]?bus_[\\w\\d]+)[\t ]+(?P<param>\\()")
 re_func_end = re.compile("[)]{1}.*[;]{1}")
 
 # special case matcher
 # G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDBusNodeInfo, g_dbus_node_info_unref)
-re_def_auto_ptr = re.compile("G_DEFINE_AUTOPTR_CLEANUP_FUNC\(.*(?P<api>[_]?g_(test_)?[d]?bus_[\w\d]+)+[\w\s]*\)")
+re_def_auto_ptr = re.compile("G_DEFINE_AUTOPTR_CLEANUP_FUNC\\(.*(?P<api>[_]?g_(test_)?[d]?bus_[\\w\\d]+)+[\\w\\s]*\\)")
 
 def api_filter(relative_path):
     # traverse header files
     for glibdir in glibdirs.split():
         glibpath = relative_path + "/usr/include/" + glibdir
         if not os.path.isdir(glibpath):
-            print(glibpath, 'is not valid path')
+            print((glibpath, 'is not valid path'))
             continue
         print(glibpath)
         for subdir, dirs, files in os.walk(glibpath):
@@ -27,7 +28,7 @@ def api_filter(relative_path):
                 buf = list()
                 fp = open(filepath, "rt")
                 if not fp:
-                    print('file open error', filepath)
+                    print(('file open error', filepath))
                     continue
                 lines = fp.readlines()
                 fp.close()
@@ -75,13 +76,13 @@ def api_filter(relative_path):
                         result = re_def_auto_ptr.search(line_dup)
                         if result:
                             buf.append('//{0}'.format(line))
-                            print('{0: <30} {1: <45}\tX'.format(file, '(G_DEFINE*) ' + result.group('api')))
+                            print(('{0: <30} {1: <45}\tX'.format(file, '(G_DEFINE*) ' + result.group('api'))))
                         else:
                             buf.append(line)
                         continue
 
                     if not result.group('api') or not result.group('api').strip():
-                        print('error:un reachable', result.groupdict())
+                        print(('error:un reachable', result.groupdict()))
                         continue
 
                     # ignore private api _g_dbus_xxx
@@ -102,14 +103,14 @@ def api_filter(relative_path):
                         buf[-1] = '//' + buf[-1]
                     buf.append('//{0}'.format(line))
 
-                    print('{0: <30} {1: <45}\tX'.format(file, result.group('api')))
+                    print(('{0: <30} {1: <45}\tX'.format(file, result.group('api'))))
 
                 # re-write header file
                 for i in range(3):
                     fp = open(filepath, "wt")
                     if not fp:
-                        print('file open error. failed to re-write', filepath)
-                        print('retry re-write', i)
+                        print(('file open error. failed to re-write', filepath))
+                        print(('retry re-write', i))
                         continue
                     fp.writelines(buf)
                     fp.close()