[Bps-public-commit] r16828 - in Prophet/trunk: lib/Prophet/CLI/Command lib/Prophet/Test t
jesse at bestpractical.com
jesse at bestpractical.com
Wed Nov 12 21:44:18 EST 2008
Author: jesse
Date: Wed Nov 12 21:44:17 2008
New Revision: 16828
Modified:
Prophet/trunk/lib/Prophet/CLI/Command/Clone.pm
Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm
Prophet/trunk/lib/Prophet/Config.pm
Prophet/trunk/lib/Prophet/Record.pm
Prophet/trunk/lib/Prophet/Test.pm
Prophet/trunk/lib/Prophet/Test/Participant.pm
Prophet/trunk/t/config.t
Prophet/trunk/t/export.t
Prophet/trunk/t/real-conflicting-merge.t
Prophet/trunk/t/simple-conflicting-merge.t
Prophet/trunk/t/simple-push.t
Log:
* new format for ticket lists
* move replica list from replica internals to the config file
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Clone.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Clone.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Clone.pm Wed Nov 12 21:44:17 2008
@@ -8,27 +8,26 @@
$self->set_arg( 'to' => $self->app_handle->handle->url() );
my $source = Prophet::Replica->new(
- url => $self->arg('from'),
+ url => $self->arg('from'),
app_handle => $self->app_handle,
);
my $target = Prophet::Replica->new(
- url => $self->arg('to'),
+ url => $self->arg('to'),
app_handle => $self->app_handle,
);
if ( $target->replica_exists ) {
- die "The target replica already exists.";
+ die "The target replica already exists.";
}
- if (!$target->can_initialize ) {
+ if ( !$target->can_initialize ) {
die "The replica path you specified isn't writable";
}
my %init_args;
- if ($source->isa('Prophet::ForeignReplica')) {
+ if ( $source->isa('Prophet::ForeignReplica') ) {
$target->after_initialize( sub { shift->app_handle->set_db_defaults } );
- }
- else {
+ } else {
%init_args = (
db_uuid => $source->db_uuid,
resdb_uuid => $source->resolution_db_handle->db_uuid,
@@ -36,9 +35,14 @@
}
$target->initialize(%init_args);
- $target->_write_cached_upstream_replicas($self->arg('from'));
+ $self->app_handle->config->set(
+ _sources =>
+ { $self->arg('from') => $self->arg('from') }
+ );
+ $self->app_handle->config->save;
+
$self->SUPER::run();
-};
+}
__PACKAGE__->meta->make_immutable;
no Moose;
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm Wed Nov 12 21:44:17 2008
@@ -6,26 +6,26 @@
my $self = shift;
my @from;
- if ($self->app_handle->handle->replica_exists) {
- $self->set_arg( db_uuid => $self->app_handle->handle->db_uuid ) unless ($self->arg('db_uuid'));
- }
- my %previous_sources = $self->_read_cached_upstream_replicas;
- push @from, $self->arg('from')
- if ($self->arg('from') && ( !$self->has_arg('all') || !$previous_sources{$self->arg('from')}));
- push @from, keys %previous_sources if $self->has_arg('all');
+ my $previous_sources = $self->app_handle->config->sources;
- my @bonjour_replicas = $self->find_bonjour_replicas;
- die "Please specify a --from, --local or --all.\n"
- unless ( $self->has_arg('from')
- || $self->has_arg('local')
- || $self->has_arg('all') );
+ my $explicit_from;
+
+ if ($self->has_arg('from')) {
+ $explicit_from = $self->arg('from') ;
+ push @from, $explicit_from;
+ }
+
+ elsif ($self->has_arg('all')){
+ push @from, values %$previous_sources;
+ }
+ $self->validate_args;
$self->set_arg( to => $self->cli->app_handle->default_replica_type
. ":file://"
. $self->handle->fs_root );
- for my $from ( @from, @bonjour_replicas ) {
+ for my $from ( @from, $self->find_bonjour_sources ) {
print "Pulling from $from\n";
#if ( $self->has_arg('all') || $self->has_arg('local') );
$self->set_arg( from => $from );
@@ -33,13 +33,32 @@
print "\n";
}
- if ( $self->arg('from') && !exists $previous_sources{$self->arg('from')} ) {
- $previous_sources{$self->arg('from')} = 1;
- $self->_write_cached_upstream_replicas(%previous_sources);
- }
+ $self->record_pull_from_source($explicit_from) if ($explicit_from);
};
-=head2 find_bonjour_replicas
+sub record_pull_from_source {
+ my $self = shift;
+ my $source = shift;
+ my $previous_sources = $self->app_handle->config->sources;
+ my %sources_by_url = map { $previous_sources->{$_} => $_ }
+ %$previous_sources;
+ if ( !exists $sources_by_url{$source}) {
+ $previous_sources->{$source} = $source;
+ $self->app_handle->config->set(_sources => $previous_sources );
+ $self->app_handle->config->save;
+ }
+}
+
+
+sub validate_args {
+ my $self = shift;
+ die "Please specify a --from, --local or --all.\n"
+ unless ( $self->has_arg('from')
+ || $self->has_arg('local')
+ || $self->has_arg('all') );
+}
+
+=head2 find_bonjour_sources
Probes the local network for bonjour replicas if the local arg is specified.
@@ -47,9 +66,12 @@
=cut
-sub find_bonjour_replicas {
+sub find_bonjour_sources {
my $self = shift;
- my @bonjour_replicas;
+ my @bonjour_sources;
+
+ my $db_uuid = $self->arg('db_uuid') || $self->app_handle->handle->db_uuid;
+
if ( $self->has_arg('local') ) {
Prophet::App->try_to_require('Net::Bonjour');
if ( Prophet::App->already_required('Net::Bonjour') ) {
@@ -57,7 +79,7 @@
my $res = Net::Bonjour->new('prophet');
$res->discover;
for my $entry ( $res->entries ) {
- if ( $entry->name eq $self->arg('db_uuid') ) {
+ if ( $entry->name eq $db_uuid ) {
print "Found a database replica on " . $entry->hostname."\n";
require URI;
my $uri = URI->new();
@@ -65,39 +87,13 @@
$uri->host($entry->hostname);
$uri->port( $entry->port );
$uri->path('replica/');
- push @bonjour_replicas, $uri->canonical.""; #scalarize
+ push @bonjour_sources, $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->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);
+ return @bonjour_sources;
}
__PACKAGE__->meta->make_immutable;
Modified: Prophet/trunk/lib/Prophet/Config.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Config.pm (original)
+++ Prophet/trunk/lib/Prophet/Config.pm Wed Nov 12 21:44:17 2008
@@ -34,15 +34,24 @@
return $_[0]->config->{_aliases};
}
+
+sub sources {
+ return $_[0]->config->{_sources};
+}
+
+
sub app_config_file {
my $self = shift;
return $self->file_if_exists($ENV{'PROPHET_APP_CONFIG'})
- || $self->file_if_exists(
- File::Spec->catfile(
- $self->app_handle->handle->fs_root => 'prophetrc' ))
- || $self->file_if_exists(
- File::Spec->catfile( $ENV{'HOME'} => '.prophetrc' ));
+ || $self->file_if_exists( $self->replica_config_file)
+ || $self->file_if_exists( File::Spec->catfile( $ENV{'HOME'} => '.prophetrc' ))
+ || $self->replica_config_file
+}
+
+sub replica_config_file {
+ my $self = shift;
+ return File::Spec->catfile( $self->app_handle->handle->fs_root => 'prophetrc' )
}
#my $singleton;
@@ -69,16 +78,19 @@
for my $line ($file->slurp) {
$line =~ s/\#.*$//; # strip comments
- next unless ($line =~ /^([^:]+?)\s*=\s*(.*)$/);
+ next unless ($line =~ /^(.*?)\s*=\s*(.*)$/);
my $key = $1;
my $val = $2;
if ($key =~ m!alias\s+(.+)!) {
$config->{_aliases}->{$1} = $val;
+ } elsif ($key =~ m!source\s+(.+)!) {
+ $config->{_sources}->{$1} = $val;
} else {
$config->{$key} = $val;
}
}
$config->{_aliases} ||= {}; # default aliases is null.
+ $config->{_sources} ||= {}; # default to no sources.
}
sub display_name_for_uuid {
@@ -112,7 +124,7 @@
#XXX TODO this won't save comments, which I think we should do.
#in case of overwriting your file( you will hate me for that ),
-#I chose to update alias only for now.
+#I chose to update alias and source lines only for now.
sub save {
my $self = shift;
@@ -127,11 +139,16 @@
open my $fh, '>', $file or die "can't save config to $file: $!";
for my $line (@lines) {
- # skip old aliases
- next if $line =~ /^ \s* alias \s+ .+ \s* = \s* .+/x;
+ # skip old aliases and sources
+ next if $line =~ /^ \s* (?:alias|source) \s+ .+ \s* = \s* .+/x;
print $fh $line;
}
+ if ( $self->sources ) {
+ for my $source ( keys %{ $self->sources } ) {
+ print $fh "source $source = " . $self->sources->{$source} . "\n";
+ }
+ }
if ( $self->aliases ) {
for my $alias ( keys %{ $self->aliases } ) {
print $fh "alias $alias = " . $self->aliases->{$alias} . "\n";
Modified: Prophet/trunk/lib/Prophet/Record.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Record.pm (original)
+++ Prophet/trunk/lib/Prophet/Record.pm Wed Nov 12 21:44:17 2008
@@ -559,7 +559,7 @@
=cut
-sub _default_summary_format { 'No summary format defined for this record type' }
+sub _default_summary_format { undef }
=head2 _summary_format
@@ -588,10 +588,12 @@
sub _atomize_summary_format {
my $self = shift;
my $format = shift || $self->_summary_format;
+
+ return undef unless $format;
return split /\s*\|\s*/, $format;
}
-=head2 _parse_summary_format
+=head2 _parse_format_summary
Parses the summary format for this record's type (or the default summary
format if no type-specific format exists).
@@ -637,13 +639,15 @@
$prop = $value = $atom;
}
- @atom_data{'format', 'prop'} = ($format, $prop);
- $atom_data{value} = $self->atom_value($value);
- $atom_data{formatted} = $self->format_atom($format => $atom_data{value});
+ my $atom_value = $self->atom_value($value);
+ push @out, {
+ format => $format,
+ prop => $prop,
+ value => $atom_value,
+ formatted => $self->format_atom( $format => $atom_value )
- push @out, \%atom_data;
+ };
}
-
return @out;
}
@@ -657,11 +661,50 @@
sub format_summary {
my $self = shift;
- my @out = $self->_parse_format_summary;
+ my @out = $self->_summary_format ?
+ $self->_parse_format_summary
+ :
+ $self->_format_all_props_raw
+ ;
return @out if wantarray;
return join ' ', map { $_->{formatted} } @out;
}
+sub _format_all_props_raw {
+ my $self = shift;
+ my $props = $self->get_props;
+
+ my @out;
+
+ push @out,
+ {
+ prop => 'uuid',
+ value => $self->uuid,
+ format => '%s',
+ formatted => "'uuid': '" . $self->uuid . "'"
+ };
+ push @out, {
+ prop => 'luid',
+ value => $self->luid,
+ format => '%s',
+ formatted => "'luid': '"
+ . $self->luid . "'"
+
+ };
+
+ for my $prop ( keys %$props ) {
+ push @out,
+ {
+ prop => $prop,
+ value => $props->{$prop},
+ format => '%s',
+ formatted => "'$prop': '" . $props->{$prop} . "'"
+ };
+ }
+ return @out;
+}
+
+
=head2 atom_value $value_in
Takes an input value from a summary format atom and returns either its
Modified: Prophet/trunk/lib/Prophet/Test.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Test.pm (original)
+++ Prophet/trunk/lib/Prophet/Test.pm Wed Nov 12 21:44:17 2008
@@ -8,7 +8,7 @@
/;
use File::Path 'rmtree';
-use File::Temp qw/tempdir/;
+use File::Temp qw/tempdir tempfile/;
use Path::Class 'dir';
use Test::Exception;
use IPC::Run3 'run3';
@@ -47,7 +47,10 @@
*Test::Builder::plan = sub { };
}
- $ENV{'PROPHET_APP_CONFIG'} = 't/testing.conf';
+
+
+
+ delete $ENV{'PROPHET_APP_CONFIG'};
$ENV{'EMAIL'} = 'nobody at example.com';
}
@@ -99,8 +102,8 @@
# diag(join(' ', @cmd, @$args));
my $ret = run3 [ @cmd, @$args ], undef, \$stdout, \$stderr;
Carp::croak $stderr if $?;
- diag( "STDOUT: " . $stdout ) if ($stdout);
- diag( "STDERR: " . $stderr ) if ($stderr);
+ #diag( "STDOUT: " . $stdout ) if ($stdout);
+ #diag( "STDERR: " . $stderr ) if ($stderr);
#Test::More::diag $stderr;
return ( $ret, $stdout, $stderr );
@@ -123,8 +126,8 @@
local $Test::Builder::Level = $Test::Builder::Level + 1;
my ( $ret, $stdout, $stderr ) = ( run_script( $script, $args ), $msg );
- #diag("STDOUT: " . $stdout) if ($stdout);
- #diag("STDERR: " . $stderr) if ($stderr);
+ diag("STDOUT: " . $stdout) if ($stdout);
+ diag("STDERR: " . $stderr) if ($stderr);
ok($ret, $msg);
};
}
Modified: Prophet/trunk/lib/Prophet/Test/Participant.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Test/Participant.pm (original)
+++ Prophet/trunk/lib/Prophet/Test/Participant.pm Wed Nov 12 21:44:17 2008
@@ -128,7 +128,7 @@
sub get_random_local_record {
my ( $ok, $stdout, $stderr ) = call_func( [qw(search --type Scratch --regex .)] );
- my $update_record = ( shuffle( map { $_ =~ /^(\S*)/ } split( /\n/, $stdout ) ) )[0];
+ my $update_record = ( shuffle( map { $_ =~ /'uuid': '(\S*?)'/ } split( /\n/, $stdout ) ) )[0];
return $update_record;
}
Modified: Prophet/trunk/t/config.t
==============================================================================
--- Prophet/trunk/t/config.t (original)
+++ Prophet/trunk/t/config.t Wed Nov 12 21:44:17 2008
@@ -42,7 +42,7 @@
my $conf = Prophet::Config->new(app_handle => Prophet::CLI->new->app_handle);
# interrogate its config to see if we have any config options set
my @keys = $conf->list;
-is (scalar @keys,3);
+is (scalar @keys,4);
# test the alias
is($conf->aliases->{tlist}, "ticket list", "Got correct alias");
}
Modified: Prophet/trunk/t/export.t
==============================================================================
--- Prophet/trunk/t/export.t (original)
+++ Prophet/trunk/t/export.t Wed Nov 12 21:44:17 2008
@@ -30,7 +30,7 @@
# check our local replicas
my ( $ret, $out, $err ) = run_script( 'prophet', [qw(search --type Bug --regex .)] );
like( $out, qr/new/, "We have the one record from alice" );
- if ( $out =~ /^(.*?)\s./ ) {
+ if ( $out =~ /'uuid': '(.*?)'\s./ ) {
$record_id = $1;
}
diag($record_id);
Modified: Prophet/trunk/t/real-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/real-conflicting-merge.t (original)
+++ Prophet/trunk/t/real-conflicting-merge.t Wed Nov 12 21:44:17 2008
@@ -24,7 +24,8 @@
# check our local replicas
my $out = run_command(qw(search --type Bug --regex .));
like($out, qr/new/, "We have the one record from alice" );
- if ( $out =~ /^(.*?)\s./ ) {
+ diag($out);
+ if ( $out =~ /'uuid': '(.*?)'/ ) {
$record_id = $1;
}
Modified: Prophet/trunk/t/simple-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/simple-conflicting-merge.t (original)
+++ Prophet/trunk/t/simple-conflicting-merge.t Wed Nov 12 21:44:17 2008
@@ -24,7 +24,7 @@
# check our local replicas
my ( $ret, $out, $err ) = run_script( 'prophet', [qw(search --type Bug --regex .)] );
like( $out, qr/new/, "We have the one record from alice" );
- if ( $out =~ /^(.*?)\s./ ) {
+ if ( $out =~ /'uuid': '(.*?)'/ ) {
$record_id = $1;
}
Modified: Prophet/trunk/t/simple-push.t
==============================================================================
--- Prophet/trunk/t/simple-push.t (original)
+++ Prophet/trunk/t/simple-push.t Wed Nov 12 21:44:17 2008
@@ -57,7 +57,7 @@
as_bob {
my ( $ret, $stdout, $stderr )
= run_script( 'prophet', [qw(search --type Bug --regex open-bob)] );
- if ( $stdout =~ /^(.*?)\s/ ) {
+ if ( $stdout =~ /^'uuid': '(.*?)'\s/ ) {
$openbug = $1;
}
diag(
@@ -146,7 +146,7 @@
);
my ( $ret, $stdout, $stderr )
= run_script( 'prophet', [qw(search --type Bug --regex new2)] );
- if ( $stdout =~ /^(.*?)\s/ ) {
+ if ( $stdout =~ /^'uuid': '(.*?)'\s/ ) {
$last_id = $1;
}
};
More information about the Bps-public-commit
mailing list