Hi everyone!

As promised in [1], this patch makes svn_apply_autoprops.py Python
3-compatible while keeping Python 2 compatibility. Afaik, the original
semantics are preserved 100% -- I think I did the conversion from
`os.path.walk()` to `os.walk()` correctly.

[1] https://lists.apache.org/thread/j8cjrgxosz2cmcysymhy8pr4b5x9s96k

[[[
Make svn_apply_autoprops.py Python 3-compatible.

* contrib/client-side/svn_apply_autoprops.py: Set hashbang binary to `python3`.
  (get_autoprop_lines): Use `for line in fd` instead of `for line in
fd.xreadlines()`.
  (filter_walk): Pass directory names separately.
  (main): Use `open()` instead of `file()`, and `os.walk()` instead of
`os.path.walk()`.
]]]

Best regards,
Khairul
Index: contrib/client-side/svn_apply_autoprops.py
===================================================================
--- contrib/client-side/svn_apply_autoprops.py  (revision 1917418)
+++ contrib/client-side/svn_apply_autoprops.py  (working copy)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # coding=utf-8
 
 # To do:
@@ -71,7 +71,7 @@ def get_autoprop_lines(fd):
   re_start_autoprops = re.compile('^\s*\[auto-props\]\s*')
   re_end_autoprops = re.compile('^\s*\[\w+\]\s*')
 
-  for line in fd.xreadlines():
+  for line in fd:
     if reading_autoprops:
       if re_end_autoprops.match(line):
         reading_autoprops = 0
@@ -124,13 +124,14 @@ def process_autoprop_lines(lines):
 
   return result
 
-def filter_walk(autoprop_lines, dirname, filenames):
+def filter_walk(autoprop_lines, dirname, dirnames, filenames):
   # Do not descend into a .svn directory.
   try:
-    filenames.remove(SVN_WC_ADM_DIR_NAME)
+    dirnames.remove(SVN_WC_ADM_DIR_NAME)
   except ValueError:
     pass
 
+  filenames += dirnames
   filenames.sort()
 
   # Find those filenames that match each fnmatch.
@@ -184,7 +185,7 @@ def main():
     return 1
 
   try:
-    fd = file(config_filename)
+    fd = open(config_filename)
   except IOError:
     print("Cannot open svn configuration file '%s' for reading: %s" \
           % (config_filename, sys.exc_value.strerror))
@@ -196,7 +197,8 @@ def main():
 
   autoprop_lines = process_autoprop_lines(autoprop_lines)
 
-  os.path.walk(wc_path, filter_walk, autoprop_lines)
+  for root, dirs, files in os.walk(wc_path):
+    filter_walk(autoprop_lines, root, dirs, files)
 
 if __name__ == '__main__':
   sys.exit(main())

Reply via email to