diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-09-30 22:05:47 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-09-30 22:05:47 (GMT) |
commit | 3e52b13a26edcf217969f6f52b716486ed61dabd (patch) | |
tree | 9a0022a090aafd0fcae4986edf684cb239353da5 /utils | |
parent | 5897b1bc3b059a29f57bde6c08344deceb41bd23 (diff) |
add-show create group if not exists
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/rd-show | 74 |
1 files changed, 69 insertions, 5 deletions
diff --git a/utils/rd-show b/utils/rd-show index ff5a169..7a2736c 100755 --- a/utils/rd-show +++ b/utils/rd-show @@ -34,7 +34,7 @@ sub print_usage { print STDERR "Usage: rd-show list\n" . " rd-show (show|remove) <show-id>\n" . - " rd-show add <shortname> <title> <num-carts> <rhythm> <dow> <starttime> <len>\n"; + " rd-show add <groupname> <name> <title> <num-carts> <rhythm> <dow> <starttime> <len>\n"; } sub list @@ -73,11 +73,75 @@ sub show return 0; } +sub add__get_group_carts +{ + my ($dbh, $groupname, $num_carts) = @_; + + my ($result, $status, $errorstring) = RHRD::rddb::check_group($dbh, $groupname); + unless(defined $result) { + print STDERR $status . ": " . $errorstring . "\n"; + return undef; + } + + 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 + + } else { + print " > '" . $groupname . "' does not exist - creating it .. "; + (my $cnt, $status, $errorstring) = RHRD::rddb::add_group($dbh, $groupname); + unless(defined $cnt) { + print STDERR $status . ": " . $errorstring . "\n"; + return undef; + } + print int($cnt) . " rows affected\n"; + + ($low_cart, my $high_cart, $errorstring) = RHRD::rddb::get_shows_next_free_slot($dbh); + if(!$low_cart) { + print $high_cart . ": " . $errorstring . "\n"; + return undef; + } + print " using carts " . $low_cart . " - " . $high_cart . " for new group .. "; + + ($cnt, $status, $errorstring) = RHRD::rddb::set_group_carts($dbh, $groupname, $low_cart, $high_cart, 1, 'Y'); + unless(defined $cnt) { + print STDERR $status . ": " . $errorstring . "\n"; + return undef; + } + print int($cnt) . " rows affected\n"; + + print " enabling reports .. "; + ($cnt, $status, $errorstring) = RHRD::rddb::set_group_reports($dbh, $groupname, 'Y', 'Y', 'Y'); + unless(defined $cnt) { + print STDERR $status . ": " . $errorstring . "\n"; + return undef; + } + print int($cnt) . " rows affected\n"; + } + + return $low_cart; +} + sub add { - my ($dbh, $shortname, $title, $numcarts, $rhythm, $dow, $starttime, $len) = @_; + my ($dbh, $groupname, $name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_; + + print " * creating show: " . $title . " (" . $name . ") for group '" . $groupname . "'\n"; + + my $low_cart = add__get_group_carts($dbh, $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"; + + # TODO: + # create log named <name> and fill with $low_cart - $high_cart + # create macro cart referencing log -> show-id + # create dropbox for: groupname, show-id, $rhythm, $dow, $starttime, $len + + print " * finished\n"; - print "add show $shortname, $title, $numcarts, $rhythm, $dow, $starttime, $len not yet implemented!\n"; return 0; } @@ -124,11 +188,11 @@ if(defined $dbh) { } } elsif($cmd eq "add") { - if($num_args != 8) { + if($num_args != 9) { print_usage(); $ret = 1; } else { - $ret = add($dbh, $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6], $ARGV[7]); + $ret = add($dbh, $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6], $ARGV[7], $ARGV[8]); } } else { |