From: Chris W. <la...@us...> - 2005-02-02 13:20:16
|
Update of /cvsroot/openinteract/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26281 Modified Files: build_bricks Log Message: add code to generate the package brick classes Index: build_bricks =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/build_bricks,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** build_bricks 28 Jan 2005 17:07:32 -0000 1.4 --- build_bricks 2 Feb 2005 13:20:03 -0000 1.5 *************** *** 7,10 **** --- 7,12 ---- use strict; + use File::Basename qw( basename ); + use MIME::Base64 qw( encode_base64 ); use Template; *************** *** 70,77 **** --- 72,82 ---- my $brick_template = join( '', <DATA> ); + my @brick_params = (); + while ( my ( $brick_dir, $brick_info ) = each %SPECS ) { my @brick_files = read_brick_files( $brick_dir ); my $brick_name = $brick_info->[0]; my %params = ( + brick_dir => $brick_dir, brick_name => $brick_name, lc_brick_name => lc $brick_name, *************** *** 82,93 **** all_files => \@brick_files, ); ! my $brick_lib_dir = 'lib/OpenInteract2/Brick'; ! unless ( -d $brick_lib_dir ) { ! mkdir( $brick_lib_dir ); ! } my $output_file = "$brick_lib_dir/$brick_name.pm"; ! $template->process( \$brick_template, \%params, $output_file ) ! || die "Cannot process files from '$brick_dir' -> '$output_file': ", $template->error(); ! print "Generated $output_file with ", scalar( @brick_files ), " inlined files\n"; } } --- 87,142 ---- all_files => \@brick_files, ); ! push @brick_params, \%params; ! } ! ! # Now do the same with packages, but base64 them first... ! ! my $pkg_desc = 'This class holds the Base64-encoded versions of ' . ! 'package file "%s" shipped with OpenInteract2. Once you ' . ! 'decode them you should store them as a ZIP file ' . ! 'and then read them in with Archive::Zip or some ' . ! 'other utility.'; ! my %pkg_brick_base = ( ! brick_dir => 'pkg', ! brick_name => 'App%s', ! lc_brick_name => 'pkg_%s', ! brick_summary => "Base-64 encoded OI2 package '%s' shipped with distribution", ! brick_example => 'oi2_manage create_website --website_dir=/path/to/site', ! brick_description => $pkg_desc, ! oi2_version => $oi2_version, ! ); ! foreach my $pkg_file ( read_package_files( 'pkg/' ) ) { ! my %pkg_brick = %pkg_brick_base; ! my $base_name = $pkg_file->{name}; ! $base_name =~ s/^([^-]+).*/$1/; ! my $cc_base_name = ucfirst( $base_name ); ! $cc_base_name =~ s/_(\w)/uc($1)/ge; ! $pkg_brick{brick_name} = sprintf( ! $pkg_brick{brick_name}, $cc_base_name ); ! $pkg_brick{lc_brick_name} = sprintf( ! $pkg_brick{lc_brick_name}, $base_name ); ! $pkg_brick{brick_summary} = sprintf( ! $pkg_brick{brick_summary}, $pkg_file->{name} ); ! $pkg_brick{brick_description} = sprintf( ! $pkg_brick{brick_description}, $pkg_file->{name} ); ! $pkg_brick{all_files} = [ $pkg_file ]; ! push @brick_params, \%pkg_brick; ! } ! ! ! my $brick_lib_dir = 'lib/OpenInteract2/Brick'; ! unless ( -d $brick_lib_dir ) { ! mkdir( $brick_lib_dir ); ! } ! ! foreach my $brick_param ( @brick_params ) { ! my $brick_name = $brick_param->{brick_name}; my $output_file = "$brick_lib_dir/$brick_name.pm"; ! $template->process( \$brick_template, $brick_param, $output_file ) ! || die "Cannot process files from '$brick_param->{brick_dir}' ", ! "-> '$output_file': ", $template->error(); ! print "Generated $output_file with ", ! scalar( @{ $brick_param->{all_files} } ), " ", ! "inlined files\n"; } } *************** *** 113,123 **** my $contents = join( '', <FILE> ); close( FILE ); - my $inline_name = uc $file; - $inline_name =~ s/\W//g; push @files, { name => $file, ! inline_name => $inline_name, destination => $destination, ! evaluatable => $do_evaluate, contents => $contents, }; --- 162,170 ---- my $contents = join( '', <FILE> ); close( FILE ); push @files, { name => $file, ! inline_name => create_inline_name( $file ), destination => $destination, ! evaluate => $do_evaluate, contents => $contents, }; *************** *** 127,130 **** --- 174,211 ---- } + sub read_package_files { + my ( $subdir ) = @_; + my @specs = (); + opendir( ZIPS, $subdir ) + || die "Cannot read zips from '$subdir': $!"; + my @zips = map { "$subdir/$_" } grep /\.zip$/, readdir( ZIPS ); + closedir( ZIPS ); + foreach my $zipfile ( @zips ) { + open( ZIP, '<', $zipfile ) + || die "Cannot read '$zipfile': $!"; + my ( $buf, $content ); + while ( read( ZIP, $buf, 60*57 ) ) { + $content .= encode_base64( $buf ); + } + close( ZIP ); + my $base_filename = basename( $zipfile ); + push @specs, { + name => $base_filename, + inline_name => create_inline_name( $base_filename ), + destination => "pkg $base_filename", + evaluate => 'no', + contents => $content, + }; + } + return @specs; + } + + sub create_inline_name { + my ( $file ) = @_; + my $inline_name = uc $file; + $inline_name =~ s/\W//g; + return $inline_name; + } + sub read_version { open( VER, '<', 'VERSION' ) || die "Cannot open version doc: $!"; *************** *** 156,160 **** return ( [% FOREACH file_info = all_files -%] ! '[% file_info.name %]' => [ '[% file_info.destination %]', '[% file_info.evaluatable %]' ], [% END -%] ); --- 237,241 ---- return ( [% FOREACH file_info = all_files -%] ! '[% file_info.name %]' => [ '[% file_info.destination %]', '[% file_info.evaluate %]' ], [% END -%] ); |