summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-17 21:57:15 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-09-17 21:57:15 (GMT)
commit66557641d3fb28103df0a947552993e5827320aa (patch)
treedc2395a7ea5c358480e1abfccf6fcc7c19b6a4c1 /utils
parent08cfff490aec608049b031cc148ad89ee5543ea4 (diff)
added group handling support
Diffstat (limited to 'utils')
-rwxr-xr-xutils/rd-group108
1 files changed, 108 insertions, 0 deletions
diff --git a/utils/rd-group b/utils/rd-group
new file mode 100755
index 0000000..da50be6
--- /dev/null
+++ b/utils/rd-group
@@ -0,0 +1,108 @@
+#!/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 lib "../lib/";
+
+use RHRD::rddb;
+
+my $num_args = $#ARGV + 1;
+if ($num_args < 2) {
+ print STDERR "Usage: rd-group ( (check|remove|get-carts|get-reports) <groupname> |\n" .
+ " add <groupname> [ <description> ] |\n" .
+ " set-carts <groupname> [ <low> [ <high> [ <type> [ <enforce range> ]]] |\n" .
+ " set-reports <groupname> [ <nownext> [ <traffic> [ <music> ]]] )\n";
+ exit 1;
+}
+
+my $cmd = $ARGV[0];
+my $groupname = $ARGV[1];
+
+my ($dbh, undef, $errorstring) = RHRD::rddb::opendb();
+if(defined $dbh) {
+ if($cmd eq "check") {
+ (my $result, my $status, $errorstring) = RHRD::rddb::check_group($dbh, $groupname);
+ print "$result, $status: $errorstring\n";
+ RHRD::rddb::closedb($dbh);
+ exit $result;
+ } elsif($cmd eq "add") {
+ (my $cnt, undef, $errorstring) = RHRD::rddb::add_group($dbh, $groupname, $ARGV[2]);
+ unless(defined $cnt) {
+ print "$errorstring\n";
+ RHRD::rddb::closedb($dbh);
+ exit 1;
+ }
+ print int($cnt) . " rows affected\n";
+ } elsif($cmd eq "remove") {
+ my @results = RHRD::rddb::remove_group($dbh, $groupname);
+ if(!defined $results[0] && defined $results[2]) {
+ print "$results[2]\n";
+ } else {
+ for my $href (@results) {
+ print int($href->{cnt}) . " " . $href->{name} . " deleted\n";
+ }
+ }
+ } elsif($cmd eq "get-carts") {
+ my ($low, $high, $type, $enforce_range) = RHRD::rddb::get_group_carts($dbh, $groupname);
+ unless(defined $low) {
+ print "$type\n";
+ RHRD::rddb::closedb($dbh);
+ exit 1;
+ }
+ print "Range: " . int($low) . " - " . int($high) . ", Type: " . int($type) . ", Enforce Range: " . $enforce_range . "\n";
+ } elsif($cmd eq "set-carts") {
+ (my $cnt, undef, $errorstring) = RHRD::rddb::set_group_carts($dbh, $groupname, $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5]);
+ unless(defined $cnt) {
+ print "$errorstring\n";
+ RHRD::rddb::closedb($dbh);
+ exit 1;
+ }
+ print int($cnt) . " rows affected\n";
+ } elsif($cmd eq "get-reports") {
+ my ($nownext, $traffic, $music) = RHRD::rddb::get_group_reports($dbh, $groupname);
+ unless(defined $nownext) {
+ print "$music\n";
+ RHRD::rddb::closedb($dbh);
+ exit 1;
+ }
+ print "Now-Next: " . $nownext . ", Traffic: " . $traffic . ", Music: " . $music . "\n";
+ } elsif($cmd eq "set-reports") {
+ (my $cnt, undef, $errorstring) = RHRD::rddb::set_group_reports($dbh, $groupname, $ARGV[2], $ARGV[3], $ARGV[4]);
+ unless(defined $cnt) {
+ print "$errorstring\n";
+ RHRD::rddb::closedb($dbh);
+ exit 1;
+ }
+ print int($cnt) . " rows affected\n";
+ } else {
+ print STDERR "unknown command\n";
+ RHRD::rddb::closedb($dbh);
+ exit 1;
+ }
+
+ RHRD::rddb::closedb($dbh);
+} else {
+ print STDERR "$errorstring\n";
+ exit 1;
+}
+
+exit 0