From: Rob H. <for...@us...> - 2003-06-09 18:38:35
|
Update of /cvsroot/sandweb/sandweb/bin In directory sc8-pr-cvs1:/tmp/cvs-serv14263/bin Modified Files: sandweb.cgi Log Message: * disabled "CVS status" requests, this should happen from CVS/* metadatadir anyway (those "status" patches need some cleanup anyway) * new feature - batch/upload download. Index: sandweb.cgi =================================================================== RCS file: /cvsroot/sandweb/sandweb/bin/sandweb.cgi,v retrieving revision 1.354 retrieving revision 1.355 diff -U2 -r1.354 -r1.355 --- sandweb.cgi 1 Jun 2003 20:26:24 -0000 1.354 +++ sandweb.cgi 9 Jun 2003 18:16:13 -0000 1.355 @@ -553,4 +553,6 @@ elsif ( $action eq 'upload' ) { # called file uploader + my $batch = $cgi->param('batch'); + if ($submit) { upload_commit( @@ -561,4 +563,5 @@ location => $location, previous_url => $previous_url, + batch => $batch, ) } else { @@ -568,7 +571,36 @@ repo_name => $repo_name, location => $location, + batch => $batch, ); } } + elsif ( $action eq 'batch_download' ) { + # called batch file downloader + + my @files = (); + + if ( $cgi->param('filename') ) { + @files = $cgi->param('filename'), + } else { + @files = ('.'); + } + + batch_download_menu( + ck_auth => $ck_auth, + filename => \@files, + module_name => $module_name, + repo_name => $repo_name, + location => $location, + ); + } + elsif ( $action eq 'batch_download_commit' ) { + # called batch file downloader + batch_download_commit( + ck_auth => $ck_auth, + module_name => $module_name, + repo_name => $repo_name, + location => $location, + ); + } elsif ( $action eq 'download_file' ) { # called file downloader @@ -977,6 +1009,7 @@ $log->debug("current_location: ".$location); - my %localstatus = $repository->status(file => ".", recurse => "false" ); - my @localstatusoutput=$localstatus{output}; + #my %localstatus = $repository->status(file => ".", recurse => "false" ); + #my @localstatusoutput=$localstatus{output}; + my @localstatusoutput = ''; my %browser = $browse->get_browser( @@ -986,6 +1019,6 @@ 'repo_name' => $repo_name, 'sort' => $sort, - 'viewcvs' => $viewcvs, - 'localstatus' => \@localstatusoutput, + 'viewcvs' => $viewcvs, + 'localstatus' => \@localstatusoutput, ); @@ -1868,4 +1901,5 @@ my $repo_name = $args{'repo_name'}; my $prev_url = "$ENV{'HTTP_REFERER'}"; + my $batch = $args{'batch'}; my $image_dir = $config->{'webserver'}->{'image_dir'}; @@ -1879,4 +1913,5 @@ PREVIOUS_URL => $prev_url, IMAGE_DIR => $image_dir, + BATCH => $batch, ); print $cgi->header( -cookie => $ck_auth ); @@ -1893,4 +1928,96 @@ =head1 ############################################################################### +# batch download menu +# +# allows user to download a set of files +# +# args: +# ck_auth - the sessions cookie +# location - system path to the file(s) specified by filename +# repo_name - name of the current repository. +# module_name - name of the current module. +# users_dir - location of user sandbox directories. +############################################################################### +=cut + +sub batch_download_menu{ + my %args = @_; + + my $ck_auth = $args{'ck_auth'}; + my $location = $args{'location'}; + my $username = $auth->get_username(); + my $users_dir = $config->{'paths'}->{'users_dir'}; + my $repo_name = $args{'repo_name'}; + my $module_name = $args{'module_name'}; + my $previous_url = $args{'previous_url'}; + my $filename = $args{'filename'}; + + my @files = (); + my $count=0; + while ( $filename->[$count] ) { + my $line = $filename->[$count]; + unless ($line eq '.') { + push (@files, "$module_name/$line"); + } + $count++; + } + + my $files; + + foreach my $file (@files){ + chomp $file; + if ($file =~ "CVS") { + $file = ''; + } elsif ($file) { + $files = $files." \"$file\""; + } + } + + unless ($files){ + $log->debug("no file was selected for download"); + my $content = $ui->get_menu( + MENU => 'output', + LOCATION => $location, + FILENAME => '', + OUTPUT => "Please select file or folders to +download", + ERROR => "No files selected", + ); + print $cgi->header( -cookie => $ck_auth ); + $ui->print_popup( + TITLE => 'SandWeb : batch download', + MENU_TITLE => 'SandWeb', + SUBMENU_TITLE => 'batch download', + FOOTER => '', + CONTENT => $content, + MESSAGE => $message, + ); + exit; + } + + # FIXME - move to SW::File + print `cd $users_dir/$username/$repo_name/ && /bin/tar -cf $users_dir/$username/.tmp/$module_name.tar $files 2>&1 > /dev/null`; + + my $content = $ui->get_menu( + MENU => 'batch_download', + LOCATION => $location, + PROGNAME => $progname, + MODULE_NAME => $module_name, + REPO_NAME => $repo_name, + DOWNLOAD => "/cgi-bin/sandweb.cgi/$module_name.tar?action=batch_download_commit&module_name=$module_name", + ); + print $cgi->header( -cookie => $ck_auth ); + $ui->print_popup( + TITLE=> 'SandWeb : download batch', + MENU_TITLE => 'SandWeb', + SUBMENU_TITLE => 'download batch', + FOOTER => '', + CONTENT => $content, + MESSAGE => $message, + ); +} + +=head1 +############################################################################### # vcs menu # @@ -2513,4 +2640,5 @@ my $module_name = $args{'module_name'}; my $previous_url = $args{'previous_url'}; + my $batch = $args{'batch'}; my $filename = $args{'filename'}; my $filehandle = $args{'filehandle'}; @@ -2530,4 +2658,11 @@ filehandle => $filehandle, ); + # if it's a batch, unpack it! + # FIXME - need a way to notify user of success/failure! + if ($batch) { + `cd $users_dir/$username/$repo_name/ && tar xvf "$module_name/$location/$filename"`; + # don't want to leave batches laying around.. + $file->delete(); + } print $cgi->redirect( "$previous_url" ); } else { @@ -2535,4 +2670,45 @@ print $cgi->redirect( "$previous_url" ); } +} + +=head1 +############################################################################### +# batch_download_commit generates an archive of files and sends the archive to +# the user. +# +# A File object is created and used. +# +# args: +# ck_auth - the sessions cookie +# filename - name of the file(s) that the File object should +# be invoked with. +# location - system path to the file(s) specified by filename +# repo_name - name of the current repository. +# module_name - name of the current module. +# users_dir - location of user sandbox directories. +############################################################################### + +=cut + +sub batch_download_commit { + my %args = @_; + + my $ck_auth = $args{'ck_auth'}; + my $location = $args{'location'}; + my $username = $auth->get_username(); + my $users_dir = $config->{'paths'}->{'users_dir'}; + my $repo_name = $args{'repo_name'}; + my $module_name = $args{'module_name'}; + my $previous_url = $args{'previous_url'}; + + my $file = SandWeb::File->new( + 'config_obj' => $config, + 'log_obj' => $log, + 'filename' => "$module_name.tar", + 'location' => "$users_dir/$username/.tmp/", + ); + + $file->download(); + $file->delete(); } |