diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-10-06 00:00:39 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-10-06 00:00:39 (GMT) |
commit | 07713309fa3d14e2ff3926901f7571507f44fa32 (patch) | |
tree | 8129651e1c4812953dcfd390a934b72367229c60 | |
parent | ce9bb78516ae37a2a912a7d4baec01c6d32c4953 (diff) |
adding show log works now (needs to filled!
-rwxr-xr-x | lib/RHRD/rddb.pm | 149 | ||||
-rwxr-xr-x | utils/rd-show | 133 |
2 files changed, 204 insertions, 78 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 2ad8297..e3e4b0b 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -35,6 +35,7 @@ use constant { RD_MAX_CART => 999999, RD_MIN_CUT => 1, RD_MAX_CUT => 999, + RD_FADE_DEPTH => -3000, RHRD_CONFIG_FILE => '/etc/rhrd.conf', }; @@ -52,7 +53,7 @@ sub init $ctx{'config'}{'specialgroups'}{'shows'} = $cfg->val('specialgroups', 'shows', 'SHOWS'); $ctx{'config'}{'specialgroups'}{'allshows'} = $cfg->val('specialgroups', 'allshows', 'ALL_SHOWS'); $ctx{'config'}{'specialgroups'}{'allpools'} = $cfg->val('specialgroups', 'allpools', 'ALL_POOLS'); - $ctx{'config'}{'specialgroups'}{'allingles'} = $cfg->val('specialgroups', 'alljingles', 'ALL_JINGLE'); + $ctx{'config'}{'specialgroups'}{'alljingles'} = $cfg->val('specialgroups', 'alljingles', 'ALL_JINGLE'); @{$ctx{'config'}{'specialusers'}{'no-update-token'}} = split(' ', $cfg->val('specialusers', 'no-update-token', '')); @{$ctx{'config'}{'specialusers'}{'admins'}} = split(' ', $cfg->val('specialusers', 'admins', 'admin')); @@ -61,6 +62,11 @@ sub init $ctx{'config'}{'dropboxes'}{'dropbox-pseudo-station'} = $cfg->val('dropboxes', 'dropbox-pseudo-station', 'import-dropbox'); + $ctx{'config'}{'shows'}{'service'} = $cfg->val('shows', 'service', ''); + $ctx{'config'}{'shows'}{'defaultuser'} = $cfg->val('shows', 'defaultuser', ''); + @{$ctx{'config'}{'shows'}{'logprefix'}} = split(' ', $cfg->val('shows', 'logprefix', '')); + @{$ctx{'config'}{'shows'}{'logsuffix'}} = split(' ', $cfg->val('shows', 'logsuffix', '')); + my ($dbh, $status, $errorstring) = opendb(); unless(defined $dbh) { return ($dbh, $status, $errorstring); @@ -170,6 +176,88 @@ sub get_next_free_slot return ($low_cart, $high_cart); } +sub check_log_exists +{ + my ($ctx, $logname) = @_; + + my $sql = qq{select LOG_EXISTS from LOGS where NAME = ?;}; + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($logname) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my $log_exists = $sth->fetchrow_array(); + $sth->finish(); + + if(!defined $log_exists || $log_exists ne 'Y') { + return (0, 'OK', 'log does not exist'); + } + return (1, 'OK', 'log exists'); +} + +sub create_log_table +{ + my ($ctx, $logname) = @_; + + $logname=~s/ /_/g; + $logname = $ctx->{'dbh'}->quote_identifier($logname . '_LOG'); + my $sql = qq{ + create table if not exists $logname + (ID INT NOT NULL PRIMARY KEY, + COUNT INT NOT NULL, + TYPE INT DEFAULT 0, + SOURCE INT NOT NULL, + START_TIME int, + GRACE_TIME int default 0, + CART_NUMBER INT UNSIGNED NOT NULL, + TIME_TYPE INT NOT NULL, + POST_POINT enum('N','Y') default 'N', + TRANS_TYPE INT NOT NULL, + START_POINT INT NOT NULL DEFAULT -1, + END_POINT INT NOT NULL DEFAULT -1, + FADEUP_POINT int default -1, + FADEUP_GAIN int default ?, + FADEDOWN_POINT int default -1, + FADEDOWN_GAIN int default ?, + SEGUE_START_POINT INT NOT NULL DEFAULT -1, + SEGUE_END_POINT INT NOT NULL DEFAULT -1, + SEGUE_GAIN int default ?, + DUCK_UP_GAIN int default 0, + DUCK_DOWN_GAIN int default 0, + COMMENT CHAR(255), + LABEL CHAR(64), + ORIGIN_USER char(255), + ORIGIN_DATETIME datetime, + EVENT_LENGTH int default -1, + LINK_EVENT_NAME char(64), + LINK_START_TIME int, + LINK_LENGTH int default 0, + LINK_START_SLOP int default 0, + LINK_END_SLOP int default 0, + LINK_ID int default -1, + LINK_EMBEDDED enum('N','Y') default 'N', + EXT_START_TIME time, + EXT_LENGTH int, + EXT_CART_NAME char(32), + EXT_DATA char(32), + EXT_EVENT_ID char(32), + EXT_ANNC_TYPE char(8), + index COUNT_IDX (COUNT), + index CART_NUMBER_IDX (CART_NUMBER), + index LABEL_IDX (LABEL)); + }; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute(RD_FADE_DEPTH, RD_FADE_DEPTH, RD_FADE_DEPTH) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + return (1, 'OK', 'success'); +} + + ########################### TOKEN handling ########################### sub get_token @@ -850,25 +938,19 @@ sub get_show_carts return (undef, $status, $errorstring); } - my $sql = qq{select LOG_EXISTS from LOGS where NAME = ?;}; - my $sth = $ctx->{'dbh'}->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); - - $sth->execute($log) - or return (undef, 'ERROR', "Database Error: " . $sth->errstr); - - my $log_exists = $sth->fetchrow_array(); - $sth->finish(); - - if(!defined $log_exists || $log_exists ne 'Y') { + (my $log_exists, $status, $errorstring) = check_log_exists($ctx, $log); + unless (defined $log_exists) { + return (undef, $status, $errorstring); + } + unless($log_exists) { return (undef, 'ERROR', "Log with name '$log' does not exist") } $log=~s/ /_/g; $log = $ctx->{'dbh'}->quote_identifier($log . '_LOG'); - $sql = qq{select COUNT,CART_NUMBER from $log order by COUNT;}; + my $sql = qq{select COUNT,CART_NUMBER from $log order by COUNT;}; - $sth = $ctx->{'dbh'}->prepare($sql) + my $sth = $ctx->{'dbh'}->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute() @@ -885,6 +967,45 @@ sub get_show_carts return @carts; } +sub create_show_log +{ + my ($ctx, $logname, $low_cart, $high_cart) = @_; + + my ($log_exists, $status, $errorstring) = check_log_exists($ctx, $logname); + unless (defined $log_exists) { + return (undef, $status, $errorstring); + } + if($log_exists) { + return (undef, 'ERROR', "Log with name '" . $logname . "' already exists") + } + + my $sql = qq{insert into LOGS set NAME = ?, LOG_EXISTS='N', TYPE=0, DESCRIPTION = ?, ORIGIN_USER = ?, ORIGIN_DATETIME=NOW(), LINK_DATETIME=NOW(), SERVICE = ?}; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($logname, $logname . " log", $ctx->{'config'}{'shows'}{'defaultuser'}, $ctx->{'config'}{'shows'}{'service'}) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + (my $result, $status, $errorstring) = create_log_table($ctx, $logname); + unless (defined $result && defined $status) { + return (undef, $status, $errorstring); + } + +# TODO: fill up new log with cart references + my $next_id = 0; + + $sql = qq{update LOGS set LOG_EXISTS='Y', AUTO_REFRESH='Y', NEXT_ID = ? where NAME = ?}; + + $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($next_id, $logname) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + return (1, 'OK', 'success'); +} + ########################### MUSICPOOL handling ########################### sub get_musicpools_cart_range diff --git a/utils/rd-show b/utils/rd-show index c2db583..c193f11 100755 --- a/utils/rd-show +++ b/utils/rd-show @@ -75,6 +75,67 @@ sub show +sub add__check_arguments +{ + my ($name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_; + + if($name !~ m/^[a-zA-Z0-9_]{1,10}$/) { + print STDERR "name '" . $name . "' contains illegal characters or is too long/short\n"; + print STDERR " only a-z, A-Z, 0-9 and _ are allowed and the length must be between 1 and 10\n"; + return 1; + } + + if($num_carts <= 0) { + print STDERR "num-carts '" . $num_carts . "' must be > 0\n"; + return 1; + } + + if($rhythm !~ m/^[01]{4}$/ || $rhythm eq '0000') { + print STDERR "rhythm '" . $rhythm . "' contains illegal characters or is too long/short\n"; + print STDERR " only 0 or 1 are allowed and, length must be exactly 4 and it must not be '0000'\n"; + return 1; + } + + if($dow < 1 || $dow > 7) { + print STDERR "dow '" . $dow . "' is out of range, must be between 1 and 7 (1=Monday, ..., 7=Sunday)\n"; + return 1; + } + + if($starttime !~ m/^[0-2][0-9][0-5][0-9]$/ || $starttime > 2359) { + print STDERR "starttime '" . $starttime . "' is not a valid time must be HHMM\n"; + return 1; + } + + if($len <= 0) { + print STDERR "len '" . $len . "' must be > 0\n"; + return 1; + } + + return 0; +} + +sub add__get_show_carts +{ + my ($ctx, $groupname, $num_carts) = @_; + + my ($result, $status, $errorstring) = RHRD::rddb::check_group($ctx, $groupname); + unless(defined $result) { + print STDERR $status . ": " . $errorstring . "\n"; + return undef; + } + + my $low_cart = 0; + if($result) { + print " > using existing group '" . $groupname . "'\n"; + $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); + } + + return $low_cart; +} + sub add__create_group { my ($ctx, $groupname) = @_; @@ -121,7 +182,7 @@ sub add__get_free_group_carts return undef; } - my @dropboxes = RHRD::rddb::get_dropboxes($ctx, 'player', $groupname, 'S'); + my @dropboxes = RHRD::rddb::get_dropboxes($ctx, $ctx->{'config'}{'shows'}{'defaultuser'}, $groupname, 'S'); if(!defined $dropboxes[0]) { if(defined $dropboxes[1]) { print STDERR "$dropboxes[1]: $dropboxes[2]"; @@ -146,74 +207,13 @@ sub add__get_free_group_carts $low_cart += 1; } if(($low_cart + $num_carts -1) > $high_cart) { - print STDERR "there are not enough carts free\n"; + print STDERR "there are not enough free carts\n"; return undef; } return $low_cart; } -sub add__get_show_carts -{ - my ($ctx, $groupname, $num_carts) = @_; - - my ($result, $status, $errorstring) = RHRD::rddb::check_group($ctx, $groupname); - unless(defined $result) { - print STDERR $status . ": " . $errorstring . "\n"; - return undef; - } - - my $low_cart = 0; - if($result) { - print " > using existing group '" . $groupname . "'\n"; - $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); - } - - return $low_cart; -} - -sub add__check_arguments -{ - my ($name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_; - - if($name !~ m/^[a-zA-Z0-9_]{1,10}$/) { - print STDERR "name '" . $name . "' contains illegal characters or is too long/short\n"; - print STDERR " only a-z, A-Z, 0-9 and _ are allowed and the length must be between 1 and 10\n"; - return 1; - } - - if($num_carts <= 0) { - print STDERR "num-carts '" . $num_carts . "' must be > 0\n"; - return 1; - } - - if($rhythm !~ m/^[01]{4}$/ || $rhythm eq '0000') { - print STDERR "rhythm '" . $rhythm . "' contains illegal characters or is too long/short\n"; - print STDERR " only 0 or 1 are allowed and, length must be exactly 4 and it must not be '0000'\n"; - return 1; - } - - if($dow < 1 || $dow > 7) { - print STDERR "dow '" . $dow . "' is out of range, must be between 1 and 7 (1=Monday, ..., 7=Sunday)\n"; - return 1; - } - - if($starttime !~ m/^[0-2][0-9][0-5][0-9]$/ || $starttime > 2359) { - print STDERR "starttime '" . $starttime . "' is not a valid time must be HHMM\n"; - return 1; - } - - if($len <= 0) { - print STDERR "len '" . $len . "' must be > 0\n"; - return 1; - } - - return 0; -} - sub add { my ($ctx, $groupname, $name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_; @@ -230,8 +230,13 @@ sub add my $high_cart = $low_cart + $num_carts - 1; print " * will be using carts: " . $low_cart . " - " . $high_cart . "\n"; + my ($result, $status, $errorstring) = RHRD::rddb::create_show_log($ctx, $name, $low_cart, $high_cart); + unless(defined $result) { + print STDERR $status . ": " . $errorstring . "\n"; + return 1; + } + # 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 |