[Bps-public-commit] Prophet branch, master, updated. b8c45cee867cc1a722eceb70d78a39501ec616d9
spang at bestpractical.com
spang at bestpractical.com
Thu Aug 27 20:00:19 EDT 2009
The branch, master has been updated
via b8c45cee867cc1a722eceb70d78a39501ec616d9 (commit)
via 904e64ab573695a5690c8b6c6b6606a0fd513a7c (commit)
via 168a27b16b30e7bfc5582e246a3eb45a2de7fd02 (commit)
from 7b57a8c61eddc1b0f9314d8d0c8c928eaff6fe12 (commit)
Summary of changes:
lib/Prophet/CLI/Command/Clone.pm | 37 +++++++++++-----------
lib/Prophet/CLI/Command/Merge.pm | 9 +++--
lib/Prophet/ForeignReplica.pm | 63 +++++++++++++++++++++++++++++++------
lib/Prophet/Replica.pm | 52 +++++++++++++++++++------------
4 files changed, 108 insertions(+), 53 deletions(-)
- Log -----------------------------------------------------------------
commit 168a27b16b30e7bfc5582e246a3eb45a2de7fd02
Author: Christine Spang <spang at bestpractical.com>
Date: Wed Aug 26 15:15:18 2009 +0100
Reformat some code with wrapping lines
diff --git a/lib/Prophet/Replica.pm b/lib/Prophet/Replica.pm
index 62ab3be..a4cfe7d 100644
--- a/lib/Prophet/Replica.pm
+++ b/lib/Prophet/Replica.pm
@@ -57,7 +57,7 @@ has after_initialize => (
has uuid_generator => (
is => 'rw',
isa => 'Prophet::UUIDGenerator',
- lazy => 1,
+ lazy => 1,
default => sub {
my $self = shift;
my $ug = Prophet::UUIDGenerator->new( uuid_scheme => 2 );
@@ -225,13 +225,13 @@ sub import_changesets {
my $self = shift;
my %args = validate(
@_,
- { from => { isa => 'Prophet::Replica' },
- resdb => { optional => 1 },
- resolver => { optional => 1 },
- resolver_class => { optional => 1 },
- conflict_callback => { type => CODEREF, optional => 1 },
- reporting_callback => { type => CODEREF, optional => 1 },
- force => { optional => 1 },
+ { from => { isa => 'Prophet::Replica' },
+ resdb => { optional => 1 },
+ resolver => { optional => 1 },
+ resolver_class => { optional => 1 },
+ conflict_callback => { type => CODEREF, optional => 1 },
+ reporting_callback => { type => CODEREF, optional => 1 },
+ force => { optional => 1 },
}
);
@@ -239,22 +239,33 @@ sub import_changesets {
$self->_check_db_uuids_on_merge(for => $source, force => $args{'force'});
- warn "The source (@{[$source->url]}) does not exist" unless ($source->replica_exists);
+ warn "The source (@{[$source->url]}) does not exist"
+ unless ($source->replica_exists);
- $self->log_debug("Integrating changesets from ".$source->uuid. " after ". $self->last_changeset_from_source( $self->uuid ));
+ $self->log_debug("Integrating changesets from ".$source->uuid.
+ " after ". $self->last_changeset_from_source( $self->uuid ));
$source->traverse_changesets(
- after => $self->last_changeset_from_source( $source->uuid ),
- before_load_changeset_callback => sub {
+ after =>
+ $self->last_changeset_from_source( $source->uuid ),
+ before_load_changeset_callback => sub {
my %args = (@_);
- my ($seq, $orig_uuid, $orig_seq, $key) = @{$args{changeset_metadata}};
+ my ($seq, $orig_uuid, $orig_seq, $key)
+ = @{$args{changeset_metadata}};
# skip changesets we've seen before
- if ( $self->has_seen_changeset( source_uuid => $orig_uuid, sequence_no => $orig_seq) ){
- # If we've seen the changeset, yet we still got here, it means we saw it by original
- # replica/sequence pair, but not # the direct upstream's uuid/sequence pair.
- # recording that can help performance a whole bunch for next sync
- if ($source->uuid && $seq && $seq > $self->last_changeset_from_source($source->uuid)) {
- $self->record_last_changeset_from_replica( $source->uuid => $seq);
+ if ( $self->has_seen_changeset( source_uuid => $orig_uuid,
+ sequence_no => $orig_seq) ){
+ # If we've seen the changeset, yet we still got here, it
+ # means we saw it by original
+
+ # replica/sequence pair, but not # the direct upstream's
+ # uuid/sequence pair.
+ # recording that can help performance a whole bunch for
+ # next sync
+ if ($source->uuid && $seq && $seq
+ > $self->last_changeset_from_source($source->uuid)) {
+ $self->record_last_changeset_from_replica(
+ $source->uuid => $seq);
}
return undef;
} else {
@@ -274,7 +285,8 @@ sub import_changesets {
);
if ( ref( $callback_args{'after_integrate_changeset'} ) ) {
- $callback_args{'after_integrate_changeset'}->( changeset => $callback_args{'changeset'} );
+ $callback_args{'after_integrate_changeset'}->(
+ changeset => $callback_args{'changeset'} );
}
}
commit 904e64ab573695a5690c8b6c6b6606a0fd513a7c
Author: Christine Spang <spang at bestpractical.com>
Date: Thu Aug 27 18:36:24 2009 +0100
Generalise Prophet::ForeignReplica->prompt_for_login
Sometimes, you want the prompt to say something other than
"Username for <uri>" and "Password for <username> @ <uri>"
without duping all the logic code in here.
diff --git a/lib/Prophet/ForeignReplica.pm b/lib/Prophet/ForeignReplica.pm
index abec3df..5e5169e 100644
--- a/lib/Prophet/ForeignReplica.pm
+++ b/lib/Prophet/ForeignReplica.pm
@@ -63,31 +63,72 @@ sub uuid_for_url {
return $self->uuid_generator->create_string_from_url( $url );
}
-sub prompt_for_login {
- my ( $self, $uri, $username ) = @_;
+=head2 prompt_for_login
+
+Interactively prompt the user for a username and an authentication secret
+(usually a password).
+
+Named parameters:
+
+ uri
+ username
+ username_prompt
+ secret_prompt
+
+To use the default prompts, which ask for a username and password, pass in
+C<uri> and (optionally) C<username>. The username prompt will be skipped
+if a username is passed in.
+
+You can also override the default prompts by passing in subroutines for
+C<username_prompt> and/or C<secret_prompt>. These subroutines return strings
+to be printed and are called like this:
+
+ username_prompt( uri )
+ secret_prompt( uri, username )
- my $password;
+Where C<uri> and C<username> are the args that are passed in under those
+names (if any). You don't need to use them; use a closure if you want
+something else.
+
+=cut
+
+sub prompt_for_login {
+ my $self = shift;
+ my %args = (
+ uri => undef,
+ username => undef,
+ secret_prompt => sub {
+ my ($uri, $username) = @_;
+ return "Password for $username: @ $uri: ";
+ },
+ username_prompt => sub {
+ my ($uri) = shift;
+ return "Username for ${uri}: ";
+ },
+ @_,
+ );
+
+ my $secret;
my $was_in_pager = Prophet::CLI->in_pager();
Prophet::CLI->end_pager();
+
# XXX belongs to some CLI callback
use Term::ReadKey;
local $| = 1;
- unless ($username) {
- print "Username for $uri: ";
+ unless ($args{username}) {
+ print $args{username_prompt}($args{uri});
ReadMode 1;
- $username = ReadLine 0;
- chomp $username;
+ chomp( $args{username} = ReadLine 0 );
}
- print "Password for $username @ $uri: ";
+ print $args{secret_prompt}($args{uri}, $args{username});
ReadMode 2;
- $password = ReadLine 0;
- chomp $password;
+ chomp( $secret = ReadLine 0 );
ReadMode 1;
print "\n";
Prophet::CLI->start_pager() if ($was_in_pager);
- return ( $username, $password );
+ return ( $args{username}, $secret );
}
sub log {
commit b8c45cee867cc1a722eceb70d78a39501ec616d9
Author: Christine Spang <spang at bestpractical.com>
Date: Thu Aug 27 20:11:28 2009 +0100
Don't instantiate handle objects twice on clone
The most noticeable benefit of this right away is that we don't get
double prompts for foreign replica clones, since many of these prompt for
the username/password in BUILD methods.
diff --git a/lib/Prophet/CLI/Command/Clone.pm b/lib/Prophet/CLI/Command/Clone.pm
index 9473528..fd40af6 100644
--- a/lib/Prophet/CLI/Command/Clone.pm
+++ b/lib/Prophet/CLI/Command/Clone.pm
@@ -20,38 +20,39 @@ sub run {
$self->set_arg( 'to' => $self->app_handle->handle->url() );
- my $source = Prophet::Replica->get_handle(
- url => $self->arg('from'),
+ $self->source( Prophet::Replica->get_handle(
+ url => $self->arg('from'),
app_handle => $self->app_handle,
- );
- my $target = Prophet::Replica->get_handle(
- url => $self->arg('to'),
+ ));
+
+ $self->target( Prophet::Replica->get_handle(
+ url => $self->arg('to'),
app_handle => $self->app_handle,
- );
+ ));
- if ( $target->replica_exists ) {
+ if ( $self->target->replica_exists ) {
die "The target replica already exists.\n";
}
- if ( !$target->can_initialize ) {
+ if ( !$self->target->can_initialize ) {
die "The target replica path you specified can't be created.\n";
}
my %init_args;
- if ( $source->isa('Prophet::ForeignReplica') ) {
- $target->after_initialize( sub { shift->app_handle->set_db_defaults } );
+ if ( $self->source->isa('Prophet::ForeignReplica') ) {
+ $self->target->after_initialize( sub { shift->app_handle->set_db_defaults } );
} else {
%init_args = (
- db_uuid => $source->db_uuid,
- resdb_uuid => $source->resolution_db_handle->db_uuid,
+ db_uuid => $self->source->db_uuid,
+ resdb_uuid => $self->source->resolution_db_handle->db_uuid,
);
}
- unless ($source->replica_exists) {
- die "The source replica '@{[$source->url]}' doesn't exist or is unreadable.\n";
+ unless ($self->source->replica_exists) {
+ die "The source replica '@{[$self->source->url]}' doesn't exist or is unreadable.\n";
}
- $target->initialize(%init_args);
+ $self->target->initialize(%init_args);
# create new config section for this replica
my $from = $self->arg('from');
@@ -62,13 +63,13 @@ sub run {
value => $self->arg('from'),
},
{ key => 'replica.'.$from.'.uuid',
- value => $target->uuid,
+ value => $self->target->uuid,
},
]
);
- if ( $source->can('database_settings') ) {
- my $remote_db_settings = $source->database_settings;
+ if ( $self->source->can('database_settings') ) {
+ my $remote_db_settings = $self->source->database_settings;
my $default_settings = $self->app_handle->database_settings;
for my $name ( keys %$remote_db_settings ) {
my $uuid = $default_settings->{$name}[0];
diff --git a/lib/Prophet/CLI/Command/Merge.pm b/lib/Prophet/CLI/Command/Merge.pm
index c1d44f3..1fa36c1 100644
--- a/lib/Prophet/CLI/Command/Merge.pm
+++ b/lib/Prophet/CLI/Command/Merge.pm
@@ -33,14 +33,14 @@ sub run {
Prophet::CLI->end_pager();
$self->source( Prophet::Replica->get_handle(
- url => $self->arg('from'),
+ url => $self->arg('from'),
app_handle => $self->app_handle,
- ));
+ )) unless $self->source; # subclass may already have set source
$self->target( Prophet::Replica->get_handle(
- url => $self->arg('to'),
+ url => $self->arg('to'),
app_handle => $self->app_handle,
- ));
+ )) unless $self->target; # subclass may already have set target
$self->validate_merge_replicas($self->source => $self->target);
@@ -54,6 +54,7 @@ sub run {
$self->target->import_resolutions_from_remote_replica(
from => $self->source,
force => $self->has_arg('force'),
+ resolver_class => 'Prophet::Resolver::Prompt',
) if ($self->source->resolution_db_handle);
my $changesets = $self->_do_merge();
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list