[Bps-public-commit] r16117 - in Prophet/branches/dispatcher: . lib/Prophet/CLI
sartak at bestpractical.com
sartak at bestpractical.com
Sat Sep 27 16:47:12 EDT 2008
Author: sartak
Date: Sat Sep 27 16:47:12 2008
New Revision: 16117
Removed:
Prophet/branches/dispatcher/lib/Prophet/CLI/Command/Pull.pm
Modified:
Prophet/branches/dispatcher/ (props changed)
Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm
Log:
r72982 at onn: sartak | 2008-09-27 15:52:50 -0400
pull command
Modified: Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm (original)
+++ Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm Sat Sep 27 16:47:12 2008
@@ -209,6 +209,47 @@
run('merge', $self, @_);
};
+on pull => sub {
+ my $self = shift;
+ my @from;
+
+ my $from = $self->context->arg('from');
+
+ $self->context->set_arg(db_uuid => $self->cli->handle->db_uuid)
+ unless $self->context->has_arg('db_uuid');
+
+ my %previous_sources = $self->_read_cached_upstream_replicas;
+ push @from, $from
+ if $from
+ && (!$self->context->has_arg('all') || !$previous_sources{$from});
+
+ push @from, keys %previous_sources if $self->context->has_arg('all');
+
+ my @bonjour_replicas = $self->find_bonjour_replicas;
+
+ die "Please specify a --from, --local or --all.\n"
+ unless $from
+ || $self->context->has_arg('local')
+ || $self->context->has_arg('all');
+
+ $self->context->set_arg(to => $self->cli->app_handle->default_replica_type
+ . ":file://"
+ . $self->cli->handle->fs_root );
+
+ for my $from ( @from, @bonjour_replicas ) {
+ print "Pulling from $from\n";
+ #if ( $self->has_arg('all') || $self->has_arg('local') );
+ $self->context->set_arg(from => $from);
+ run("merge", $self, @_);
+ print "\n";
+ }
+
+ if ( $from && !exists $previous_sources{$from} ) {
+ $previous_sources{$from} = 1;
+ $self->_write_cached_upstream_replicas(%previous_sources);
+ }
+};
+
# catch-all. () makes sure we don't hit the annoying historical feature of
# the empty regex meaning the last-used regex
on qr/()/ => sub {
@@ -378,6 +419,73 @@
return $resolver;
}
+=head2 find_bonjour_replicas
+
+Probes the local network for bonjour replicas if the local arg is specified.
+
+Returns a list of found replica URIs.
+
+=cut
+
+sub find_bonjour_replicas {
+ my $self = shift;
+ my @bonjour_replicas;
+ if ( $self->context->has_arg('local') ) {
+ Prophet::App->try_to_require('Net::Bonjour');
+ if ( Prophet::App->already_required('Net::Bonjour') ) {
+ print "Probing for local database replicas with Bonjour\n";
+ my $res = Net::Bonjour->new('prophet');
+ $res->discover;
+ foreach my $entry ( $res->entries ) {
+ if ( $entry->name eq $self->context->arg('db_uuid') ) {
+ print "Found a database replica on " . $entry->hostname."\n";
+ my $uri = URI->new();
+ $uri->scheme( 'http' );
+ $uri->host($entry->hostname);
+ $uri->port( $entry->port );
+ $uri->path('replica/');
+ push @bonjour_replicas, $uri->canonical.""; #scalarize
+ }
+ }
+ }
+
+ }
+ return @bonjour_replicas;
+}
+
+=head2 _read_cached_upstream_replicas
+
+Returns a hash containing url => 1 pairs, where the URLs are the replicas that
+have been previously pulled from.
+
+=cut
+
+sub _read_cached_upstream_replicas {
+ my $self = shift;
+ return map { $_ => 1 } $self->cli->handle->_read_cached_upstream_replicas;
+}
+
+=head2 _write_cached_upstream_replicas %replicas
+
+Writes the replica URLs given in C<keys %replicas> to the current Prophet
+repository's upstream replica cache (these replicas will be pulled from when a
+user specifies --all).
+
+=cut
+
+sub _write_cached_upstream_replicas {
+ my $self = shift;
+ my %repos = @_;
+ return $self->handle->_write_cached_upstream_replicas(keys %repos);
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+
+
+1;
+
no Moose;
__PACKAGE__->meta->make_immutable;
More information about the Bps-public-commit
mailing list