summaryrefslogtreecommitdiffstats
path: root/bm/seed.pl
diff options
context:
space:
mode:
Diffstat (limited to 'bm/seed.pl')
-rw-r--r--bm/seed.pl64
1 files changed, 64 insertions, 0 deletions
diff --git a/bm/seed.pl b/bm/seed.pl
new file mode 100644
index 0000000..7649b64
--- /dev/null
+++ b/bm/seed.pl
@@ -0,0 +1,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";