1#!/tmp/zstream-venv/bin/python3
2"""Generate randomly-named files with lorem ipsum paragraphs."""
3
4#
5# SPDX-License-Identifier: CDDL-1.0
6#
7# This file and its contents are supplied under the terms of the
8# Common Development and Distribution License ("CDDL"), version 1.0.
9# You may only use this file in accordance with the terms of version
10# 1.0 of the CDDL.
11#
12# A full copy of the text of the CDDL should have accompanied this
13# source.  A copy of the CDDL is also available via the Internet at
14# https://opensource.org/license/CDDL-1.0.
15#
16
17#
18# Copyright (c) 2026 by Garth Snyder. All rights reserved.
19#
20
21import argparse
22import random
23import sys
24from pathlib import Path
25from lorem_text import lorem
26
27ADJECTIVES = [
28    "boogie", "funky", "wobbly", "snazzy", "jazzy", "groovy", "zippy",
29    "bouncy", "fluffy", "crunchy", "sparkly", "fuzzy", "spiffy", "dandy",
30    "peppy", "snappy", "sassy", "zesty", "swanky", "nifty", "plucky",
31    "quirky", "wacky", "goofy", "dizzy", "breezy", "cheery", "perky",
32    "frisky", "chirpy", "feisty", "jolly", "lively", "merry", "spunky",
33    "frisky", "zippy", "vivid", "brisk", "sunny", "witty", "kinky",
34]
35
36NOUNS = [
37    "woogie", "monkey", "noodle", "pickle", "muffin", "waffle", "pebble",
38    "wobble", "doodle", "tangle", "giggle", "wiggle", "jiggle", "sparkle",
39    "crinkle", "twinkle", "frizzle", "drizzle", "sizzle", "fizzle",
40    "puddle", "bubble", "muddle", "huddle", "cuddle", "juggle", "muggle",
41    "snuggle", "tuggle", "buggle", "nugget", "widget", "gadget", "gibbet",
42    "trinket", "bracket", "racket", "jacket", "ticket", "cricket", "thicket",
43    "biscuit", "circuit", "summit", "muppet", "trumpet", "basket", "casket",
44]
45
46
47def random_name(used: set) -> str:
48    for _ in range(1000):
49        name = f"{random.choice(ADJECTIVES)}-{random.choice(NOUNS)}"
50        if name not in used:
51            return name
52    # Fallback: append a number
53    base = f"{random.choice(ADJECTIVES)}-{random.choice(NOUNS)}"
54    i = 2
55    while f"{base}-{i}" in used:
56        i += 1
57    return f"{base}-{i}"
58
59
60def fill_file(path: Path, target_size: int, repeat=False) -> None:
61    content_parts = []
62    total = 0
63    para = lorem.paragraph()
64    while total < target_size:
65        content_parts.append(para)
66        total += len(para) + 1  # +1 for newline
67        if not repeat:
68            para = lorem.paragraph()
69    path.write_text("\n\n".join(content_parts) + "\n")
70
71
72def main():
73    parser = argparse.ArgumentParser(
74        description="Generate files with random names and lorem ipsum content."
75    )
76    parser.add_argument("count", type=int, help="Number of files to create")
77    parser.add_argument("-d", "--directory", default=".",
78                        help="Target directory (default: .)")
79    parser.add_argument("-r", "--repeat", action="store_true",
80                        help="Fill files with reps of a single paragraph")
81    parser.add_argument("--min-size", type=int, default=16384,
82                        help="Minimum file size in bytes (default: 16384)")
83    parser.add_argument("--max-size", type=int, default=128000,
84                        help="Maximum file size in bytes (default: 128000)")
85    args = parser.parse_args()
86
87    if args.min_size >= args.max_size:
88        print(f"error: min-size ({args.min_size}) must be less than max-size "
89              f" ({args.max_size})", file=sys.stderr)
90        sys.exit(1)
91
92    directory = Path(args.directory)
93    directory.mkdir(parents=True, exist_ok=True)
94
95    used_names = set()
96    for i in range(args.count):
97        name = random_name(used_names)
98        used_names.add(name)
99        target_size = random.randint(args.min_size, args.max_size)
100        path = directory / name
101        fill_file(path, target_size, args.repeat)
102        print(f"  {path}  ({path.stat().st_size:,} bytes)")
103
104
105if __name__ == "__main__":
106    main()
107