[Bps-public-commit] r12517 - in Shipwright/trunk: lib/Shipwright/Backend

sunnavy at bestpractical.com sunnavy at bestpractical.com
Sun May 18 11:17:51 EDT 2008


Author: sunnavy
Date: Sun May 18 11:17:51 2008
New Revision: 12517

Modified:
   Shipwright/trunk/   (props changed)
   Shipwright/trunk/lib/Shipwright/Backend/SVK.pm
   Shipwright/trunk/lib/Shipwright/Backend/SVN.pm

Log:
 r12552 at sunnavys-mb:  sunnavy | 2008-05-18 22:52:28 +0800
 added updated method to update shipwright's own files


Modified: Shipwright/trunk/lib/Shipwright/Backend/SVK.pm
==============================================================================
--- Shipwright/trunk/lib/Shipwright/Backend/SVK.pm	(original)
+++ Shipwright/trunk/lib/Shipwright/Backend/SVK.pm	Sun May 18 11:17:51 2008
@@ -71,13 +71,15 @@
 
     unless ( $args{_initialize} || $args{_extra_tests} ) {
         if ( $args{build_script} ) {
-            if ( $self->info( path => "scripts/$name") && not $args{overwrite} ) {
+            if ( $self->info( path => "scripts/$name" )
+                && not $args{overwrite} )
+            {
                 $self->log->warn(
 "path scripts/$name alreay exists, need to set overwrite arg to overwrite"
                 );
             }
             else {
-                $self->delete( path => "scripts/$name");
+                $self->delete( path => "scripts/$name" );
                 $self->log->info(
                     "import $args{source}'s scripts to " . $self->repository );
                 Shipwright::Util->run(
@@ -85,13 +87,14 @@
             }
         }
         else {
-            if ( $self->info( path => "dists/$name") && not $args{overwrite} ) {
+            if ( $self->info( path => "dists/$name" ) && not $args{overwrite} )
+            {
                 $self->log->warn(
 "path dists/$name alreay exists, need to set overwrite arg to overwrite"
                 );
             }
             else {
-                $self->delete( path => "dists/$name");
+                $self->delete( path => "dists/$name" );
                 $self->log->info(
                     "import $args{source} to " . $self->repository );
                 $self->_add_to_order($name);
@@ -425,7 +428,7 @@
     my $self = shift;
     my %args = @_;
     my $path = $args{path} || '';
-    if ( $self->info( path => $path) ) {
+    if ( $self->info( path => $path ) ) {
         $self->log->info( "delete " . $self->repository . "/$path" );
         Shipwright::Util->run( $self->_cmd( delete => path => $path ), 1 );
     }
@@ -446,7 +449,7 @@
       Shipwright::Util->run( $self->_cmd( info => path => $path ), 1 );
     $self->log->warn($err) if $err;
 
-    if ( wantarray ) {
+    if (wantarray) {
         return $info, $err;
     }
     else {
@@ -515,10 +518,10 @@
 =cut
 
 sub flags {
-    my $self = shift;
+    my $self  = shift;
     my $flags = shift;
 
-    if ( $flags ) {
+    if ($flags) {
         my $dir = tempdir( CLEANUP => 1 );
         my $file = File::Spec->catfile( $dir, 'flags.yml' );
 
@@ -545,10 +548,10 @@
 =cut
 
 sub version {
-    my $self = shift;
+    my $self    = shift;
     my $version = shift;
 
-    if ( $version ) {
+    if ($version) {
         my $dir = tempdir( CLEANUP => 1 );
         my $file = File::Spec->catfile( $dir, 'version.yml' );
 
@@ -608,6 +611,41 @@
     return 0;
 }
 
+=head2 update
+
+update shipwright's own files, e.g. bin/shipwright-builder
+
+=cut
+
+sub update {
+    my $self = shift;
+    my %args = @_;
+
+    croak "need path option" unless $args{path};
+
+    croak "$args{path} seems not shipwright's own file"
+      unless -e File::Spec->catfile( Shipwright::Util->share_root,
+              $args{path} );
+
+    $args{path} = '/' . $args{path} unless $args{path} =~ m{^/};
+
+    my $dir = tempdir( CLEANUP => 1 );
+    my $file = File::Spec->catfile( $dir, $args{path} );
+
+    $self->checkout(
+        path   => $args{path},
+        target => $file,
+    );
+
+    copy( File::Spec->catfile( Shipwright::Util->share_root, $args{path} ),
+        $file );
+    $self->commit(
+        path    => $file,
+        comment => "update $args{path}",
+    );
+    $self->checkout( detach => 1, target => $file );
+}
+
 1;
 
 __END__

Modified: Shipwright/trunk/lib/Shipwright/Backend/SVN.pm
==============================================================================
--- Shipwright/trunk/lib/Shipwright/Backend/SVN.pm	(original)
+++ Shipwright/trunk/lib/Shipwright/Backend/SVN.pm	Sun May 18 11:17:51 2008
@@ -71,7 +71,7 @@
 
     unless ( $args{_initialize} ) {
         if ( $args{_extra_tests} ) {
-            $self->delete( path => "t/extra");
+            $self->delete( path => "t/extra" );
             $self->log->info( "import extra tests to " . $self->repository );
             Shipwright::Util->run(
                 $self->_cmd( import => %args, name => $name ) );
@@ -85,7 +85,7 @@
                 );
             }
             else {
-                $self->delete( path => "scripts/$name");
+                $self->delete( path => "scripts/$name" );
                 $self->log->info(
                     "import $args{source}'s scripts to " . $self->repository );
                 Shipwright::Util->run(
@@ -100,13 +100,13 @@
                 );
             }
             else {
-                $self->delete( path => "dists/$name");
+                $self->delete( path => "dists/$name" );
                 $self->log->info(
                     "import $args{source} to " . $self->repository );
                 $self->_add_to_order($name);
                 my $version = $self->version;
                 $version->{$name} = $args{version};
-                $self->version( $version );
+                $self->version($version);
 
                 Shipwright::Util->run(
                     $self->_cmd( import => %args, name => $name ) );
@@ -528,10 +528,10 @@
 =cut
 
 sub flags {
-    my $self = shift;
+    my $self  = shift;
     my $flags = shift;
 
-    if ( $flags ) {
+    if ($flags) {
         my $dir = tempdir( CLEANUP => 1 );
         my $file = File::Spec->catfile( $dir, 'flags.yml' );
 
@@ -557,10 +557,10 @@
 =cut
 
 sub version {
-    my $self = shift;
+    my $self    = shift;
     my $version = shift;
 
-    if ( $version ) {
+    if ($version) {
         my $dir = tempdir( CLEANUP => 1 );
         my $file = File::Spec->catfile( $dir, 'version.yml' );
 
@@ -583,7 +583,6 @@
     }
 }
 
-
 =head2 check_repository
 
 =cut
@@ -610,6 +609,43 @@
     return 0;
 }
 
+=head2 update
+
+update shipwright's own files, e.g. bin/shipwright-builder
+
+=cut
+
+sub update {
+    my $self = shift;
+    my %args = @_;
+
+    croak "need path option" unless $args{path};
+
+    croak "$args{path} seems not shipwright's own file"
+      unless -e File::Spec->catfile( Shipwright::Util->share_root,
+        $args{path} );
+
+    $args{path} = '/' . $args{path} unless $args{path} =~ m{^/};
+
+    my $dir = tempdir( CLEANUP => 1 );
+
+    my $file = File::Spec->catfile( $dir, $args{path} );
+
+    if ( $args{path} =~ m{(.*)/} ) {
+        $self->checkout(
+            path   => $1,
+            target => $file,
+        );
+
+        copy( File::Spec->catfile( Shipwright::Util->share_root, $args{path} ),
+            $file );
+        $self->commit(
+            path    => $file,
+            comment => "update $args{path}",
+        );
+    }
+}
+
 1;
 
 __END__



More information about the Bps-public-commit mailing list