← Back to team overview

zeya team mailing list archive

[PATCH] support python 2.5 and 2.6 os.walk variations

 

This is a patch for bug 647129, 
https://bugs.edge.launchpad.net/zeya/+bug/647129

Basically, os.walk() in python 2.6 allows you to specify if you want to 
follow symlinks or not while 2.5 and lower does not.

This is a simple fix to test what version of python is being used and 
call os.walk() accordingly. It works for me, but others testing it would 
be greatly appreciated.

Best,

Greg

-- 
|       Greg Grossmeier |
| http://grossmeier.net |
>From cee7f0ecfef5bf21cfb9448e92ef700655ee8371 Mon Sep 17 00:00:00 2001
From: Greg Grossmeier <greg@xxxxxxxxxxxxxx>
Date: Fri, 24 Sep 2010 19:09:42 -0400
Subject: [PATCH] Support python 2.5 and 2.6 variations in os.walk() calls
        * LP:647129

---
 directory.py |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/directory.py b/directory.py
index 34d5368..b1c64db 100644
--- a/directory.py
+++ b/directory.py
@@ -26,6 +26,7 @@
 import os
 import tagpy
 import pickle
+import sys
 
 from backends import LibraryBackend
 from backends import extract_metadata
@@ -168,8 +169,15 @@ class DirectoryBackend(LibraryBackend):
         if not os.path.exists(self._media_path):
             raise IOError("Error: directory %r doesn't exist." % (self._media_path,))
         print "Scanning for music in %r..." % (os.path.abspath(self._media_path),)
+       # create list of all the files
+       python_installed = sys.version_info
+       python_prefered = (2,6)
+       if python_installed >= python_prefered:
+               allfiles = os.walk(self._media_path, followlinks=True)
+       else:
+               allfiles = os.walk(self._media_path)
         # Iterate over all the files.
-        for path, dirs, files in os.walk(self._media_path, followlinks=True):
+        for path, dirs, files in allfiles:
             # Sort dirs so that subdirectories will subsequently be visited
             # alphabetically (see os.walk).
             dirs.sort(key=tokenize_filename)
-- 
1.6.0.4

Follow ups