| 1 | # | ||
| 2 | # This file is part of App-Magpie | ||
| 3 | # | ||
| 4 | # This software is copyright (c) 2011 by Jerome Quelin. | ||
| 5 | # | ||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||
| 8 | # | ||
| 9 | 2 | ▶ | use 5.012; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | package App::Magpie::Action::Checkout; | ||
| 14 | # ABSTRACT: checkout command implementation | ||
| 15 | $App::Magpie::Action::Checkout::VERSION = '2.010'; | ||
| 16 | 2 | ▶ | use File::pushd; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 2 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 2 | ▶ | use Path::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 0 | ▶ | use App::Magpie::URPM; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 21 | |||
| 22 | with 'App::Magpie::Role::Logging'; | ||
| 23 | with 'App::Magpie::Role::RunningCommand'; | ||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | sub run { | ||
| 28 | my ($self, $pkg, $directory) = @_; | ||
| 29 | |||
| 30 | # check if argument is a perl module or a mageia rpm name | ||
| 31 | if ( not _pkg_exist_in_svn($pkg) ) { | ||
| 32 | $self->log( "$pkg doesn't exist, looking if it's a perl module" ); | ||
| 33 | my $urpm = App::Magpie::URPM->instance; | ||
| 34 | my ($realpkg) = map { $_->name } $urpm->packages_providing( $pkg ); | ||
| 35 | $self->log_fatal( "$pkg doesn't exist and isn't a perl module, aborting" ) | ||
| 36 | unless $realpkg && _pkg_exist_in_svn( $realpkg ); | ||
| 37 | $self->log( "$pkg is a module provided by $realpkg" ); | ||
| 38 | $pkg = $realpkg; | ||
| 39 | } | ||
| 40 | |||
| 41 | # check out the package, or update the local checkout | ||
| 42 | my $dir = defined($directory) ? path( $directory ) : path("."); | ||
| 43 | my $pkgdir = $dir->child( $pkg ); | ||
| 44 | $dir->mkpath unless -d $dir; | ||
| 45 | $self->log( "checking out $pkg in $pkgdir" ); | ||
| 46 | |||
| 47 | if ( -d $pkgdir ) { | ||
| 48 | $self->log( "package already checked out, refreshing checkout"); | ||
| 49 | my $old = pushd( $pkgdir ); | ||
| 50 | $self->run_command( "mgarepo up" ); | ||
| 51 | } else { | ||
| 52 | my $old = pushd( $dir ); | ||
| 53 | $self->run_command( "mgarepo co $pkg" ); | ||
| 54 | } | ||
| 55 | |||
| 56 | return $pkgdir; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | # -- private subs | ||
| 61 | |||
| 62 | # | ||
| 63 | # my $bool = _pkg_exist_in_svn( $pkg ); | ||
| 64 | # | ||
| 65 | # return true if $pkg is a real package in cauldron. | ||
| 66 | # | ||
| 67 | sub _pkg_exist_in_svn { | ||
| 68 | my $pkg = shift; | ||
| 69 | my $svn = "svn+ssh://svn.mageia.org/svn/packages/cauldron"; | ||
| 70 | return system( "svn ls $svn/$pkg >/dev/null 2>&1" ) == 0; | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | 1; | ||
| 75 | |||
| 76 | __END__ | ||