[Bps-public-commit] Prophet branch, config-gitlike, created. b50d1d02112e12cf0b1c4881b6c1fba4ded1b7e7
spang at bestpractical.com
spang at bestpractical.com
Tue Jun 16 06:51:07 EDT 2009
The branch, config-gitlike has been created
at b50d1d02112e12cf0b1c4881b6c1fba4ded1b7e7 (commit)
- Log -----------------------------------------------------------------
commit a65f6607f9268635493614b0e1bd3834ba211c49
Author: Christine Spang <spang at mit.edu>
Date: Fri Jun 12 14:17:45 2009 +0300
add dep on Config::GitLike
diff --git a/Makefile.PL b/Makefile.PL
index eaba2ce..6992289 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -21,6 +21,7 @@ requires( 'Mouse' => '0.21' );
requires('XML::Atom::SimpleFeed');
requires( 'Path::Dispatcher' => '0.09' ); # Path::Dispatcher::Declarative
requires('Time::Progress');
+requires('Config::GitLike' => '1.0');
build_requires( 'Test::Exception' => '0.26' );
build_requires( 'Test::Script::Run' => '0.02' );
commit ffb88044d00175b46298aec71abce07a4c405b15
Author: Christine Spang <spang at mit.edu>
Date: Tue Jun 16 13:23:59 2009 +0300
Rip out old config system core and replace with Config::GitLike.
diff --git a/lib/Prophet/App.pm b/lib/Prophet/App.pm
index dda9fdd..ea8d726 100644
--- a/lib/Prophet/App.pm
+++ b/lib/Prophet/App.pm
@@ -12,7 +12,8 @@ has handle => (
default => sub {
my $self = shift;
- if ($ENV{'PROPHET_REPO'} !~ /^[\w\+]+\:/ ) {
+ if ( defined $ENV{'PROPHET_REPO'}
+ && $ENV{'PROPHET_REPO'} !~ /^[\w\+]+\:/ ) {
my $path = $ENV{PROPHET_REPO};
$path = File::Spec->rel2abs(glob($path)) unless File::Spec->file_name_is_absolute($path);
$ENV{PROPHET_REPO} = "file://$path";
@@ -27,7 +28,10 @@ has config => (
isa => 'Prophet::Config',
default => sub {
my $self = shift;
- return Prophet::Config->new(app_handle => $self);
+ return Prophet::Config->new(
+ app_handle => $self,
+ confname => 'prophetrc',
+ );
},
documentation => "This is the config instance for the running application",
);
@@ -226,7 +230,7 @@ sub log_fatal {
sub current_user_email {
my $self = shift;
- return $self->config->get('email_address') || $ENV{'PROPHET_EMAIL'} || $ENV{'EMAIL'};
+ return $self->config->get( key => 'user.email-address' ) || $ENV{'PROPHET_EMAIL'} || $ENV{'EMAIL'};
}
diff --git a/lib/Prophet/Config.pm b/lib/Prophet/Config.pm
index 44f287b..ba4040e 100644
--- a/lib/Prophet/Config.pm
+++ b/lib/Prophet/Config.pm
@@ -2,6 +2,7 @@ package Prophet::Config;
use Any::Moose;
use File::Spec;
use Prophet::Util;
+extends 'Config::GitLike';
has app_handle => (
is => 'ro',
@@ -10,151 +11,86 @@ has app_handle => (
required => 0
);
-has config_files => (
- is => 'rw',
- isa => 'ArrayRef' ,
- default =>sub {[]}
-);
+# reload config after setting values
+after set => sub {
+ my $self = shift;
-has config => (
- is => 'rw',
- isa => 'HashRef',
- lazy => 0,
- default => sub {shift->load_from_files;},
-);
+ $self->load;
+};
-sub get { $_[0]->config->{$_[1]} }
-sub set { $_[0]->config->{$_[1]} = $_[2] }
-sub list { keys %{ $_[0]->config } }
+# per-replica config filename
+override dir_file => sub { 'config' };
-sub aliases {
- return $_[0]->config->{_aliases} || {};
-}
-
-
-sub sources {
- return $_[0]->config->{_sources};
-}
+# Override the replica config file with the PROPHET_APP_CONFIG
+# env var if it's set. Also, don't walk up the given path if no replica
+# config is found.
+override load_dirs => sub {
+ my $self = shift;
+ $self->load_file( $self->replica_config_file )
+ if -f $self->replica_config_file;
+};
-sub app_config_file {
+# If PROPHET_APP_CONFIG is set, don't load anything else
+override user_file => sub {
my $self = shift;
- return $self->file_if_exists($ENV{'PROPHET_APP_CONFIG'})
- || $self->file_if_exists( $self->replica_config_file)
- || $self->file_if_exists( File::Spec->catfile( $ENV{'HOME'} => '.prophetrc' ))
- || $self->replica_config_file
-}
+ return exists $ENV{PROPHET_APP_CONFIG} ? '' : $self->SUPER::user_file(@_);
+};
-sub replica_config_file {
+override global_file => sub {
my $self = shift;
- return
- $self->file_if_exists( File::Spec->catfile( $self->app_handle->handle->fs_root => 'config' )) ||
- $self->file_if_exists( File::Spec->catfile( $self->app_handle->handle->fs_root => 'prophetrc' )) ||
- File::Spec->catfile( $self->app_handle->handle->fs_root => 'config' );
-}
+ return exists $ENV{PROPHET_APP_CONFIG} ? '' : $self->SUPER::global_file(@_);
+};
-sub load_from_files {
+# grab all values in the 'alias' section and strip away the section name
+sub aliases {
my $self = shift;
- my @config = @_;
- @config = grep { -f $_ } $self->app_config_file if !@config;
- my $config = {};
- for my $file (@config) {
- $self->load_from_file($file => $config);
- push @{$self->config_files}, $file;
- }
+ my %aliases = $self->get_regexp( key => '^alias\.' );
- return $config;
-}
+ my %new_aliases = map {
+ my $alias = $_;
+ $alias =~ s/^alias\.//;
+ ( $alias => $aliases{$_} );
+ } keys %aliases;
-sub load_from_file {
- my $self = shift;
- my $file = shift;
- my $config = shift || {};
-
- for my $line (Prophet::Util->slurp($file) ) {
- $line =~ s/\#.*$//; # strip comments
- 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.
+ return wantarray ? %new_aliases : \%new_aliases;
}
-sub display_name_for_uuid {
+# grab all values in the 'source' section and strip away the section name
+sub sources {
my $self = shift;
- my $uuid = shift;
- my $friendly = $self->get("display_$uuid");
- return defined($friendly) ? $friendly : $uuid;
-}
+ my %sources = $self->get_regexp( key => '^source\.' );
-=head2 file_if_exists FILENAME
+ my %new_sources = map {
+ my $source = $_;
+ $source =~ s/^source\.//;
+ ( $source => $sources{$_} );
+ } keys %sources;
-Returns the given filename if it exists on the filesystem, and an
-empty string otherwise.
-
-=cut
+ return wantarray ? %new_sources : \%new_sources;
+}
-sub file_if_exists {
+sub replica_config_file {
my $self = shift;
- my $file = shift || ''; # quiet warnings
- return (-e $file) ? $file : '';
+ return exists $ENV{PROPHET_APP_CONFIG} ? $ENV{PROPHET_APP_CONFIG}
+ : File::Spec->catfile(
+ $self->app_handle->handle->fs_root, $self->dir_file
+ );
}
-=head2 save FILENAME
-
-save the current config to file, if the file is not supplied,
-save to $self->app_config_file
-
-=cut
-
-#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 and source lines only for now.
-
-sub save {
+# friendly replica names go in the [display] section
+sub display_name_for_uuid {
my $self = shift;
- my $file = shift || $self->app_config_file;
-
- my @lines;
- if ( $self->file_if_exists($file) ) {
- @lines = Prophet::Util->slurp($file);
- }
-
- open my $fh, '>', $file or die "can't save config to $file: $!";
- for my $line (@lines) {
-
- # 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";
- }
- }
- close $fh;
- return 1;
-}
+ my $uuid = shift;
+ my $friendly = $self->get( key => "display.$uuid" );
+ return defined($friendly) ? $friendly : $uuid;
+}
__PACKAGE__->meta->make_immutable;
no Any::Moose;
commit 89937cf5d7b1e2ffedd8483a48cb149c7341f626
Author: Christine Spang <spang at mit.edu>
Date: Tue Jun 16 13:26:15 2009 +0300
By default, don't load any config files in tests.
diff --git a/lib/Prophet/Test.pm b/lib/Prophet/Test.pm
index ab62988..6e7dbca 100644
--- a/lib/Prophet/Test.pm
+++ b/lib/Prophet/Test.pm
@@ -23,6 +23,9 @@ our $REPO_BASE = File::Temp::tempdir();
Test::More->import;
diag( "Replicas can be found in $REPO_BASE" );
+# by default, load no configuration file
+$ENV{PROPHET_APP_CONFIG} = '';
+
{
no warnings 'redefine';
require Test::More;
commit 3480992a9efd08d4b64c5b94f823c27b13262f42
Author: Christine Spang <spang at mit.edu>
Date: Tue Jun 16 13:27:10 2009 +0300
Update summary format config key to new style.
diff --git a/lib/Prophet/Record.pm b/lib/Prophet/Record.pm
index 9ef1d6e..b0ed10d 100644
--- a/lib/Prophet/Record.pm
+++ b/lib/Prophet/Record.pm
@@ -641,8 +641,9 @@ L<_default_summary_format> if nothing better can be found.
sub _summary_format {
my $self = shift;
- return $self->app_handle->config->get('summary_format_'.$self->type)
- || $self->app_handle->config->get('default_summary_format')
+ return
+ $self->app_handle->config->get( key => $self->type.'.summary-format' )
+ || $self->app_handle->config->get( key => 'record.summary-format' )
|| $self->_default_summary_format;
}
commit 3e159946003d4802598dda6c53acfe06279abccb
Author: Christine Spang <spang at mit.edu>
Date: Tue Jun 16 13:28:40 2009 +0300
Update config command and its tests.
diff --git a/lib/Prophet/CLI/Command/Config.pm b/lib/Prophet/CLI/Command/Config.pm
index ea61ad6..2f69352 100644
--- a/lib/Prophet/CLI/Command/Config.pm
+++ b/lib/Prophet/CLI/Command/Config.pm
@@ -13,38 +13,20 @@ sub run {
print $self->no_config_files;
return;
}
+ print "Config files:\n\n";
for my $file (@files) {
- print "Config files:\n\n";
print "$file\n";
}
print "\nYour configuration:\n\n";
- for my $item ( $config->list ) {
- if ( $item eq '_aliases' ) {
- if ( my $aliases = $config->aliases ) {
- for my $key ( keys %$aliases ) {
- print "alias $key = $aliases->{$key}\n";
- }
- }
- }
- elsif ( $item eq '_sources' ) {
- if ( my $sources = $config->sources ) {
- for my $key ( keys %$sources ) {
- print "source $key = $sources->{$key}\n";
- }
- }
- }
- else {
- print $item . " = " . $config->get($item) . "\n";
- }
- }
+ $config->dump;
}
sub no_config_files {
my $self = shift;
return "No configuration files found. "
- . " Either create a file called 'config' inside of "
- . $self->handle->fs_root
- . " or set the PROPHET_APP_CONFIG environment variable.\n\n";
+ . " Either create a file called
+ '".$self->handle->app_handle->config->replica_config_file.
+ "' or set the PROPHET_APP_CONFIG environment variable.\n\n";
}
__PACKAGE__->meta->make_immutable;
diff --git a/t/config.t b/t/config.t
index 47c64bd..a7ff1f4 100644
--- a/t/config.t
+++ b/t/config.t
@@ -2,51 +2,79 @@
#
use warnings;
use strict;
-use Prophet::Test 'no_plan';
+use Prophet::Test tests => 11;
+use File::Copy;
use File::Temp qw'tempdir';
- $ENV{'PROPHET_REPO'} = tempdir( CLEANUP => ! $ENV{PROPHET_DEBUG} ) . '/repo-' . $$;
-delete $ENV{'PROPHET_APP_CONFIG'};
-use_ok('Prophet::CLI');
-# Test basic config file parsing
-use_ok('Prophet::Config');
-my $config = Prophet::Config->new(app_handle => Prophet::CLI->new->app_handle);
-
-isa_ok($config => 'Prophet::Config');
-can_ok($config => 'load_from_files');
+my $repo = $ENV{'PROPHET_REPO'} = $Prophet::Test::REPO_BASE . '/repo-' . $$;
-can_ok($config, 'get');
-can_ok($config, 'set');
-can_ok($config, 'list');
-can_ok($config, 'aliases');
+# since we don't initialize the db for these tests, make the repo dir
+mkdir $ENV{PROPHET_REPO};
-is($config->get('_does_not_exist'), undef);
-is($config->set('_does_not_exist' => 'hey you!'), 'hey you!');
-is($config->get('_does_not_exist'), 'hey you!');
-is_deeply([$config->list], ['_does_not_exist'], "The deep structures match");
+use_ok('Prophet::CLI');
# load up a prophet app instance
-
my $a = Prophet::CLI->new();
can_ok($a, 'app_handle');
can_ok($a->app_handle, 'config');
my $c = $a->config;
+$c->load;
+
+is( $c->config_files->[0], undef, 'no config files loaded' );
+
# interrogate its config to see if we have any config options set
-my @keys = $c->list;
-is (scalar @keys,0);
+my @keys = $c->dump;
+is( scalar @keys, 0, 'no config options are set' );
# set a config file
-{ local $ENV{'PROPHET_APP_CONFIG'} = 't/test_app.conf';
-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,4);
-# test the alias
-is($conf->aliases->{tlist}, "ticket list", "Got correct alias");
-}
+{
+ copy 't/test_app.conf', $repo;
+ local $ENV{'PROPHET_APP_CONFIG'}
+ = File::Spec->catfile($repo,'test_app.conf');
+
+ my $conf = Prophet::Config->new(
+ app_handle => Prophet::CLI->new->app_handle,
+ confname => 'testrc',
+ );
+ $conf->load;
+ # make sure we only have the one test config file loaded
+ is( length @{$conf->config_files}, 1, 'only test conf is loaded' );
+
+ # interrogate its config to see if we have any config options set
+ my @data = $conf->dump;
+ is( scalar @data, 6, '3 config options are set' );
+ # test the aliases sub
+ is( $conf->aliases->{tlist}, 'ticket list', 'Got correct alias' );
+ # test automatic reload after setting
+ $conf->set(
+ key => 'source.sd',
+ value => 'http://fsck.com/sd/',
+ filename => File::Spec->catfile($repo, 'test_app.conf'),
+ );
+ is( $conf->get( key => 'source.sd' ), 'http://fsck.com/sd/',
+ 'automatic reload after set' );
+ # test the sources sub
+ is( $conf->sources->{sd}, 'http://fsck.com/sd/', 'Got correct alias' );
+
+ # run the cli "config" command
+ # make sure it matches with our file
+ my $got = run_command('config');
+ my $expect = <<EOF
+Configuration:
+Config files:
-# run the cli "show config" command
-# make sure it matches with our file
+$repo/test_app.conf
+
+Your configuration:
+
+alias.tlist=ticket list
+source.sd=http://fsck.com/sd/
+test.foo=bar
+test.re=rawr
+EOF
+ ;
+ is($got, $expect, 'output of config command');
+}
commit 1020026b97d2aa3f2d142112c61ed1bf2f053d9a
Author: Christine Spang <spang at mit.edu>
Date: Tue Jun 16 13:28:59 2009 +0300
Update test config file to new format.
diff --git a/t/test_app.conf b/t/test_app.conf
index 18daa28..1dd02bd 100644
--- a/t/test_app.conf
+++ b/t/test_app.conf
@@ -1,6 +1,8 @@
-#This is not a config directive
-foo=bar
-# nor is this
-re = rawr
-# This is an alias
-alias tlist = ticket list
+[test]
+ #This is not a config directive
+ foo=bar
+ # nor is this
+ re = rawr
+[alias]
+ # This is an alias
+ tlist = ticket list
commit b2284f04cd90756342fce0226ad82a2ab304af6f
Author: Christine Spang <spang at mit.edu>
Date: Tue Jun 16 13:29:31 2009 +0300
Kill t/testing.conf which isn't used for anything.
diff --git a/t/testing.conf b/t/testing.conf
deleted file mode 100644
index de908b4..0000000
--- a/t/testing.conf
+++ /dev/null
@@ -1 +0,0 @@
-default_summary_format = %s,$uuid | %s,summary | %s,status
commit 8efc16d02ddba7765d7141b6d4d3d6b0cbe114fe
Author: Christine Spang <spang at mit.edu>
Date: Tue Jun 16 13:30:40 2009 +0300
Update alias command and its tests for new config API.
diff --git a/lib/Prophet/CLI/Command/Aliases.pm b/lib/Prophet/CLI/Command/Aliases.pm
index 0875bbb..36f6cf1 100644
--- a/lib/Prophet/CLI/Command/Aliases.pm
+++ b/lib/Prophet/CLI/Command/Aliases.pm
@@ -11,6 +11,8 @@ sub run {
my $self = shift;
my $template = $self->make_template;
+ my $config = $self->app_handle->config;
+
if ( $self->context->has_arg('show') ) {
print $template. "\n";
return;
@@ -22,17 +24,18 @@ sub run {
}
if ( $self->has_arg('set') || $self->has_arg('delete') ) {
- my $aliases = $self->app_handle->config->aliases;
- my $need_to_save;
if ( $self->has_arg('set') ) {
my $value = $self->arg('set');
if ( $value =~ /^\s*(.+?)\s*=\s*(.+?)\s*$/ ) {
- if ( exists $aliases->{$1} ) {
- if ( $aliases->{$1} ne $2 ) {
- my $old = $aliases->{$1};
- $aliases->{$1} = $2;
- $need_to_save = 1;
+ my $old = $config->get( key => "alias.$1" );
+ if ( defined $old ) {
+ if ( $old ne $2 ) {
+ $config->set(
+ key => "alias.$1",
+ value => $2,
+ filename => $config->replica_config_file,
+ );
print
"changed alias '$1' from '$old' to '$2'\n";
}
@@ -41,27 +44,32 @@ sub run {
}
}
else {
- $need_to_save = 1;
- $aliases->{$1} = $2;
+ $config->set(
+ key => "alias.$1",
+ value => $2,
+ filename => $config->replica_config_file,
+ );
print "added alias '$1 = $2'\n";
}
}
}
elsif ( $self->has_arg('delete') ) {
my $key = $self->arg('delete');
- if ( exists $aliases->{$key} ) {
- $need_to_save = 1;
- print "deleted alias '$key = $aliases->{$key}'\n";
- delete $aliases->{$key};
+
+ if ( defined $config->get( key => "alias.$key" ) ) {
+ print "deleted alias '$key = "
+ .$config->get( key => "alias.$key" )."'\n";
+
+ $config->set(
+ key => "alias.$key",
+ filename => $config->replica_config_file,
+ );
}
else {
print "didn't find alias '$key'\n";
}
}
- if ($need_to_save) {
- $self->app_handle->config->save;
- }
}
else {
@@ -71,8 +79,6 @@ sub run {
$done = $self->try_to_edit( template => \$template );
}
}
-
-
}
sub make_template {
@@ -117,27 +123,43 @@ sub process_template {
my ($config) = $self->parse_template($updated);
my $aliases = $self->app_handle->config->aliases;
+ my $c = $self->app_handle->config;
+
+ my @added = grep { !$aliases->{$_} } sort keys %$config;
- my @added = grep { ! $aliases->{$_} } sort keys %$config;
my @changed =
- grep { $config->{$_} && $aliases->{$_} ne $config->{$_} } sort keys %$aliases;
+ grep { $config->{$_} && $aliases->{$_} ne $config->{$_}
+ } sort keys %$aliases;
+
my @deleted = grep { !$config->{$_} } sort keys %$aliases;
+ # TODO: 'set' all at once after implementing hash sets
for my $add ( @added ) {
print 'Added alias ' . "'$add' = '$config->{$add}'\n";
+ $c->set(
+ key => "alias.$add",
+ value => $config->{$add},
+ filename => $c->replica_config_file,
+ );
}
for my $change (@changed) {
print 'Changed alias ' . "'$change' from '$aliases->{$change}' to '$config->{$change}'\n";
+ $c->set(
+ key => "alias.$change",
+ value => $config->{$change},
+ filename => $c->replica_config_file,
+ );
}
for my $delete ( @deleted ) {
print "Deleted alias '$delete'\n";
+ $c->set(
+ key => "alias.$delete",
+ filename => $c->replica_config_file,
+ );
}
- $self->app_handle->config->set(_aliases => $config );
- $self->app_handle->config->save;
-
return 1;
}
diff --git a/t/aliases.t b/t/aliases.t
index ae007e2..a7ac708 100644
--- a/t/aliases.t
+++ b/t/aliases.t
@@ -3,16 +3,22 @@
use warnings;
use strict;
use Prophet::Test 'no_plan';
-use File::Temp qw/tempfile/;
+use File::Temp qw/tempdir tempfile/;
-$ENV{'PROPHET_APP_CONFIG'} = (tempfile(UNLINK => 1))[1];
+$ENV{'PROPHET_REPO'} = $Prophet::Test::REPO_BASE . '/repo-' . $$;
+$ENV{'PROPHET_APP_CONFIG'} = (tempfile(UNLINK => !$ENV{PROPHET_DEBUG}))[1];
+diag("Using config file $ENV{PROPHET_APP_CONFIG}");
+
+# since we don't initialize the db for these tests, make the repo dir
+mkdir $ENV{PROPHET_REPO};
use_ok('Prophet::CLI');
use_ok('Prophet::Config');
-my $aliases = Prophet::Config->new(app_handle =>
- Prophet::CLI->new->app_handle)->aliases;
-is_deeply( $aliases, {}, 'initial alias is empty' );
+my $config = Prophet::CLI->new()->config;
+$config->load;
+
+is_deeply( scalar $config->aliases, {}, 'initial alias is empty' );
my @cmds = (
{
@@ -47,7 +53,7 @@ my @cmds = (
{
cmd => [ '--add', 'pull -a=pull --all' ],
output => qr/added alias 'pull -a = pull --all/,
- comment => 'readd a new alias',
+ comment => 'read a new alias',
},
{
cmd => [ '--add', 'pull -l=pull --local' ],
@@ -63,8 +69,11 @@ for my $item ( @cmds ) {
# check aliases in config
-$aliases = Prophet::Config->new(app_handle =>
- Prophet::CLI->new->app_handle)->aliases;
+my $aliases = Prophet::Config->new(
+ app_handle => Prophet::CLI->new->app_handle,
+ confname => 'testrc'
+)->aliases;
+
is_deeply(
$aliases,
{
@@ -80,7 +89,10 @@ open my $fh, '<', $ENV{'PROPHET_APP_CONFIG'}
or die "failed to open $ENV{'PROPHET_APP_CONFIG'}: $!";
{ local $/; $content = <$fh>; }
is( $content, <<EOF, 'content in config' );
-alias pull -l = pull --local
-alias pull -a = pull --all
+
+[alias]
+ pull -a = pull --all
+ pull -l = pull --local
EOF
+# TODO: need tests for interactive alias editing
commit 6b4d60db12a6b7f8b228ce88b2b6266d26999464
Author: Christine Spang <spang at mit.edu>
Date: Tue Jun 16 13:32:31 2009 +0300
Update pull command to use new config API.
diff --git a/lib/Prophet/CLI/Command/Pull.pm b/lib/Prophet/CLI/Command/Pull.pm
index c79bc3f..dec663e 100644
--- a/lib/Prophet/CLI/Command/Pull.pm
+++ b/lib/Prophet/CLI/Command/Pull.pm
@@ -12,21 +12,18 @@ sub run {
my $previous_sources = $self->app_handle->config->sources;
-
my $explicit_from = '';
-
+
if ($self->has_arg('from')) {
$explicit_from = $self->arg('from') ;
push @from, $explicit_from;
}
-
elsif ($self->has_arg('all')){
for my $source (values %$previous_sources) {
my ($url, $uuid ) = split(qr/ \| /,$source,2);
push @from, $url;
}
-
}
$self->validate_args;
@@ -49,17 +46,19 @@ sub record_pull_from_source {
my $self = shift;
my $source = shift;
my $from_uuid = shift;
- my $previous_sources = $self->app_handle->config->sources;
+ my %previous_sources = $self->app_handle->config->sources;
my %sources_by_url = map {
- my $meta = $_;
- my ($url,$uuid);
- ($url, $uuid ) = split(qr/ \| /,$meta,2);
- ($previous_sources->{$meta} => $url )
- } keys %$previous_sources;
+ my $name = $_;
+ my ($url, $uuid);
+ ($url, $uuid ) = split(qr/ \| /, $previous_sources{$name}, 2);
+ ($url => $uuid )
+ } keys %previous_sources;
if ( !exists $sources_by_url{$source}) {
- $previous_sources->{$source} = $source ." | ".$from_uuid;
- $self->app_handle->config->set(_sources => $previous_sources );
- $self->app_handle->config->save;
+ $self->app_handle->config->set(
+ key => "source.'$source'",
+ value => "$source | $from_uuid",
+ filename => $self->app_handle->config->replica_config_file,
+ );
}
}
commit b50d1d02112e12cf0b1c4881b6c1fba4ded1b7e7
Author: Christine Spang <spang at mit.edu>
Date: Tue Jun 16 13:33:00 2009 +0300
Update clone command to use new config API.
diff --git a/lib/Prophet/CLI/Command/Clone.pm b/lib/Prophet/CLI/Command/Clone.pm
index f729b64..fa87866 100644
--- a/lib/Prophet/CLI/Command/Clone.pm
+++ b/lib/Prophet/CLI/Command/Clone.pm
@@ -42,8 +42,12 @@ sub run {
}
$target->initialize(%init_args);
- $self->app_handle->config->set( _sources => { $self->arg('from') => $self->arg('from') });
- $self->app_handle->config->save;
+
+ $self->app_handle->config->set(
+ key => 'source.'.$self->arg('from'),
+ value => $self->arg('from'),
+ filename => $self->app_handle->config->replica_config_file,
+ );
if ( $source->can('database_settings') ) {
my $remote_db_settings = $source->database_settings;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list