summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-10-01 18:06:49 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-10-01 18:06:49 (GMT)
commit5b3cfa9386c2733a399e51848782cecb99024c05 (patch)
tree2297944fdc3f7bf4b54ebc7c4e26a05c51581fb6
parent8d815c3eed89242cee1f355ded4ca2a03fee2de3 (diff)
read context config from special config file
-rwxr-xr-xlib/RHRD/rddb.pm48
-rwxr-xr-xtest/context40
2 files changed, 69 insertions, 19 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index 9155d8e..df9f25b 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -36,12 +36,7 @@ use constant {
RD_MIN_CUT => 1,
RD_MAX_CUT => 999,
- RHRD_DROPBOX_PSEUDO_STATION_NAME => 'import-dropbox',
- RHRD_SYSTEM_MACROS_GROUP => 'SYSTEM',
- RHRD_SHOW_MACROS_GROUP => 'SHOWS',
- RHRD_ALLSHOWS_GROUP => 'ALL_SHOWS',
- RHRD_ALLMUSICPOOLS_GROUP => 'ALL_POOLS',
- RHRD_ALLJINGLES_GROUP => 'ALL_JINGLE',
+ RHRD_CONFIG_FILE => '/etc/rhrd.conf',
};
########################### context handling ###########################
@@ -50,6 +45,22 @@ sub init
{
my %ctx;
+ my $cfg = Config::IniFiles->new(-file => RD_CONFIG_FILE)
+ or return (undef , 'ERROR', "RHRD Config File Error: " . join("\n", @Config::IniFiles::errors));
+
+ $ctx{'config'}{'specialgroups'}{'system'} = $cfg->val('specialgroups', 'system', 'SYSTEM');
+ $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'}{'specialusers'}{'no-update-token'} = $cfg->val('specialusers', 'no-update-token', 'admin');
+ $ctx{'config'}{'specialusers'}{'admins'} = $cfg->val('specialusers', 'no-update-token', 'admin');
+ $ctx{'config'}{'specialusers'}{'allshows'} = $cfg->val('specialusers', 'no-update-token', '');
+ $ctx{'config'}{'specialusers'}{'allpools'} = $cfg->val('specialusers', 'no-update-token', '');
+
+ $ctx{'config'}{'dropboxes'}{'dropbox-pseudo-station'} = $cfg->val('dropboxes', 'dropbox-pseudo-station', 'import-dropbox');
+
my ($dbh, $status, $errorstring) = opendb();
unless(defined $dbh) {
return ($dbh, $status, $errorstring);
@@ -68,9 +79,8 @@ sub destroy
sub opendb
{
- my $RD_CONF = RD_CONFIG_FILE;
- my $cfg = Config::IniFiles->new(-file => $RD_CONF)
- or return (undef , 'ERROR', "Config File Error: " . join("\n", @Config::IniFiles::errors));
+ my $cfg = Config::IniFiles->new(-file => RD_CONFIG_FILE)
+ or return (undef , 'ERROR', "RD Config File Error: " . join("\n", @Config::IniFiles::errors));
my $dbhost = $cfg->val('mySQL', 'Hostname');
my $dbname = $cfg->val('mySQL', 'Database');
@@ -674,10 +684,10 @@ sub get_dropboxes
or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
if(defined $groupname) {
- $sth->execute($username, RHRD_DROPBOX_PSEUDO_STATION_NAME, $groupname)
+ $sth->execute($username, $ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'}, $groupname)
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
} else {
- $sth->execute($username, RHRD_DROPBOX_PSEUDO_STATION_NAME)
+ $sth->execute($username, $ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'})
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
}
@@ -731,13 +741,13 @@ sub get_dropboxes
sub get_shows_cart_range
{
my ($ctx) = @_;
- return get_cart_range($ctx, RHRD_ALLSHOWS_GROUP)
+ return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'allshows'})
}
sub get_shows_next_free_slot
{
my ($ctx) = @_;
- return get_next_free_slot($ctx, RHRD_ALLSHOWS_GROUP)
+ return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'allshows'})
}
sub list_shows
@@ -749,7 +759,7 @@ sub list_shows
my $sth = $ctx->{'dbh'}->prepare($sql)
or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
- $sth->execute(RHRD_DROPBOX_PSEUDO_STATION_NAME)
+ $sth->execute($ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'})
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
my @show_dbs;
@@ -787,7 +797,7 @@ sub get_show_group_carts
my $sth = $ctx->{'dbh'}->prepare($sql)
or return (undef, undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
- $sth->execute($showid, RHRD_DROPBOX_PSEUDO_STATION_NAME)
+ $sth->execute($showid, $ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'})
or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr);
my ($group_low_cart, $group_high_cart) = $sth->fetchrow_array();
@@ -880,13 +890,13 @@ sub get_show_carts
sub get_musicpools_cart_range
{
my ($ctx) = @_;
- return get_cart_range($ctx, RHRD_ALLMUSICPOOLS_GROUP)
+ return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'})
}
sub get_musicpools_next_free_slot
{
my ($ctx) = @_;
- return get_next_free_slot($ctx, RHRD_ALLMUSICPOOLS_GROUP)
+ return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'})
}
########################### JINGLES handling ###########################
@@ -894,13 +904,13 @@ sub get_musicpools_next_free_slot
sub get_jingles_cart_range
{
my ($ctx) = @_;
- return get_cart_range($ctx, RHRD_ALLJINGLES_GROUP)
+ return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'})
}
sub get_jingles_next_free_slot
{
my ($ctx) = @_;
- return get_next_free_slot($ctx, RHRD_ALLJINGLES_GROUP)
+ return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'})
}
################################# END ####################################
diff --git a/test/context b/test/context
new file mode 100755
index 0000000..f92b057
--- /dev/null
+++ b/test/context
@@ -0,0 +1,40 @@
+#!/usr/bin/perl -w
+#
+# rhrdlibs
+#
+# Copyright (C) 2015 Christian Pointner <equinox@helsinki.at>
+#
+# This file is part of rhrdlibs.
+#
+# rhrdlibs is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+#
+# rhrdlibs is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with rhrdlibs. If not, see <http://www.gnu.org/licenses/>.
+#
+
+use strict;
+use Data::Dumper::Simple;
+
+use lib "../lib/";
+use RHRD::rddb;
+
+my ($ctx, undef, $errorstring) = RHRD::rddb::init();
+if(defined $ctx) {
+
+ print Dumper($ctx);
+
+ RHRD::rddb::destroy($ctx);
+} else {
+ print "$errorstring\n";
+ exit 1;
+}
+
+exit 0