[Bps-public-commit] r9729 - in bpsbuilder/BPB: examples lib lib/BPB lib/BPB/Backend
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Fri Nov 23 10:25:22 EST 2007
Author: sunnavy
Date: Fri Nov 23 10:25:12 2007
New Revision: 9729
Modified:
bpsbuilder/BPB/examples/config.yml
bpsbuilder/BPB/lib/BPB.pm
bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
bpsbuilder/BPB/lib/BPB/Config.pm
bpsbuilder/BPB/lib/BPB/Script/Checkout.pm
bpsbuilder/BPB/lib/BPB/Script/Export.pm
bpsbuilder/BPB/lib/BPB/Script/Import.pm
Log:
refactor BPB's Config part, now we can have multiple projects in a config.yml, and ~/.bpb/config.yml will be default if not set in cli
Modified: bpsbuilder/BPB/examples/config.yml
==============================================================================
--- bpsbuilder/BPB/examples/config.yml (original)
+++ bpsbuilder/BPB/examples/config.yml Fri Nov 23 10:25:12 2007
@@ -1,4 +1,5 @@
-project: test
-backend:
- module: SVK
- command: '/usr/bin/svk'
+test:
+ project: test
+ backend:
+ module: SVK
+ command: '/usr/bin/svk'
Modified: bpsbuilder/BPB/lib/BPB.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB.pm (original)
+++ bpsbuilder/BPB/lib/BPB.pm Fri Nov 23 10:25:12 2007
@@ -21,17 +21,23 @@
my $class = shift;
my %args = @_;
- croak "need config option" unless $args{config};
+ croak "need moniker option" unless $args{moniker};
+
+ unless ( $args{config} ) {
+ require File::Spec;
+ require File::HomeDir;
+ $args{config} =
+ File::Spec->catfile( File::HomeDir->my_home, '.bpb', 'config.yml' );
+ }
my $self = {};
bless $self, $class;
- $self->config( BPB::Config->new( $args{config} ) );
- $self->backend(
- BPB::Backend->new(
- %{ $self->config->stash->{backend} },
- )
+ $self->config(
+ BPB::Config->new( config => $args{config}, moniker => $args{moniker} )
);
+ $self->backend(
+ BPB::Backend->new( %{ $self->config->moniker->{backend} }, ) );
return $self;
}
Modified: bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Backend/SVK.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Backend/SVK.pm Fri Nov 23 10:25:12 2007
@@ -17,7 +17,7 @@
path => {
dependance => 'deps',
bpb => 'bpb',
- main => 'main',
+ main => 'main',
}
);
@@ -75,6 +75,8 @@
my $type = shift;
my %args = @_;
$args{extra} ||= [];
+ $args{category} ||= '';
+ $args{path} ||= '';
for ( @{ $REQUIRE_OPTIONS{$type} } ) {
croak "$type need option $_" unless $args{$_};
@@ -86,7 +88,8 @@
# if category is null, will checkout the whole project
# if path is null, will check the whole category part
- my $path = $self->_absolute_path( $args{category}, $args{path} );
+ my $path =
+ $self->_absolute_path( $args{category}, $args{path} );
$cmd = join ' ', $self->command, 'checkout', $path, $args{target};
}
elsif ( $type eq 'import' ) {
Modified: bpsbuilder/BPB/lib/BPB/Config.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Config.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Config.pm Fri Nov 23 10:25:12 2007
@@ -5,7 +5,7 @@
use Carp;
use base qw/Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/stash/);
+__PACKAGE__->mk_accessors(qw/stash moniker/);
BEGIN {
local $@;
@@ -25,16 +25,17 @@
sub new {
my $class = shift;
- my $file = shift;
+ my %args = @_;
+
+ croak 'need config option' unless $args{config};
my $self = {};
bless $self, $class;
- if ( $file ) {
- $self->load( $file );
- }
- else {
- $self->stash( {} );
+ $self->load( $args{config} );
+
+ if ( $args{moniker} ) {
+ $self->moniker( $self->stash->{ $args{moniker} } );
}
return $self;
@@ -53,8 +54,14 @@
sub _tidy {
my $self = shift;
- # we want the backend part also has project
- $self->stash->{backend}{project} ||= $self->stash->{project};
+ # we want the backend part also has project name
+ for my $moniker ( keys %{ $self->stash } ) {
+
+ # if it doesn't have a project, let the moniker be the project
+ $self->stash->{$moniker}{project} ||= $moniker;
+ $self->stash->{$moniker}{backend}{project} ||=
+ $self->stash->{$moniker}{project};
+ }
}
1;
Modified: bpsbuilder/BPB/lib/BPB/Script/Checkout.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Checkout.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Script/Checkout.pm Fri Nov 23 10:25:12 2007
@@ -5,12 +5,13 @@
use Carp;
use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config category path target/);
+__PACKAGE__->mk_accessors(qw/config moniker category path target/);
use BPB;
sub options {
- ( 'c|config=s' => 'config',
+ ( 'k|moniker=s' => 'moniker',
+ 'c|config=s' => 'config',
'g|category=s' => 'category',
'p|path=s' => 'path',
't|target=s' => 'target',
@@ -20,7 +21,7 @@
sub run {
my $self = shift;
- my $bpb = BPB->new( config => $self->config );
+ my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
$bpb->backend->checkout( map { $_, $self->$_ } qw/category path target/ );
}
Modified: bpsbuilder/BPB/lib/BPB/Script/Export.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Export.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Script/Export.pm Fri Nov 23 10:25:12 2007
@@ -5,12 +5,13 @@
use Carp;
use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config category path target/);
+__PACKAGE__->mk_accessors(qw/config moniker category path target/);
use BPB;
sub options {
- ( 'c|config=s' => 'config',
+ ( 'k|moniker=s' => 'moniker',
+ 'c|config=s' => 'config',
'g|category=s' => 'category',
'p|path=s' => 'path',
't|target=s' => 'target',
@@ -20,7 +21,7 @@
sub run {
my $self = shift;
- my $bpb = BPB->new( config => $self->config );
+ my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
$bpb->backend->export( map { $_, $self->$_ } qw/category path target/ );
}
Modified: bpsbuilder/BPB/lib/BPB/Script/Import.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Import.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Script/Import.pm Fri Nov 23 10:25:12 2007
@@ -5,12 +5,13 @@
use Carp;
use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config category comment source/);
+__PACKAGE__->mk_accessors(qw/config moniker category comment source/);
use BPB;
sub options {
( 'c|config=s' => 'config',
+ 'k|moniker=s' => 'moniker',
'g|category=s' => 'category',
'm|comment=s' => 'comment',
's|source=s' => 'source',
@@ -20,7 +21,7 @@
sub run {
my $self = shift;
- my $bpb = BPB->new( config => $self->config );
+ my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
$bpb->backend->import( map { $_, $self->$_ } qw/category comment source/ );
}
More information about the Bps-public-commit
mailing list