« OpenInteract2/Manage/Website/ListActions.pm
↑ Summary
OpenInteract2/ActionResolver/NotFoundOrEmpty.pm »
| 1 | package OpenInteract2::Manage::Website::UpdatePackageFromWebsite; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # $Id: UpdatePackageFromWebsite.pm,v 1.5 2005/03/18 04:09:50 lachoy Exp $ | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 87 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 87 | ▶ | use base qw( OpenInteract2::Manage::Website ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 87 | ▶ | use File::Spec::Functions qw( catfile ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 87 | ▶ | use OpenInteract2::Context qw( CTX ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 87 | ▶ | use OpenInteract2::Config::PackageChanges; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 87 | $OpenInteract2::Manage::Website::UpdatePackageFromWebsite::VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 87 | my $ACTION = 'update development package'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 87 | ▶ | sub get_name { | ||||||||||||||||||||||||||
|
Subroutine
get_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 87 | return 'update_package'; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub get_brief_description { | ||||||||||||||||||||||||||
|
Subroutine
get_brief_description: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 0 | return "Update your development package with files deployed to a " . | |||||||||||||||||||||||||||
| 21 | "website. This allows you to quickly make lots of small " . | ||||||||||||||||||||||||||||
| 22 | "changes without going through the deployment steps."; | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub get_parameters { | ||||||||||||||||||||||||||
|
Subroutine
get_parameters: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 27 | 0 | my $package_desc = | |||||||||||||||||||||||||||
| 28 | "Name of package to update from. I will look into the " . | ||||||||||||||||||||||||||||
| 29 | "latest version deployed to the website for the files " . | ||||||||||||||||||||||||||||
| 30 | "to update."; | ||||||||||||||||||||||||||||
| 31 | 0 | my $changelog_desc = | |||||||||||||||||||||||||||
| 32 | "A description of these changes to enter into 'Changes'"; | ||||||||||||||||||||||||||||
| 33 | return { | ||||||||||||||||||||||||||||
| 34 | 0 | website_dir => $self->_get_website_dir_param, | |||||||||||||||||||||||||||
| 35 | package_dir => { | ||||||||||||||||||||||||||||
| 36 | description => 'Directory of development package.', | ||||||||||||||||||||||||||||
| 37 | is_required => 'yes', | ||||||||||||||||||||||||||||
| 38 | do_validate => 'yes', | ||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||
| 40 | package => { | ||||||||||||||||||||||||||||
| 41 | description => $package_desc, | ||||||||||||||||||||||||||||
| 42 | is_required => 'yes', | ||||||||||||||||||||||||||||
| 43 | do_validate => 'no', | ||||||||||||||||||||||||||||
| 44 | }, | ||||||||||||||||||||||||||||
| 45 | changelog => { | ||||||||||||||||||||||||||||
| 46 | description => $changelog_desc, | ||||||||||||||||||||||||||||
| 47 | is_required => 'no', | ||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub validate_param { | ||||||||||||||||||||||||||
|
Subroutine
validate_param: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 0 | my ( $self, $param_name, $param_value ) = @_; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( $param_name eq 'package_dir' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | unless ( -d $param_value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | return "Must be a valid directory"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 0 | my $changelog = catfile( $param_value, 'Changes' ); | |||||||||||||||||||||||||||
| 59 | 0 | my $package_conf = catfile( $param_value, 'package.conf' ); | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | unless ( -f $changelog && -f $package_conf ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $changelog and -f $package_conf
MC/DC0%0/2
-f $changelog and -f $package_conf
-f $changelog
-f $package_conf
Truth table0%0/3
A and B
A= -f $changelogB= -f $package_conf
| |||||||||||||||||||||||||||||
| 61 | 0 | return "Does not appear to be a valid package directory"; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 0 | return $self->SUPER::validate_param( $param_name, $param_value ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub run_task { | ||||||||||||||||||||||||||
|
Subroutine
run_task: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # We have to validate 'package' here because the context isn't yet | ||||||||||||||||||||||||||||
| 71 | # created when 'validate_param()' is run | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return unless ( $self->_is_valid_website_package ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | $self->_sync_dirs(); | |||||||||||||||||||||||||||
| 76 | 0 | my $rv = $self->_write_new_changelog(); | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( $rv ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | $self->_ok( $ACTION, 'Updated development package' ); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||
| 81 | 0 | $self->_fail( $ACTION, 'Failed to update development package' ); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub _is_valid_website_package { | ||||||||||||||||||||||||||
|
Subroutine
_is_valid_website_package: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 86 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my $package_name = $self->param( 'package' )->[0]; | |||||||||||||||||||||||||||
| 89 | 0 | my $package = eval { | |||||||||||||||||||||||||||
| 90 | 0 | CTX->repository->fetch_package( $package_name ) | |||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ( $@ || ! $package ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not $package
MC/DC0%0/2
$@ or not $package
$@
not $package
Truth table0%0/3
A or not(B)
A= $@B= not $package
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | my $error = $@ || "Package '$package_name' does not exist in website"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$@ || "Package '${package_name}' does not exist in website"
MC/DC0%0/1
$@ || "Package '${package_name}' does not exist in website"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 94 | 0 | $self->_fail( $ACTION, $error ); | |||||||||||||||||||||||||||
| 95 | 0 | return undef; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 0 | $self->param( package_object => $package ); | |||||||||||||||||||||||||||
| 98 | 0 | return 1; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub _sync_dirs { | ||||||||||||||||||||||||||
|
Subroutine
_sync_dirs: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 102 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 103 | 0 | my $package = $self->param( 'package_object' ); | |||||||||||||||||||||||||||
| 104 | 0 | my $source_dir = $package->directory; | |||||||||||||||||||||||||||
| 105 | 0 | my $status = $package->copy_contents_to( $self->param( 'package_dir' ) ); | |||||||||||||||||||||||||||
| 106 | 0 | $self->_set_copy_file_status( $status ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub _write_new_changelog { | ||||||||||||||||||||||||||
|
Subroutine
_write_new_changelog: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 110 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 111 | 0 | my $action = 'write changelog'; | |||||||||||||||||||||||||||
| 112 | 0 | my $package = $self->param( 'package_object' ); | |||||||||||||||||||||||||||
| 113 | 0 | my $changes = OpenInteract2::Config::PackageChanges->new({ | |||||||||||||||||||||||||||
| 114 | package => $package, | ||||||||||||||||||||||||||||
| 115 | }); | ||||||||||||||||||||||||||||
| 116 | 0 | my $latest_change = $changes->latest(1); | |||||||||||||||||||||||||||
| 117 | 0 | my $new_version = $latest_change->{version} + 0.01; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | my $change_msg = $self->param( 'changelog' ) || 'no message'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->param('changelog') || 'no message'
MC/DC0%0/1
$self->param('changelog') || 'no message'
$self->param('changelog')
Truth table0%0/2
A
A= $self->param('changelog')
| |||||||||||||||||||||||||||||
| 120 | 0 | $changes->add_entry( $new_version, scalar( localtime ), $change_msg ) ; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | my $dev_changelog = | |||||||||||||||||||||||||||
| 123 | catfile( $self->param( 'package_dir' ), 'Changes' ); | ||||||||||||||||||||||||||||
| 124 | 0 | eval { | |||||||||||||||||||||||||||
| 125 | 0 | $changes->write_config( $dev_changelog ); | |||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | $self->_fail( $action, | |||||||||||||||||||||||||||
| 129 | "Cannot write changes to '$dev_changelog': $@" ); | ||||||||||||||||||||||||||||
| 130 | 0 | return 0; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||
| 133 | 0 | $self->_ok( $action, | |||||||||||||||||||||||||||
| 134 | "Wrote changes to '$dev_changelog' ok" ); | ||||||||||||||||||||||||||||
| 135 | 0 | return 1; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 87 | OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 87 | 1; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | __END__ | ||||||||||||||||||||||||||||