diff options
Diffstat (limited to 'utils/rd-show')
-rwxr-xr-x | utils/rd-show | 115 |
1 files changed, 99 insertions, 16 deletions
diff --git a/utils/rd-show b/utils/rd-show index 4fe9def..d2e69c4 100755 --- a/utils/rd-show +++ b/utils/rd-show @@ -21,38 +21,121 @@ # use strict; +use lib "../lib/"; use RHRD::rddb; # this is ridiculous but makes it a little harder to create/remove users... -if ($> != 0 ) { - print STDERR "this must be run as root!\n"; - exit 1; +# if ($> != 0 ) { +# print STDERR "this must be run as root!\n"; +# exit 1; +# } + +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"; } -my $num_args = $#ARGV + 1; -if ($num_args != 2 && $num_args !=3) { - print STDERR "Usage: rd-show (add|remove) ??\n"; - exit 1; +sub list_shows +{ + my ($dbh) = @_; + + my @shows = RHRD::rddb::list_shows($dbh); + if(!defined $shows[0] && defined $shows[1]) { + print STDERR "$shows[1]: $shows[2]"; + return 1; + } + for my $href (@shows) { + print $href->{'ID'} . ": " . $href->{'TITLE'} . "\n"; + } + return 0; +} + +sub show_show +{ + my ($dbh, $show_id) = @_; + + my @carts = RHRD::rddb::get_show_carts($dbh, $show_id); + if(!defined $carts[0] && defined $carts[1]) { + print STDERR "$carts[1]: $carts[2]\n"; + return 1; + } + my ($title, undef, $status, $errorstring) = RHRD::rddb::get_show_title_and_log($dbh, $show_id); + unless (defined $title) { + print STDERR "$errorstring\n"; + return 1; + } + print $title . ":\n"; + for my $cart (@carts) { + print " > " . $cart . "\n"; + } + return 0; } +sub add_show +{ + my ($dbh, $shortname, $title, $numcarts, $rhythm, $dow, $starttime, $len) = @_; + + print "add show $shortname, $title, $numcarts, $rhythm, $dow, $starttime, $len not yet implemented!\n"; + return 0; +} + +sub remove_show +{ + my ($dbh, $show_id) = @_; + + print "removing show " . $show_id . ", not yet implemented!\n"; + return 0; +} + +my $num_args = $#ARGV + 1; +if($num_args < 1) { + print_usage(); + exit(1); +} my $cmd = $ARGV[0]; +my $ret = 0; -my ($dbh, undef, $errorstring) = RHRD::rddb::opendb(); +my ($dbh, $status, $errorstring) = RHRD::rddb::opendb(); if(defined $dbh) { - if($cmd eq "add") { - # TODO: implement this - } elsif($cmd eq "remove") { - # TODO: implement this - } else { - print STDERR "unknown command\n"; + if($cmd eq "list") { + if($num_args != 1) { + print_usage(); + exit(1); + } + $ret = list_shows($dbh) + } + elsif($cmd eq "show") { + if($num_args != 2) { + print_usage(); + exit(1); + } + $ret = show_show($dbh, $ARGV[1]) + } + elsif($cmd eq "remove") { + if($num_args != 2) { + print_usage(); + exit(1); + } + $ret = remove_show($dbh, $ARGV[1]); + } + elsif($cmd eq "add") { + if($num_args != 8) { + print_usage(); + exit(1); + } + $ret = add_show($dbh, $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6], $ARGV[7]); + } + else { + print_usage(); RHRD::rddb::closedb($dbh); exit 1; } - RHRD::rddb::closedb($dbh); } else { print STDERR "$errorstring\n"; exit 1; } -exit 0 +exit $ret; |