def test_link_dir_was_visited(self): visited = { self.linkdir_path : True } self.assert_(self.linkdir_path in visited, "Dictionary key testing false?!?") res = helper_functions.is_unvisited_symlink_dir(self.linkdir_path, visited) self.failIf(res, "Returned true even though linkdir_path was in visited.")
def test_link_dir_was_visited(self): visited = {self.linkdir_path: True} self.assert_(self.linkdir_path in visited, "Dictionary key testing false?!?") res = helper_functions.is_unvisited_symlink_dir( self.linkdir_path, visited) self.failIf(res, "Returned true even though linkdir_path was in visited.")
def test_target_dir_was_visited(self): visited = { self.actual_dir_path : True } realpath = os.path.realpath(self.actual_dir_path) if self.actual_dir_path != realpath: visited[realpath] = True self.assert_(self.actual_dir_path in visited, "Dictionary key testing false?!?") res = helper_functions.is_unvisited_symlink_dir(self.linkdir_path, visited) self.failIf(res, "Returned true even though target was in visited.")
def test_target_dir_was_visited(self): visited = {self.actual_dir_path: True} realpath = os.path.realpath(self.actual_dir_path) if self.actual_dir_path != realpath: visited[realpath] = True self.assert_(self.actual_dir_path in visited, "Dictionary key testing false?!?") res = helper_functions.is_unvisited_symlink_dir( self.linkdir_path, visited) self.failIf(res, "Returned true even though target was in visited.")
def process_tree(path, files_by_size, extensions): """ Given a path, a dictionary of extensions, and a dictionary of files identified by size, walks the path, categorizing files. FIXME: Currently doesn't chase symbolic links. Extend to do so, and FIXME: not loop forever. """ #FIXME: I want to log the processing somewhere, so that the user doesn't #FIXME: think the process has given up or died. visited_directories = {} for root, subdirs, localfiles in os.walk(path): realroot = os.path.realpath(root) # Don't bother re-processing if we've visited this subtree already. if realroot in visited_directories: continue # We categorize each file, which os.walk gives us in a list. for filename in localfiles: # The filenames in localfires are the names in the directory. # Since os.walk doesn't change dir from the root path, we need the # fully-qualified name for this to work. fqn = os.path.join(root, filename) # os.walk doesn't categorize links to non-files as subdirs. # Test the fqn to make sure it's actually a file, so the stat call # doesn't fail. if os.path.isfile(fqn): process_filename(fqn, files_by_size, extensions) # Here we attempt to chase symlinks elif helper_functions.is_unvisited_symlink_dir( fqn, visited_directories): subdirs.append(filename) visited_directories[realroot] = { 'subdir_count': len(subdirs), 'file_count': len(localfiles) } # Debugging / status statement. # Return a status. The extension and file_size dictionaries were # modified by the code. return visited_directories
def process_tree(path, files_by_size, extensions): """ Given a path, a dictionary of extensions, and a dictionary of files identified by size, walks the path, categorizing files. FIXME: Currently doesn't chase symbolic links. Extend to do so, and FIXME: not loop forever. """ #FIXME: I want to log the processing somewhere, so that the user doesn't #FIXME: think the process has given up or died. visited_directories = {} for root, subdirs, localfiles in os.walk(path): realroot = os.path.realpath(root) # Don't bother re-processing if we've visited this subtree already. if realroot in visited_directories: continue # We categorize each file, which os.walk gives us in a list. for filename in localfiles: # The filenames in localfires are the names in the directory. # Since os.walk doesn't change dir from the root path, we need the # fully-qualified name for this to work. fqn = os.path.join(root, filename) # os.walk doesn't categorize links to non-files as subdirs. # Test the fqn to make sure it's actually a file, so the stat call # doesn't fail. if os.path.isfile(fqn): process_filename(fqn, files_by_size, extensions) # Here we attempt to chase symlinks elif helper_functions.is_unvisited_symlink_dir(fqn, visited_directories): subdirs.append(filename) visited_directories[realroot] = { 'subdir_count': len(subdirs), 'file_count': len(localfiles) } # Debugging / status statement. # Return a status. The extension and file_size dictionaries were # modified by the code. return visited_directories