diff options
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/rd-show | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/utils/rd-show b/utils/rd-show index c9a71c9..c2db583 100755 --- a/utils/rd-show +++ b/utils/rd-show @@ -79,7 +79,6 @@ sub add__create_group { my ($ctx, $groupname) = @_; - print " > '" . $groupname . "' does not exist - creating it .. "; my ($cnt, $status, $errorstring) = RHRD::rddb::add_group($ctx, $groupname); unless(defined $cnt) { print STDERR $status . ": " . $errorstring . "\n"; @@ -112,7 +111,49 @@ sub add__create_group return $low_cart; } -sub add__get_group_carts +sub add__get_free_group_carts +{ + my ($ctx, $groupname, $num_carts) = @_; + + my ($low_cart, $high_cart, $type, undef) = RHRD::rddb::get_group_carts($ctx, $groupname); + unless(defined $low_cart) { + print STDERR $high_cart . ": " . $type . "\n"; + return undef; + } + + my @dropboxes = RHRD::rddb::get_dropboxes($ctx, 'player', $groupname, 'S'); + if(!defined $dropboxes[0]) { + if(defined $dropboxes[1]) { + print STDERR "$dropboxes[1]: $dropboxes[2]"; + return undef; + } + return $low_cart; + } + + my @carts = (); + for my $db (@dropboxes) { + my @show_carts = RHRD::rddb::get_show_carts($ctx, $db->{'SHOWID'}); + if(!defined $show_carts[0] && defined $show_carts[1]) { + print STDERR "$show_carts[1]: $show_carts[2]\n"; + return undef; + } + @carts = (@carts, @show_carts) if defined($show_carts[0]) + } + + @carts = sort(@carts); + for my $cart (@carts) { + last if(($low_cart + $num_carts - 1) < $cart); + $low_cart += 1; + } + if(($low_cart + $num_carts -1) > $high_cart) { + print STDERR "there are not enough carts free\n"; + return undef; + } + + return $low_cart; +} + +sub add__get_show_carts { my ($ctx, $groupname, $num_carts) = @_; @@ -125,10 +166,9 @@ sub add__get_group_carts my $low_cart = 0; if($result) { print " > using existing group '" . $groupname . "'\n"; - # TODO: - # find free range in group which is big enough for $num_carts carts - + $low_cart = add__get_free_group_carts($ctx, $groupname, $num_carts); } else { + print " > '" . $groupname . "' does not exist - creating it .. "; $low_cart = add__create_group($ctx, $groupname); } @@ -185,7 +225,7 @@ sub add print " * creating show: " . $title . " (" . $name . ") for group '" . $groupname . "'\n"; - my $low_cart = add__get_group_carts($ctx, $groupname, $num_carts); + my $low_cart = add__get_show_carts($ctx, $groupname, $num_carts); return 1 unless defined($low_cart); my $high_cart = $low_cart + $num_carts - 1; print " * will be using carts: " . $low_cart . " - " . $high_cart . "\n"; |