[open-ils-commits] r8157 - trunk/Open-ILS/src/reporter
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Dec 5 20:49:00 EST 2007
Author: miker
Date: 2007-12-05 20:29:18 -0500 (Wed, 05 Dec 2007)
New Revision: 8157
Added:
trunk/Open-ILS/src/reporter/find_orphaned_reports.pl
Log:
script to find and list orphaned output, report and template directories for removal
Added: trunk/Open-ILS/src/reporter/find_orphaned_reports.pl
===================================================================
--- trunk/Open-ILS/src/reporter/find_orphaned_reports.pl (rev 0)
+++ trunk/Open-ILS/src/reporter/find_orphaned_reports.pl 2007-12-06 01:29:18 UTC (rev 8157)
@@ -0,0 +1,71 @@
+#!/usr/bin/perl -w
+
+use DBI;
+use Getopt::Long;
+use OpenSRF::EX qw/:try/;
+use OpenSRF::Utils qw/:daemon/;
+use OpenSRF::System;
+use OpenSRF::AppSession;
+use OpenSRF::Utils::SettingsClient;
+use OpenILS::Reporter::SQLBuilder;
+use File::Find;
+
+my ($config, $du, $live, %seen) = ('/openils/conf/bootstrap.conf', 0, 0);
+
+GetOptions(
+ "boostrap=s" => \$config,
+ "du" => \$du,
+ "live" => \$live,
+);
+
+OpenSRF::System->bootstrap_client( config_file => $config );
+
+my $sc = OpenSRF::Utils::SettingsClient->new;
+my $db_driver = $sc->config_value( reporter => setup => database => 'driver' );
+my $db_host = $sc->config_value( reporter => setup => database => 'host' );
+my $db_port = $sc->config_value( reporter => setup => database => 'port' );
+my $db_name = $sc->config_value( reporter => setup => database => 'name' );
+my $db_user = $sc->config_value( reporter => setup => database => 'user' );
+my $db_pw = $sc->config_value( reporter => setup => database => 'password' );
+
+my $output_base = $sc->config_value( reporter => setup => files => 'output_base' );
+
+my $dsn = "dbi:" . $db_driver . ":dbname=" . $db_name .';host=' . $db_host . ';port=' . $db_port;
+
+my $dbh = DBI->connect($dsn,$db_user,$db_pw, {pg_enable_utf8 => 1, RaiseError => 1});
+
+find(\&wanted, $output_base);
+
+$dbh->disconnect;
+
+
+sub wanted {
+ my $dir = $File::Find::dir;
+ $dir =~ s/^$output_base//;
+ $dir =~ s#^/+##;
+ $dir =~ s#/+$##;
+ my @list = split '/', $dir;
+ return unless @list == 3;
+ return if $seen{$list[2]};
+ $seen{$list[2]} = 1;
+
+ if ($dbh->selectrow_array("SELECT id FROM reporter.schedule WHERE id = $list[2];")) {
+ print STDERR "$output_base/" . join('/', @list) . ( $du ? "\0" : "\n" ) if ($live);
+ } else {
+ print "$output_base/" . join('/', @list) . ( $du ? "\0" : "\n" );
+ }
+
+ if ($dbh->selectrow_array("SELECT id FROM reporter.report WHERE id = $list[1];")) {
+ print STDERR "$output_base/" . join('/', @list[0,1]) . ( $du ? "\0" : "\n" ) if ($live);
+ } else {
+ print "$output_base/" . join('/', @list[0,1]) . ( $du ? "\0" : "\n" );
+ }
+
+ if ($dbh->selectrow_array("SELECT id FROM reporter.template WHERE id = $list[0];")) {
+ print STDERR "$output_base/" . $list[0] . ( $du ? "\0" : "\n" ) if ($live);
+ } else {
+ print "$output_base/" . $list[0] . ( $du ? "\0" : "\n" );
+ }
+}
+
+
Property changes on: trunk/Open-ILS/src/reporter/find_orphaned_reports.pl
___________________________________________________________________
Name: svn:executable
+ *
More information about the open-ils-commits
mailing list