| 1 | package OpenInteract2::Setup::CreateTemporaryLibraryDirectory; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # $Id: CreateTemporaryLibraryDirectory.pm,v 1.3 2005/03/18 04:09:51 lachoy Exp $ | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 87 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 87 | ▶ | use base qw( OpenInteract2::Setup ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 87 | ▶ | use File::Basename qw( dirname ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 87 | ▶ | use File::Copy qw( cp ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 87 | ▶ | use File::Path qw( mkpath rmtree ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 87 | ▶ | use File::Spec::Functions qw( catfile ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 87 | ▶ | use Log::Log4perl qw( get_logger ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 87 | ▶ | use OpenInteract2::Constants qw( :log ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 87 | ▶ | use OpenInteract2::Exception qw( oi_error ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 87 | $OpenInteract2::Setup::CreateTemporaryLibraryDirectory::VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 87 | my ( $log ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 87 | ▶ | sub get_name { | ||||||||||||||||||||||||||
|
Subroutine
get_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 87 | return 'create templib'; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | sub get_dependencies { | ||||||||||||||||||||||||||
|
Subroutine
get_dependencies: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 1 | return ( 'read packages' ); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 0 | my ( $self, $ctx ) = @_; | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | $log ||= get_logger( LOG_INIT ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.INITIALIZE")
MC/DC0%0/2
$log ||= get_logger("OI2.INITIALIZE")
$log
get_logger("OI2.INITIALIZE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.INITIALIZE")
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | my $full_temp_lib_dir = $ctx->lookup_temp_lib_directory; | |||||||||||||||||||||||||||
| 32 | 0 | unshift @INC, $full_temp_lib_dir; | |||||||||||||||||||||||||||
| 33 | 0 | $log->info( "Added '$full_temp_lib_dir' to \@INC" ); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | $self->param( created => [] ); # default: don't create anything | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my $do_create = $self->param( 'create_templib' ) || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->param('create_templib') || 0
MC/DC0%0/1
$self->param('create_templib') || 0
$self->param('create_templib')
Truth table0%0/2
A
A= $self->param('create_templib')
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( ! $do_create && -d $full_temp_lib_dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $do_create and -d $full_temp_lib_dir
MC/DC0%0/2
not $do_create and -d $full_temp_lib_dir
not $do_create
-d $full_temp_lib_dir
Truth table0%0/3
not(A) and B
A= not $do_createB= -d $full_temp_lib_dir
| |||||||||||||||||||||||||||||
| 39 | 0 | my $refresh_file = catfile( $full_temp_lib_dir, | |||||||||||||||||||||||||||
| 40 | $ctx->lookup_temp_lib_refresh_filename ); | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | unless ( -f $refresh_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $log->info( "Temporary library directory '$full_temp_lib_dir' ", | |||||||||||||||||||||||||||
| 43 | "exists; not given a 'create_templib' parameter and ", | ||||||||||||||||||||||||||||
| 44 | "there is no 'refresh' file at '$refresh_file', ", | ||||||||||||||||||||||||||||
| 45 | "so no modules were copied." ); | ||||||||||||||||||||||||||||
| 46 | 0 | $self->_find_runtime_tasks( $full_temp_lib_dir ); | |||||||||||||||||||||||||||
| 47 | 0 | return; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | $log->info( "Not given a force create for the temporary library ", | |||||||||||||||||||||||||||
| 50 | "directory and it already exists, but there's a ", | ||||||||||||||||||||||||||||
| 51 | "'refresh' file at '$refresh_file' so we'll go ahead ", | ||||||||||||||||||||||||||||
| 52 | "and re-create it." ); | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( -d $full_temp_lib_dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | my $num_removed = rmtree( $full_temp_lib_dir ); | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | unless ( $num_removed ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | oi_error "Tried to remove existing temporary library directory ", | |||||||||||||||||||||||||||
| 59 | "'$full_temp_lib_dir' but no directories removed. ", | ||||||||||||||||||||||||||||
| 60 | "Please check permissions."; | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | $log->info( "Removed existing temporary library directory ", | |||||||||||||||||||||||||||
| 63 | "'$full_temp_lib_dir' ok" ); | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | eval { mkdir( $full_temp_lib_dir, 0777 ) || die $! }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | oi_error "Failed to create temporary library directory ", | |||||||||||||||||||||||||||
| 68 | "'$full_temp_lib_dir': $@"; | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my ( @copied_modules ); | |||||||||||||||||||||||||||
| 72 | 0 | foreach my $package ( @{ $ctx->packages } ) { | |||||||||||||||||||||||||||
| 73 | 0 | push @copied_modules, | |||||||||||||||||||||||||||
| 74 | $self->_copy_modules_from_package( $package, $full_temp_lib_dir ); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | $log->is_debug && | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $log->debug( "Copied ", scalar @copied_modules, " modules ", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | "to '$full_temp_lib_dir'" ); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # TODO: does this work properly on win32? | ||||||||||||||||||||||||||||
| 82 | 0 | chmod( 0666, @copied_modules ); # let the umask do the hard work | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | my %tmp_dirs = map { $_ => 1 } map { dirname( $_ ) } @copied_modules; | |||||||||||||||||||||||||||
| 85 | 0 | chmod( 0777, ( keys %tmp_dirs, $full_temp_lib_dir ) ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | $self->_find_runtime_tasks( $full_temp_lib_dir ); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $self->param( copied => \@copied_modules ); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # Picks up management + setup tasks from packages (move this to Context?) | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub _find_runtime_tasks { | ||||||||||||||||||||||||||
|
Subroutine
_find_runtime_tasks: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 95 | 0 | my ( $self, $temp_lib_dir ) = @_; | |||||||||||||||||||||||||||
| 96 | 0 | OpenInteract2::Util->find_factory_subclasses( | |||||||||||||||||||||||||||
| 97 | 'OpenInteract2::Manage', $temp_lib_dir | ||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||
| 99 | 0 | OpenInteract2::Util->find_factory_subclasses( | |||||||||||||||||||||||||||
| 100 | 'OpenInteract2::Setup', $temp_lib_dir | ||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub _copy_modules_from_package { | ||||||||||||||||||||||||||
|
Subroutine
_copy_modules_from_package: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 106 | 0 | my ( $self, $package, $temp_lib_dir ) = @_; | |||||||||||||||||||||||||||
| 107 | 0 | my $package_name = $package->name; | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | $log->debug( "Trying to copy files for package $package_name" ); | ||||||||||||||||||||||||||||
| 110 | 0 | my $package_dir = $package->directory; | |||||||||||||||||||||||||||
| 111 | 0 | my $module_files = $package->get_module_files; | |||||||||||||||||||||||||||
| 112 | 0 | my @package_modules = (); | |||||||||||||||||||||||||||
| 113 | 0 | foreach my $module_file_spec ( @{ $module_files } ) { | |||||||||||||||||||||||||||
| 114 | my $source_file = catfile( $package_dir, | ||||||||||||||||||||||||||||
| 115 | 0 | @{ $module_file_spec } ); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # if installed from CPAN dist, the source file won't be | ||||||||||||||||||||||||||||
| 118 | # there... | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | next unless ( -f $source_file ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | my $dest_file = catfile( $temp_lib_dir, | ||||||||||||||||||||||||||||
| 122 | 0 | @{ $module_file_spec } ); | |||||||||||||||||||||||||||
| 123 | 0 | my $dest_path = dirname( $dest_file ); | |||||||||||||||||||||||||||
| 124 | 0 | mkpath( $dest_path, undef, 0777 ); | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | eval { cp( $source_file, $dest_file ) || die $! }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | oi_error "When creating temporary library, failed to ", | |||||||||||||||||||||||||||
| 129 | "copy package '$package_name' module '$source_file' ", | ||||||||||||||||||||||||||||
| 130 | "to '$dest_file': $@"; | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 0 | push @package_modules, $dest_file; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 0 | return @package_modules; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 87 | OpenInteract2::Setup->register_factory_type( get_name() => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 87 | 1; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | __END__ | ||||||||||||||||||||||||||||