def walk_directory(basedir, followlinks=True):
 import logger
 traversed = [os.path.abspath(basedir)]
 def _inner(root, directories, files):
  for directory in directories:
   path = os.path.join(root, directory)
   if (followlinks and os.path.islink(path)):
    real_path = os.path.abspath(os.readlink(path))
    if (real_path in traversed):
     logger.debug("Skipping '%s' since it is a symlink to '%s', which is already visited.", path, real_path)
    else:
     traversed.append(real_path)
     for args in os.walk(real_path):
      for result in _inner(*args):
       (yield result)
  (yield (root, directories, files))
 for args in os.walk(basedir):
  for result in _inner(*args):
   (yield result)

def walk_directory ( basedir , followlinks = True ) : import logger traversed = [ os . path . abspath ( basedir ) ] def _inner ( root , directories , files ) : for directory in directories : path = os . path . join ( root , directory ) if ( followlinks and os . path . islink ( path ) ) : real_path = os . path . abspath ( os . readlink ( path ) ) if ( real_path in traversed ) : logger . debug ( "Skipping '%s' since it is a symlink to '%s', which is already visited." , path , real_path ) else : traversed . append ( real_path ) for args in os . walk ( real_path ) : for result in _inner ( * args ) : ( yield result ) ( yield ( root , directories , files ) ) for args in os . walk ( basedir ) : for result in _inner ( * args ) : ( yield result )
enhanced version of os .