[Bps-public-commit] r14781 - in Pushmi/trunk: lib/Pushmi lib/Pushmi/Command

alexmv at bestpractical.com alexmv at bestpractical.com
Tue Aug 5 11:30:49 EDT 2008


Author: alexmv
Date: Tue Aug  5 11:30:47 2008
New Revision: 14781

Modified:
   Pushmi/trunk/   (props changed)
   Pushmi/trunk/lib/Pushmi/Command.pm
   Pushmi/trunk/lib/Pushmi/Command/Mirror.pm
   Pushmi/trunk/lib/Pushmi/Command/Runhook.pm
   Pushmi/trunk/lib/Pushmi/Command/Runlock.pm
   Pushmi/trunk/lib/Pushmi/Command/Rununlock.pm
   Pushmi/trunk/lib/Pushmi/Command/Sync.pm
   Pushmi/trunk/lib/Pushmi/Command/Unlock.pm
   Pushmi/trunk/lib/Pushmi/Command/Verify.pm

Log:
 r35323 at kohr-ah:  chmrr | 2008-08-05 11:22:42 -0400
  * Move to runtime calculation of loggers, so we can use --config instead of PUSHMI_CONFIG


Modified: Pushmi/trunk/lib/Pushmi/Command.pm
==============================================================================
--- Pushmi/trunk/lib/Pushmi/Command.pm	(original)
+++ Pushmi/trunk/lib/Pushmi/Command.pm	Tue Aug  5 11:30:47 2008
@@ -14,8 +14,6 @@
 use SVK::I18N;
 use UNIVERSAL::require;
 
-my $logger = Pushmi::Config->logger('pushmi');
-
 sub setup_auth {
     my $self = shift;
     my ($auth) = @_;
@@ -34,7 +32,22 @@
 }
 
 sub options {
-    return ( "silent!" => "silent" );
+    return (
+        "silent!"     => "silent",
+        "config=s"    => "config",
+    );
+}
+
+sub logger {
+    my $self = shift;
+    return Pushmi::Config->logger( $self->logger_class );
+}
+
+sub logger_class {
+    my $class = shift;
+    $class = ref $class if ref $class;
+    $class =~ s/Pushmi::Command::(.*)/"pushmi." . lc $1/e;
+    return $class;
 }
 
 sub run {
@@ -44,6 +57,9 @@
         close STDIN;
     }
 
+    $ENV{"PUSHMI_CONFIG"} = $self->{config}
+        if defined $self->{config};
+
     # compat
     for ($self->subcommands) {
 	if (delete $self->{$_}) {
@@ -55,7 +71,7 @@
 
     no warnings 'redefine';
     my $memd = Pushmi::Config->memcached;
-
+    my $logger = $self->logger;
     local *SVK::Mirror::lock = sub {
         my ($self)  = @_;
         my $fs      = $self->repos->fs;
@@ -99,11 +115,10 @@
     return $self->run_with_auth(@_);
 }
 
-
 sub pushmi_auth {
     my ($cred, $realm, $default_username, $may_save, $pool) = @_;
     my $config = Pushmi::Config->config;
-    $logger->logdie("unable to get username from config file.")
+    Pushmi::Command->logger->logdie("unable to get username from config file.")
 	unless defined $config->{username};
     $cred->username($config->{username});
     $cred->password($config->{password});

Modified: Pushmi/trunk/lib/Pushmi/Command/Mirror.pm
==============================================================================
--- Pushmi/trunk/lib/Pushmi/Command/Mirror.pm	(original)
+++ Pushmi/trunk/lib/Pushmi/Command/Mirror.pm	Tue Aug  5 11:30:47 2008
@@ -4,8 +4,6 @@
 use base 'Pushmi::Command';
 use SVK::I18N;
 
-my $logger = Pushmi::Config->logger('pushmi.svkmirror');
-
 sub run_with_auth {
     my ($self, $repospath, $url) = @_;
     my $pushmi = Pushmi::Mirror->new( path => $repospath );
@@ -21,7 +19,7 @@
     $pushmi->install_hook($repospath);
     $pushmi->repos->fs->set_uuid($mirror->server_uuid);
 
-    $logger->info(loc("Mirror initialized.\n"));
+    $self->logger->info(loc("Mirror initialized.\n"));
 
     return;
 }

Modified: Pushmi/trunk/lib/Pushmi/Command/Runhook.pm
==============================================================================
--- Pushmi/trunk/lib/Pushmi/Command/Runhook.pm	(original)
+++ Pushmi/trunk/lib/Pushmi/Command/Runhook.pm	Tue Aug  5 11:30:47 2008
@@ -6,8 +6,6 @@
 use SVK::I18N;
 our $AUTHOR;
 
-my $logger = Pushmi::Config->logger('pushmi.runhook');
-
 sub options {
     return ( Pushmi::Command->options, 'txnname=s' => 'txnname' );
 }
@@ -52,7 +50,7 @@
 
     # XXX: if we reentrant, the mirror will be in deadlock.
     $AUTHOR = $txn->prop('svn:author');
-    $logger->info("[$repospath] committing from txn $self->{txnname} by $AUTHOR");
+    $self->logger->info("[$repospath] committing from txn $self->{txnname} by $AUTHOR");
     # retrieve from memcached as soon as possible, as get_editor might
     # delay because of the server latency of the first response
     _get_password();
@@ -89,12 +87,12 @@
     my $sync_upto;
     my $error;
     ${ $arg{post_handler} } = sub {
-	$logger->info("[$repospath] committed as $_[0]");
+	$self->logger->info("[$repospath] committed as $_[0]");
 	my $token = join(':', $mirror->repos->path, $mirror->_lock_token);
 	$txn->change_prop( 'svk:committed-by' => $token );
         $mirror->_backend->_revmap_prop( $txn, $_[0] );
         $sync_upto = $_[0] - 1;
-        $logger->debug("post handle decides to sync upto $sync_upto");
+        $self->logger->debug("post handle decides to sync upto $sync_upto");
 
         return 0;
     };
@@ -102,7 +100,7 @@
     {
 	local $SVN::Error::handler = sub {
 	    $_[0]->clear;
-            $logger->debug('Fail to replay: '.Carp::longmess);
+            $self->logger->debug('Fail to replay: '.Carp::longmess);
 	    die $_[0]->message."\n";
 	};
 
@@ -111,9 +109,9 @@
             $editor->close_edit;
         };
 	if ($error = $@) {
-	    $logger->info("[$repospath] Failed to replay txn to mirror: $error");
+	    $self->logger->info("[$repospath] Failed to replay txn to mirror: $error");
             eval { $txn->change_prop('pushmi:dead', '*'); 1 }
-                or $logger->warn("[$repospath] Unable to mark dead txn as dead.");
+                or $self->logger->warn("[$repospath] Unable to mark dead txn as dead.");
 	}
     }
 
@@ -128,9 +126,9 @@
 
     $mirror->_backend->_mirror_changesets( $sync_upto,
         sub { $first ||= $_[0]; $last = $_[0] } );
-    $logger->info("[$repospath] sync revision $first to $last") if $first;
+    $self->logger->info("[$repospath] sync revision $first to $last") if $first;
     if ($error) {
-        $logger->debug("Unlock on failure");
+        $self->logger->debug("Unlock on failure");
 	$mirror->unlock;
 	die $error;
     }
@@ -142,10 +140,11 @@
 sub _get_password {
     return $_cached_password if defined $_cached_password;
 
-    $logger->error_die("unable to get author info from txn")
+    Pushmi::Command::Runhook->logger->error_die("unable to get author info from txn")
 	unless defined $AUTHOR;
 
     my $memd = Pushmi::Config->memcached;
+    my $logger = Pushmi::Config->logger('pushmi.runhook');
     my $password = $memd->get($AUTHOR);
 
     # XXX: can we decline from the prompt handler?
@@ -161,9 +160,9 @@
     my $func = Pushmi::Command::Mirror->can('pushmi_auth');
     goto $func if $config->{use_shared_commit};
 
-    $logger->debug("Try to authenticate as $AUTHOR");
+    Pushmi::Command::Runhook->logger->debug("Try to authenticate as $AUTHOR");
     my $password = _get_password;
-    $logger->debug("Failed to get password") unless defined $password;
+    Pushmi::Command::Runhook->logger->debug("Failed to get password") unless defined $password;
     $cred->username($AUTHOR);
     $cred->password($password);
     $cred->may_save(0);

Modified: Pushmi/trunk/lib/Pushmi/Command/Runlock.pm
==============================================================================
--- Pushmi/trunk/lib/Pushmi/Command/Runlock.pm	(original)
+++ Pushmi/trunk/lib/Pushmi/Command/Runlock.pm	Tue Aug  5 11:30:47 2008
@@ -3,7 +3,6 @@
 use warnings;
 use base 'Pushmi::Command';
 use SVK::I18N;
-my $logger = Pushmi::Config->logger('pushmi.runlock');
 
 sub options {
     return (

Modified: Pushmi/trunk/lib/Pushmi/Command/Rununlock.pm
==============================================================================
--- Pushmi/trunk/lib/Pushmi/Command/Rununlock.pm	(original)
+++ Pushmi/trunk/lib/Pushmi/Command/Rununlock.pm	Tue Aug  5 11:30:47 2008
@@ -3,7 +3,6 @@
 use warnings;
 use base 'Pushmi::Command';
 use SVK::I18N;
-my $logger = Pushmi::Config->logger('pushmi.runlock');
 
 sub options {
     return (

Modified: Pushmi/trunk/lib/Pushmi/Command/Sync.pm
==============================================================================
--- Pushmi/trunk/lib/Pushmi/Command/Sync.pm	(original)
+++ Pushmi/trunk/lib/Pushmi/Command/Sync.pm	Tue Aug  5 11:30:47 2008
@@ -4,9 +4,6 @@
 use base 'Pushmi::Command';
 use SVK::I18N;
 
-my $memd = Pushmi::Config->memcached;
-my $logger = Pushmi::Config->logger('pushmi.sync');
-
 sub options {
     return (
         Pushmi::Command->options,
@@ -17,11 +14,14 @@
 
 sub run_with_auth {
     my ($self, $repospath) = @_;
+
+    my $memd = Pushmi::Config->memcached;
+
     my $pushmi = Pushmi::Mirror->new( path => $repospath );
     $pushmi->ensure_consistency;
 
     if ($self->{nowait} and $pushmi->locked) {
-        print loc("Mirror on $repospath is locked by %1, skipping.\n", $pushmi->locked);
+        $self->logger->info(loc("Mirror on $repospath is locked by %1, skipping.\n", $pushmi->locked));
         return;
     }
 
@@ -36,8 +36,8 @@
     $pushmi->master->mirror_changesets(undef,
         sub { $first ||= $_[0]; $last = $_[0] });
     };
-    $logger->error("[$repospath] sync failed: $@") if $@;
-    $logger->info("[$repospath] sync revision $first to $last") if $first;
+    $self->logger->error("[$repospath] sync failed: $@") if $@;
+    $self->logger->info("[$repospath] sync revision $first to $last") if $first;
 
     return;
 }

Modified: Pushmi/trunk/lib/Pushmi/Command/Unlock.pm
==============================================================================
--- Pushmi/trunk/lib/Pushmi/Command/Unlock.pm	(original)
+++ Pushmi/trunk/lib/Pushmi/Command/Unlock.pm	Tue Aug  5 11:30:47 2008
@@ -3,8 +3,6 @@
 use warnings;
 use base 'Pushmi::Command';
 
-my $logger = Pushmi::Config->logger('pushmi.unlock');
-
 sub options {
     return ( Pushmi::Command->options, 'revision=i' => 'revision' );
 }
@@ -18,15 +16,15 @@
         # non-runhook commits (like sync), nothing to unlock for.
         my $expected = $pushmi->repos->fs->revision_prop($self->{revision}, 'svk:committed-by') or return;
         if ($expected ne $token) {
-            $logger->logdie("[$repospath] revision $self->{revision} does not own lock $expected, expecting $token");
+            $self->logger->logdie("[$repospath] revision $self->{revision} does not own lock $expected, expecting $token");
         }
     }
     if (my $content = $pushmi->locked ) {
-        $logger->info("[$repospath] lock $token ($content) removed");
+        $self->logger->info("[$repospath] lock $token ($content) removed");
         $pushmi->unlock('force');
     }
     else {
-        $logger->info("[$repospath] lock $token not found");
+        $self->logger->info("[$repospath] lock $token not found");
     }
 
     return;

Modified: Pushmi/trunk/lib/Pushmi/Command/Verify.pm
==============================================================================
--- Pushmi/trunk/lib/Pushmi/Command/Verify.pm	(original)
+++ Pushmi/trunk/lib/Pushmi/Command/Verify.pm	Tue Aug  5 11:30:47 2008
@@ -6,8 +6,6 @@
 
 use IPC::Run3 'run3';
 
-my $logger = Pushmi::Config->logger('pushmi.verify');
-
 sub options {
     return (
         Pushmi::Command->options,
@@ -37,15 +35,15 @@
         };
 
     unless ($?) {
-	$logger->debug("[$repospath] revision $self->{revision} verified");
+	$self->logger->debug("[$repospath] revision $self->{revision} verified");
 	return;
     }
 
-    $logger->logdie("[$repospath] can't run verify: $!") if $? == -1;
+    $self->logger->logdie("[$repospath] can't run verify: $!") if $? == -1;
 
     $pushmi->repos->fs->change_rev_prop(0, 'pushmi:inconsistent', $self->{revision});
 
-    $logger->logdie("[$repospath] can't verify: $output");
+    $self->logger->logdie("[$repospath] can't verify: $output");
 }
 
 package Pushmi::Command::Verify::enable;



More information about the Bps-public-commit mailing list