def generate_random_directory_structure()

in tools/url-checker/create_test_files.py [0:0]


def generate_random_directory_structure(root, depth=0, max_depth=4, prefix=""):
    """Recursively generate a random directory structure."""
    if depth >= max_depth:
        return
    
    # Add some randomness to the max depth
    current_max_depth = max(1, min(max_depth, max_depth - depth + random.randint(-1, 1)))
    
    # Create base dirs at root level
    if depth == 0:
        for base_dir, subdirs in BASE_DIRS.items():
            base_path = os.path.join(root, base_dir)
            ensure_directory(base_path)
            
            # Create subdirectories
            for subdir in subdirs:
                subdir_path = os.path.join(base_path, subdir)
                ensure_directory(subdir_path)
                
                # Maybe add another level
                if random.random() < 0.7:
                    for i in range(random.randint(0, 2)):
                        rand_name = f"{subdir}_{random_word()}"
                        ensure_directory(os.path.join(subdir_path, rand_name))
    
    # Add some special directories at various levels
    if depth < 2 and random.random() < 0.7:
        special_dir = random.choice(SPECIAL_DIRS)
        special_path = os.path.join(root, f"{prefix}{special_dir}")
        ensure_directory(special_path)
        
        # Recursively add subdirectories to this special dir
        generate_random_directory_structure(
            special_path, 
            depth + 1, 
            max_depth=current_max_depth,
            prefix=f"{prefix}_sub_"
        )
    
    # Add some deeply nested paths based on complexity
    if depth < 3 and random.random() < 0.3 * COMPLEXITY / 3:
        deep_nest_path = root
        nest_depth = random.randint(2, 4)
        nest_name = "nested"
        
        for i in range(nest_depth):
            nest_name = f"{nest_name}_{i}"
            deep_nest_path = os.path.join(deep_nest_path, nest_name)
            ensure_directory(deep_nest_path)

    # Add random subdirectories based on complexity
    num_random_dirs = random.randint(0, COMPLEXITY)
    for i in range(num_random_dirs):
        rand_dir = f"{random_word()}_{i}"
        rand_path = os.path.join(root, rand_dir)
        ensure_directory(rand_path)
        
        # Maybe go deeper
        if random.random() < 0.5 / (depth + 1):
            generate_random_directory_structure(
                rand_path, 
                depth + 1, 
                max_depth=current_max_depth,
                prefix=""
            )