[Bps-public-commit] r9832 - in bpsbuilder/BPB: lib lib/BPB lib/BPB/Backend lib/BPB/Script lib/BPB/Source

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Dec 6 08:43:29 EST 2007


Author: sunnavy
Date: Thu Dec  6 08:43:28 2007
New Revision: 9832

Modified:
   bpsbuilder/BPB/examples/config.yml
   bpsbuilder/BPB/lib/BPB.pm
   bpsbuilder/BPB/lib/BPB/Backend.pm
   bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
   bpsbuilder/BPB/lib/BPB/Config.pm
   bpsbuilder/BPB/lib/BPB/Script/Export.pm
   bpsbuilder/BPB/lib/BPB/Script/Import.pm
   bpsbuilder/BPB/lib/BPB/Script/Initialize.pm
   bpsbuilder/BPB/lib/BPB/Script/Source.pm
   bpsbuilder/BPB/lib/BPB/Source/Base.pm
   bpsbuilder/BPB/lib/BPB/Source/Compressed.pm
   bpsbuilder/BPB/lib/BPB/Source/Directory.pm
   bpsbuilder/BPB/lib/BPB/Source/FTP.pm
   bpsbuilder/BPB/lib/BPB/Source/HTTP.pm

Log:
refactor bpb, remove useless and complex stuff. keep it simple, stupid ;)

Modified: bpsbuilder/BPB/examples/config.yml
==============================================================================
--- bpsbuilder/BPB/examples/config.yml	(original)
+++ bpsbuilder/BPB/examples/config.yml	Thu Dec  6 08:43:28 2007
@@ -1,11 +1,8 @@
 test:
-    project: test
     backend:
         module: SVK
-        command: '/usr/bin/svk'
+        repository: '//local/test'
     source:
-        command:
-            tar: '/usr/bin/tar'
         directory: '/tmp'
         download_directory: '/tmp/download'
         min_perl_version: 5.008008

Modified: bpsbuilder/BPB/lib/BPB.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB.pm	(original)
+++ bpsbuilder/BPB/lib/BPB.pm	Thu Dec  6 08:43:28 2007
@@ -12,7 +12,6 @@
 
 use BPB::Config;
 use BPB::Backend;
-use BPB::Source;
 
 =head2 new
 
@@ -22,7 +21,7 @@
     my $class = shift;
 
     my %args = @_;
-    croak "need moniker option" unless $args{moniker};
+    croak "need name option" unless $args{name};
 
     unless ( $args{config} ) {
         require File::Spec;
@@ -35,10 +34,11 @@
     bless $self, $class;
 
     $self->config(
-        BPB::Config->new( config => delete $args{config}, moniker => delete $args{moniker} )
+        BPB::Config->new( config => delete $args{config}, name => $args{name} )
     );
     $self->backend(
-        BPB::Backend->new( %{ $self->config->moniker->{backend} }, ) );
+        BPB::Backend->new( %{ $self->config->name->{backend} }, name
+        => $args{name} ) );
 
     return $self;
 }

Modified: bpsbuilder/BPB/lib/BPB/Backend.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Backend.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Backend.pm	Thu Dec  6 08:43:28 2007
@@ -20,7 +20,7 @@
     my $module = delete $args{module};
 
     croak "need a backend module, please check your config" unless $module;
-    croak "need project option" unless $args{project};
+    croak "need name option" unless $args{name};
 
     $module = 'BPB::Backend::' . $module unless $module =~ /^BPB::Backend/;
 

Modified: bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Backend/SVK.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Backend/SVK.pm	Thu Dec  6 08:43:28 2007
@@ -8,27 +8,14 @@
 use BPB::Config;
 use File::Temp qw/tempdir/;
 
-# command option is svk's path info, e.g. '/usr/bin/svk'
-# path is under repository/project/, e.g.
 # our project's own files will be in //local/test/main
 # all the dependance packages will be in //local/test/deps
 # the bpb's stuff will be in //local/test/bpb
 
-our %DEFAULT = (
-    command    => 'svk',
-    repository => '//local',
-    project    => 'test',
-    path       => {
-        dependance => 'deps',
-        bpb        => 'bpb',
-        main       => 'main',
-    }
-);
-
 our %REQUIRE_OPTIONS = ( import => [qw/source/], );
 
 use base qw/Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/command repository project path/);
+__PACKAGE__->mk_accessors(qw/repository/);
 
 =head2 new
 
@@ -38,7 +25,7 @@
     my $class = shift;
     my %args  = @_;
 
-    bless { %DEFAULT, %args }, $class;
+    bless {%args}, $class;
 }
 
 sub initialize {
@@ -64,16 +51,7 @@
     my %args = @_;
     my $cmd  = $self->_cmd( import => %args );
     $self->_run($cmd);
-
-    if ( $args{category} ) {
-        if ( $args{category} eq 'dependance' ) {
-            $self->_update_order( source => $args{source} );
-        }
-        elsif ( $args{category} eq 'main' ) {
-            $self->_update_version( version => $args{version} )
-              if $args{version};
-        }
-    }
+    $self->_update_order( source => $args{source} ) if $args{_deps};
 }
 
 =head2 export
@@ -106,9 +84,8 @@
     my $self = shift;
     my $type = shift;
     my %args = @_;
-    $args{extra}    ||= [];
-    $args{category} ||= '';
-    $args{path}     ||= '';
+    $args{extra} ||= [];
+    $args{path} ||= '';
 
     for ( @{ $REQUIRE_OPTIONS{$type} } ) {
         croak "$type need option $_" unless $args{$_};
@@ -117,49 +94,36 @@
     my $cmd;
 
     if ( $type eq 'checkout' ) {
-
-        # if category is null, will checkout the whole project
-        # if path is null, will check the whole category part
         if ( $args{detach} ) {
-            $cmd = join ' ', $self->command, 'checkout', '--detach',
-              $args{path};
+            $cmd = join ' ', 'svk', 'checkout', '--detach', $args{target};
         }
         else {
-            my $path = $self->_absolute_path( $args{category}, $args{path} );
-            $cmd = join ' ', $self->command, 'checkout', $path, $args{target};
-
-            if ( $args{version} ) {
-                my $revision =
-                  $self->_version_to_revision( version => $args{version} );
-                croak 'no such version' unless $revision;
-                $cmd .= ' --revision ' . $revision;
-            }
-
+            $cmd = join ' ', 'svk', 'checkout',
+              $self->repository . $args{path}, $args{target};
         }
     }
     elsif ( $type eq 'import' ) {
         push @{ $args{extra} }, '-m',
           q{'} . ( $args{comment} || 'import' ) . q{'};
 
-        my $path = $self->_absolute_path( $args{category} );
         if ( $args{_initialize} ) {
-            $cmd = join ' ', $self->command, 'import', $args{source}, $path;
+            $cmd = join ' ', 'svk', 'import', $args{source}, $self->repository;
         }
-        else {
+        elsif ( $args{_deps} ) {
             my $name = $args{source};
             $name =~ s!^.*/(.+)/?$!$1.tar.gz!;
             $name = CPAN::DistnameInfo->new($name)->dist;
-            $cmd = join ' ', $self->command, 'import', $args{source},
-              "$path/$name";
+            $cmd = join ' ', 'svk', 'import', $args{source},
+              $self->repository . "/deps/$name";
+        }
+        else {
+            $cmd = join ' ', 'svk', 'import', $args{source},
+              $self->repository . '/main';
         }
-    }
-    elsif ( $type eq 'cat' ) {
-        my $path = $self->_absolute_path( $args{category}, $args{path} );
-        $cmd = join ' ', $self->command, 'cat', $path;
     }
     elsif ( $type eq 'commit' ) {
-        $cmd = join ' ', $self->command, 'commit', '-m',
-          q{'} . $args{comment} . q{'}, $args{path};
+        $cmd = join ' ', 'svk', 'commit', '-m', q{'} . $args{comment} . q{'},
+          $args{path};
     }
     else {
         croak "invalid command";
@@ -176,9 +140,8 @@
     my $file = File::Spec->catfile( $dir, 'order.yml' );
 
     $self->checkout(
-        category => 'bpb',
-        path     => 'order.yml',
-        target   => $file,
+        path   => '/bpb/order.yml',
+        target => $file,
     );
 
     my $order = BPB::Config::LoadFile($file) || [];
@@ -192,84 +155,7 @@
         $self->commit( path => $file, comment => "added $name to order" );
     }
 
-    $self->checkout( detach => 1, path => $file );
-}
-
-sub _update_version {
-    my $self    = shift;
-    my %args    = @_;
-    my $version = $args{version};
-
-    my $dir = tempdir( CLEANUP => 0 );
-    my $file = File::Spec->catfile( $dir, 'version.yml' );
-
-    $self->checkout(
-        category => 'bpb',
-        path     => 'version.yml',
-        target   => $file,
-    );
-
-    my $yml = BPB::Config::LoadFile($file) || {};
-
-    $yml->{$version} =
-      $self->_current_revision + 1;    # the 1 is for the update version.yml
-    BPB::Config::DumpFile( $file, $yml );
-    $self->commit(
-        path    => $file,
-        comment => "added version" . $yml->{$version}
-    );
-    $self->checkout( detach => 1, path => $file );
-}
-
-sub _current_revision {
-    my $self = shift;
-    my $cmd  = join ' ', $self->command, 'info', $self->_absolute_path;
-    my @info = `$cmd`;
-    for (@info) {
-        if (/Revision: (\d+)/) {
-            return $1;
-        }
-    }
-    return;
-}
-
-sub _version_to_revision {
-    my $self    = shift;
-    my %args    = @_;
-    my $version = $args{version};
-
-    my $dir = tempdir( CLEANUP => 1 );
-    my $file = File::Spec->catfile( $dir, 'version.yml' );
-
-    $self->export(
-        category => 'bpb',
-        path     => 'version.yml',
-        target   => $file,
-    );
-
-    my $yml = BPB::Config::LoadFile($file) || {};
-
-    return $yml->{$version};
-
-}
-
-sub cat {
-    my $self = shift;
-    my %args = @_;
-    $args{category} ||= 'main';
-
-    my $cmd = $self->_cmd( category => $args{category}, path => $args{path} );
-    my $content = `$cmd`;
-    return $content;
-}
-
-sub _absolute_path {
-    my $self     = shift;
-    my $category = shift;
-    $category = $self->path->{ $category } if $category;
-
-    my @paths    = grep { $_ } $category, @_;    # trim null paths
-    return join '/', $self->repository, $self->project, @paths;
+    $self->checkout( detach => 1, target => $file );
 }
 
 sub _run {

Modified: bpsbuilder/BPB/lib/BPB/Config.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Config.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Config.pm	Thu Dec  6 08:43:28 2007
@@ -5,7 +5,7 @@
 use Carp;
 
 use base qw/Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/stash moniker/);
+__PACKAGE__->mk_accessors(qw/stash name/);
 
 BEGIN {
     local $@;
@@ -36,8 +36,8 @@
 
     $self->load( $args{config} );
 
-    if ( $args{moniker} ) {
-        $self->moniker( $self->stash->{ $args{moniker} } );
+    if ( $args{name} ) {
+        $self->name( $self->stash->{ $args{name} } );
     }
 
     return $self;
@@ -50,21 +50,6 @@
 sub load {
     my $self = shift;
     $self->stash( LoadFile(shift) );
-    $self->_tidy;
-}
-
-sub _tidy {
-    my $self = shift;
-
-    # 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/Export.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Export.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Script/Export.pm	Thu Dec  6 08:43:28 2007
@@ -5,26 +5,24 @@
 use Carp;
 
 use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config moniker category path target version/);
+__PACKAGE__->mk_accessors(qw/config name target/);
 
 use BPB;
 
 sub options {
     (
-        'k|moniker=s'  => 'moniker',
-        'c|config=s'   => 'config',
-        'g|category=s' => 'category',
-        'p|path=s'     => 'path',
-        't|target=s'   => 'target',
-        'v|version=s'  => 'version',
+        'n|name=s'   => 'name',
+        'c|config=s' => 'config',
+        't|target=s' => 'target',
     );
 }
 
 sub run {
-    my $self = shift;
-    my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
-    $bpb->backend->export( map { $_, $self->$_ }
-          qw/category path target version/ );
+    my $self   = shift;
+    my $target = shift;
+    $self->target($target) if $target;
+    my $bpb = BPB->new( config => $self->config, name => $self->name );
+    $bpb->backend->export( map { $_, $self->$_ } qw/target/ );
 }
 
 1;

Modified: bpsbuilder/BPB/lib/BPB/Script/Import.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Import.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Script/Import.pm	Thu Dec  6 08:43:28 2007
@@ -5,7 +5,7 @@
 use Carp;
 
 use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config moniker category comment source version/);
+__PACKAGE__->mk_accessors(qw/config name comment source/);
 
 use BPB;
 use File::Spec;
@@ -14,11 +14,9 @@
 sub options {
     (
         'c|config=s'   => 'config',
-        'k|moniker=s'  => 'moniker',
-        'g|category=s' => 'category',
+        'n|name=s'  => 'name',
         'm|comment=s'  => 'comment',
         's|source=s'   => 'source',
-        'v|version=s'   => 'version',
     );
 }
 
@@ -26,9 +24,9 @@
     my $self = shift;
     my $source = shift;
     $self->source( $source ) if $source;
-    my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
+    my $bpb = BPB->new( config => $self->config, name => $self->name );
     $self->import_req( $self->source, $bpb );
-    $bpb->backend->import( map { $_, $self->$_ } qw/category comment source version/ );
+    $bpb->backend->import( map { $_, $self->$_ } qw/comment source/ );
 }
 
 my %imported;
@@ -41,7 +39,7 @@
 
     if ( -e $require_file ) {
         my $req = BPB::Config::LoadFile($require_file);
-        opendir my $dir, $bpb->config->moniker->{source}{directory};
+        opendir my $dir, $bpb->config->name->{source}{directory};
         my @sources = readdir $dir;
         close $dir;
 
@@ -55,10 +53,10 @@
                   unless $dir;
                 $self->import_req( $source, $bpb );
                 $bpb->backend->import(
-                    category => 'dependance',
+                    _deps => 1,
                     comment  => 'deps for ' . $source,
                     source   => File::Spec->catfile(
-                        $bpb->config->moniker->{source}{directory}, $dir
+                        $bpb->config->name->{source}{directory}, $dir
                     )
                 );
             }

Modified: bpsbuilder/BPB/lib/BPB/Script/Initialize.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Initialize.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Script/Initialize.pm	Thu Dec  6 08:43:28 2007
@@ -5,7 +5,7 @@
 use Carp;
 
 use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config moniker/);
+__PACKAGE__->mk_accessors(qw/config name/);
 
 use BPB;
 use File::Spec;
@@ -14,13 +14,13 @@
 sub options {
     (
         'c|config=s'   => 'config',
-        'k|moniker=s'  => 'moniker',
+        'n|name=s'  => 'name',
     );
 }
 
 sub run {
     my $self = shift;
-    my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
+    my $bpb = BPB->new( config => $self->config, name => $self->name );
     $bpb->backend->initialize();
 }
 

Modified: bpsbuilder/BPB/lib/BPB/Script/Source.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Source.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Script/Source.pm	Thu Dec  6 08:43:28 2007
@@ -5,17 +5,16 @@
 use Carp;
 
 use base qw/App::CLI::Command Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw/config type source directory moniker/);
+__PACKAGE__->mk_accessors(qw/config source name/);
 
 use BPB;
+use BPB::Source;
 
 sub options {
     (
         'c|config=s'    => 'config',
-        'k|moniker=s'   => 'moniker',
-        't|type=s'      => 'type',
+        'n|name=s'   => 'name',
         's|source=s'    => 'source',
-        'd|directory=s' => 'directory',
     );
 }
 
@@ -29,7 +28,7 @@
     $args{source} ||= shift;
     my $bpb = BPB->new(%args);
     $bpb->source(
-        BPB::Source->new( %{ $bpb->config->moniker->{source} }, %args ) );
+        BPB::Source->new( %{ $bpb->config->name->{source} }, %args ) );
     $bpb->source->run;
 }
 

Modified: bpsbuilder/BPB/lib/BPB/Source/Base.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/Base.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source/Base.pm	Thu Dec  6 08:43:28 2007
@@ -10,7 +10,7 @@
 
 use base qw/Class::Accessor::Fast/;
 __PACKAGE__->mk_accessors(
-    qw/source directory command download_directory follow min_perl_version/);
+    qw/source directory download_directory follow min_perl_version/);
 
 our %MODULE = (
     '^(LWP

Modified: bpsbuilder/BPB/lib/BPB/Source/Compressed.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/Compressed.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source/Compressed.pm	Thu Dec  6 08:43:28 2007
@@ -26,9 +26,8 @@
 
 sub path {
     my $self     = shift;
-    my $tar      = $self->command->{compressed};
     my $source = $self->source;
-    my @contents = `$tar -t -f $source`;
+    my @contents = `tar -t -f $source`;
     my %path;
 
     for (@contents) {
@@ -45,7 +44,7 @@
     my $self = shift;
     my %file = @_;
     for ( keys %file ) {
-        my $cmd = join ' ', $self->command->{directory}, $file{$_},
+        my $cmd = join ' ', 'cp', $file{$_},
            File::Spec->catfile($self->path,  $_);
         system($cmd);
     }
@@ -64,7 +63,7 @@
     else {
         croak "I've no idea what the cmd is";
     }
-    return join ' ', $self->command->{compressed}, 'xfz', $self->source, '-C',
+    return join ' ', 'tar', 'xfz', $self->source, '-C',
       $self->directory;
 }
 

Modified: bpsbuilder/BPB/lib/BPB/Source/Directory.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/Directory.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source/Directory.pm	Thu Dec  6 08:43:28 2007
@@ -35,7 +35,7 @@
 
 sub _cmd {
     my $self = shift;
-    return join ' ', $self->command->{directory}, '-r', $self->source,
+    return join ' ', 'cp', '-r', $self->source,
       $self->directory;
 }
 

Modified: bpsbuilder/BPB/lib/BPB/Source/FTP.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/FTP.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source/FTP.pm	Thu Dec  6 08:43:28 2007
@@ -33,7 +33,7 @@
         my $src_dir = $self->download_directory;
         mkdir $src_dir unless -e $src_dir;
         $self->source( File::Spec->catfile( $src_dir, $file ) );
-        return join ' ', $self->command->{ftp}, $source, '-O', $self->source;
+        return join ' ', 'wget', $source, '-O', $self->source;
     }
     else {
         croak "invalid source: $source";

Modified: bpsbuilder/BPB/lib/BPB/Source/HTTP.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/HTTP.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source/HTTP.pm	Thu Dec  6 08:43:28 2007
@@ -33,7 +33,7 @@
         my $src_dir = $self->download_directory;
         mkdir $src_dir unless -e $src_dir;
         $self->source( File::Spec->catfile( $src_dir, $file ) );
-        return join ' ', $self->command->{http}, $source, '-O', $self->source;
+        return join ' ', 'wget', $source, '-O', $self->source;
     }
     else {
         croak "invalid source: $source";



More information about the Bps-public-commit mailing list