summaryrefslogtreecommitdiffstats
path: root/bm/seed.pl
blob: 7649b64ff9b3c3e5154b6c0fb2507b5d749d45d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl
use strict;
use warnings;
use File::Spec;
use File::Path qw(make_path);

my ($total_files, $max_depth) = @ARGV;

if (!defined $total_files || !defined $max_depth) {
	die "Usage: perl seed.pl <total_files> <max_depth>\nExample: perl seed.pl 200 20\n";
}

my $target_root = "bm_repo";
my $files_created = 0;

# Helper to generate random "code-like" text
sub generate_content {
	my $size_kb = 5 + int(rand(21)); # 5-25 KB
	my $bytes = $size_kb * 1024;
	my $content = "";
	my @chars = ('a'..'z', 'A'..'Z', '0'..'9');
	
	while (length($content) < $bytes) {
		my $line_len = 20 + int(rand(60));
		$content .= "\t" if rand() > 0.5; # Random indentation
		for (1..$line_len) { $content .= $chars[rand @chars]; }
		$content .= (rand() > 0.7) ? " " : ""; # Random spaces
		$content .= "\n";
	}
	return $content;
}

sub seed_tree {
	my ($current_path, $depth, $files_left) = @_;
	return if $files_left <= 0;

	# Determine how many files to put in THIS directory
	# Heuristic: Spread them out, but ensure at least 1 if depth remains
	my $files_here = ($depth == $max_depth) 
		? $files_left 
		: int($files_left / ($max_depth - $depth + 1)) + int(rand(3));
	
	$files_here = $files_left if $files_here > $files_left;

	make_path($current_path) unless -d $current_path;

	for (1..$files_here) {
		my $filename = "file_" . sprintf("%04d", ++$files_created) . ".txt";
		my $full_path = File::Spec->catfile($current_path, $filename);
		open(my $fh, '>', $full_path) or die $!;
		print $fh generate_content();
		close($fh);
	}

	# If we have depth and files remaining, go deeper
	if ($depth < $max_depth && ($files_left - $files_here) > 0) {
		my $next_dir = File::Spec->catdir($current_path, "depth_" . ($depth + 1));
		seed_tree($next_dir, $depth + 1, $files_left - $files_here);
	}
}

print "Seeding $total_files files across $max_depth levels...\n";
seed_tree($target_root, 1, $total_files);
print "Done. Created $files_created files in '$target_root'.\n";