From: Chris W. <la...@us...> - 2005-03-24 05:32:44
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Manage/Website In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28827/Website Modified Files: InstallPackage.pm Log Message: be able to install package given a brick_class or brick_name, assuming it contains a single resource with the base64'd zip file Index: InstallPackage.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Manage/Website/InstallPackage.pm,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** InstallPackage.pm 17 Mar 2005 14:58:04 -0000 1.20 --- InstallPackage.pm 24 Mar 2005 05:32:35 -0000 1.21 *************** *** 34,38 **** package_class => { description => ! 'Package distribution application class that can perform installation', is_required => 'no', do_validate => 'yes', --- 34,50 ---- package_class => { description => ! 'OpenInteract2::App:: class that can perform installation', ! is_required => 'no', ! do_validate => 'yes', ! }, ! brick_class => { ! description => ! 'OpenInteract2::Brick:: class that contains package as zip file', ! is_required => 'no', ! do_validate => 'yes', ! }, ! brick_name => { ! description => ! 'Name of OpenInteract2::Brick:: implementation that contains package as zip file', is_required => 'no', do_validate => 'yes', *************** *** 45,50 **** if ( $name eq 'package_class' ) { my $pkg_file = $self->param( 'package_file' ); ! unless ( $value or $pkg_file ) { ! return "Either 'package_class' or 'package_file' must be defined."; } return; --- 57,65 ---- if ( $name eq 'package_class' ) { my $pkg_file = $self->param( 'package_file' ); ! my $brick_class = $self->param( 'brick_class' ); ! my $brick_name = $self->param( 'brick_name' ); ! unless ( $value or $pkg_file or $brick_class or $brick_name ) { ! return "One of 'package_class', 'package_file', " . ! "'brick_class', or 'brick_name' must be defined."; } return; *************** *** 53,56 **** --- 68,92 ---- return unless ( $value ); } + elsif ( $name eq 'brick_class' ) { + return unless ( $value ); + eval "require $value"; + if ( $@ ) { + return "Failed to require '$value': $@"; + } + my $brick_name = $value->get_name(); + unless ( $brick_name ) { + return "Class '$value' is valid but did not return a " . + "name with 'get_name()'"; + } + $self->param( brick_name => $brick_name ); + return; + } + elsif ( $name eq 'brick_name' ) { + my $brick = eval { OpenInteract2::Brick->new( $value ) }; + if ( $@ or ! $brick ) { + my $error = $@ || 'no brick found'; + return "Brick '$name' error: $error"; + } + } return $self->SUPER::validate_param( $name, $value ); } *************** *** 72,75 **** --- 108,114 ---- $self->_install_app( $app_class, \%status ); } + elsif ( my $brick_name = $self->param( 'brick_name' ) ) { + $self->_install_brick( $brick_name, \%status ); + } $self->_add_status( \%status ); } *************** *** 170,174 **** $status->{message} = sprintf( 'Installed package %s-%s to website %s', ! $name, $version, $self->param( 'website_dir' ) ); --- 209,213 ---- $status->{message} = sprintf( 'Installed package %s-%s to website %s', ! $name, $version, $self->param( 'website_dir' ) ); *************** *** 177,180 **** --- 216,237 ---- } + sub _install_brick { + my ( $self, $brick_name, $status ) = @_; + my $brick = OpenInteract2::Brick->new( $brick_name ); + my @resources = $brick->list_resources; + if ( scalar @resources > 1 ) { + $status->{is_ok} = 'no'; + $status->{message} = + "Brick class ", ref( $brick ), " should only have one " . + "resource -- the Base64 version of the zip file."; + return; + } + my $pkg_info = $brick->load_resource( $resources[0] ); + my $pkg_file = OpenInteract2::Util->decode_base64_and_store( + \$pkg_info->{content} + ); + $self->_install_file( $pkg_file, $status ); + } + sub _check_package_exists { my ( $self, $name, $version, $status ) = @_; |