[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] The followlinks arg of os.walk needs python 2.6



commit d2eef839544eaf1ed55a85df2e4fd466a175fc40
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Jun 13 09:24:34 2012 -0700

    The followlinks arg of os.walk needs python 2.6
    
    We were using the 'followlinks' argument two places: in the descriptor reader
    and whitespace checker. For the former I'm noting that 2.6 is a requirement for
    the argument and coding around it to work on 2.5. For the later I don't really
    care if the whitespace checker follows links so I'm simply dropping the arg.
---
 stem/descriptor/reader.py |   10 ++++++++--
 test/check_whitespace.py  |    2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 01f77df..676676f 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -79,6 +79,7 @@ import threading
 import mimetypes
 import Queue
 
+import stem.prereq
 import stem.descriptor
 
 # flag to indicate when the reader thread is out of descriptor files to read
@@ -204,7 +205,7 @@ class DescriptorReader:
   instead.
   
   :param str,list target: path or list of paths for files or directories to be read from
-  :param bool follow_links: determines if we'll follow symlinks when traversing directories
+  :param bool follow_links: determines if we'll follow symlinks when traversing directories (requires python 2.6)
   :param int buffer_size: descriptors we'll buffer before waiting for some to be read, this is unbounded if zero
   :param str persistence_path: if set we will load and save processed file listings from this path, errors are ignored
   """
@@ -343,8 +344,13 @@ class DescriptorReader:
         continue
       
       if os.path.isdir(target):
+        if stem.prereq.is_python_26():
+          walker = os.walk(target, followlinks = self._follow_links)
+        else:
+          walker = os.walk(target)
+        
         # adds all of the files that it contains
-        for root, _, files in os.walk(target, followlinks = self._follow_links):
+        for root, _, files in walker:
           for filename in files:
             self._handle_file(os.path.join(root, filename), new_processed_files)
           
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index 23ca1af..a567d49 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -102,7 +102,7 @@ def _get_python_files(base_path):
   :returns: iterator that yields the absolute path for python source code
   """
   
-  for root, _, files in os.walk(base_path, followlinks = True):
+  for root, _, files in os.walk(base_path):
     for filename in files:
       if filename.endswith(".py"):
         yield os.path.join(root, filename)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits