[Swift-commit] r3524 - usertools/swift/swiftconfig/bin

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Thu Aug 12 00:27:06 CDT 2010


Author: davidk
Date: 2010-08-12 00:27:06 -0500 (Thu, 12 Aug 2010)
New Revision: 3524

Modified:
   usertools/swift/swiftconfig/bin/swiftrun
Log:
Symlink data in run directory with -input


Modified: usertools/swift/swiftconfig/bin/swiftrun
===================================================================
--- usertools/swift/swiftconfig/bin/swiftrun	2010-08-12 00:34:26 UTC (rev 3523)
+++ usertools/swift/swiftconfig/bin/swiftrun	2010-08-12 05:27:06 UTC (rev 3524)
@@ -1,31 +1,34 @@
 #!/usr/bin/perl -w
 
 use strict;
+use FindBin qw($Bin);
+use lib "$FindBin::Bin/../lib/perl";
 use Cwd;
 use Cwd qw(abs_path);
 use File::Copy;
 use File::Path;
+use Getopt::Long;
+use File::Which qw(which where);
+use XML::Simple;
 
-my $swifthome = '';
+# Figure out the path to Swift
+my $swift_home = q{};
 if ( $ENV{'SWIFT_HOME'} && -e "$ENV{'SWIFT_HOME'}/bin/swift" ) {
-    $swifthome = $ENV{'SWIFT_HOME'};
+    $swift_home = $ENV{'SWIFT_HOME'};
 }
-
-my @path = split( '/', abs_path($0) );
- at path = splice( @path, 0, $#path - 1 );
-my $parent_directory = join( '/', @path );
-
-if ( !$swifthome ) {
+my @execution_path = split( '/', abs_path($0) );
+ at execution_path = splice( @execution_path, 0, $#execution_path - 1 );
+my $parent_directory = join( '/', @execution_path );
+if ( !$swift_home ) {
     if ( -e "$parent_directory/bin/swift" ) {
-        $swifthome = $parent_directory;
+        $swift_home = $parent_directory;
     }
-
     else {
-        @path = split( '/', which("swift") );
-        @path = splice( @path, 0, $#path - 1 );
-        my $tmp = join( '/', @path );
+        @execution_path = split( '/', which("swift") );
+        @execution_path = splice( @execution_path, 0, $#execution_path - 1 );
+        my $tmp = join( '/', @execution_path );
         if ( -e "$tmp/bin/swift" ) {
-            $swifthome = $tmp;
+            $swift_home = $tmp;
         }
     }
 }
@@ -35,7 +38,7 @@
     my $directory = $_[0];
     if ( !-d "$directory" ) {
         mkdir "$directory", 0700
-            or die "Unable to create directory $directory\n";
+            || die "Unable to create directory $directory\n";
     }
 }
 
@@ -43,7 +46,7 @@
 sub cat_file {
     my ( $src, $dst ) = @_;
     if ( -e $dst ) {
-        open( DSTFILE, ">>$dst" ) or die "Unable to open $dst for append\n";
+        open( DSTFILE, ">>$dst" ) || die "Unable to open $dst for append\n";
     }
     else {
         open( DSTFILE, ">$dst" )
@@ -71,56 +74,70 @@
     return $filename;
 }
 
-use FindBin qw($Bin);
-use lib "$FindBin::Bin/../lib/perl";
-use Getopt::Long;
-use File::Which qw(which where);
-use XML::Simple;
-use Data::Dumper;
+# Command line processing
+my @option_sites;     # Site name to execute upon
+my $option_script;    # Script name to run
+my @option_inputs;    # Name of data to include with execution
 
-my $site;      # Site name to execute upon
-my $script;    # Script name to run
-
 GetOptions(
-    'site=s'   => \$site,
-    'script=s' => \$script,
+    'site|sites=s{,}'   => \@option_sites,
+    'script=s'          => \$option_script,
+    'input|inputs=s{,}' => \@option_inputs,
 );
 
 # Verify user-created profile info exists
 my ( $seconds, $minutes, $hours, $days, $months, $years, @junk ) =
     localtime(time);
-my $datestring = sprintf "%04s%02s%02s%02s%02s%02s%s", $years + 1900,
+my $date_string = sprintf "%04s%02s%02s%02s%02s%02s%s", $years + 1900,
     $months + 1, $days, $hours, $minutes, $seconds, getpgrp(0);
-my $dotswift = "$ENV{'HOME'}/.swift";
+my $dotswift_directory = "$ENV{'HOME'}/.swift";
 
 # Run job
-my @sites = split( /,/, $site );
-my $script_filename = strip_directory($script);
-create_directory("$dotswift/jobs");
-create_directory("$dotswift/jobs/$script_filename");
-create_directory("$dotswift/jobs/$script_filename/$datestring");
-copy_file( "$script", "$dotswift/jobs/$script_filename/$datestring" );
+my $script_filename = strip_directory($option_script);
+create_directory("$dotswift_directory/jobs");
+create_directory("$dotswift_directory/jobs/$script_filename");
+create_directory("$dotswift_directory/jobs/$script_filename/$date_string");
+copy_file( "$option_script",
+    "$dotswift_directory/jobs/$script_filename/$date_string" );
 
-# Create configuration file for run
-foreach my $s (@sites) {
-    if ( !-d "$dotswift/sites/$s" ) {
-        print "$dotswift/sites/$site\n";
-        die "Unable to find entry for $s\n";
+# Create configuration files for run
+foreach my $site (@option_sites) {
+    if ( !-d "$dotswift_directory/sites/$site" ) {
+        die "Unable to find entry for $site\n";
     }
-    if ( !-e "$dotswift/sites/$s/sites.xml" ) {
-        die "Unable to find sites.xml for $s\n";
+    if ( !-e "$dotswift_directory/sites/$site/sites.xml" ) {
+        die "Unable to find sites.xml for $site\n";
     }
-    if ( !-e "$dotswift/sites/$s/tc.data" ) {
-        die "Unable to find tc.data for $s\n";
+    if ( !-e "$dotswift_directory/sites/$site/tc.data" ) {
+        die "Unable to find tc.data for $site\n";
     }
-    cat_file( "$dotswift/sites/$s/sites.xml",
-        "$dotswift/jobs/$script_filename/$datestring/sites.xml" );
-    cat_file( "$dotswift/sites/$s/tc.data",
-        "$dotswift/jobs/$script_filename/$datestring/tc.data" );
+    cat_file( "$dotswift_directory/sites/$site/sites.xml",
+        "$dotswift_directory/jobs/$script_filename/$date_string/sites.xml" );
+    cat_file( "$dotswift_directory/sites/$site/tc.data",
+        "$dotswift_directory/jobs/$script_filename/$date_string/tc.data" );
 }
 
-# Update XML tags
-my $site_filename = "$dotswift/jobs/$script_filename/$datestring/sites.xml";
+# Link input data
+foreach my $input_file (@option_inputs) {
+
+    # Check for relative path
+    my $relative_file = getcwd() . "/$input_file";
+    if ( -e $relative_file ) {
+        $input_file = $relative_file;
+    }
+
+    if ( !-e $input_file ) {
+        die "Unable to find requested input file: $input_file\n";
+    }
+    my $new_path = "$dotswift_directory/jobs/$script_filename/$date_string/"
+        . strip_directory($input_file);
+    symlink $input_file, $new_path
+        || die "Unable to create symlink to $new_path\n";
+}
+
+# Complete XML tags
+my $site_filename =
+    "$dotswift_directory/jobs/$script_filename/$date_string/sites.xml";
 open( SITEFILE, "$site_filename" ) || die "Unable to open $site_filename\n";
 my @sitedata = <SITEFILE>;
 close(SITEFILE);
@@ -129,10 +146,10 @@
 close(SITEFILE);
 
 # Run swift
-my $run_directory = "$dotswift/jobs/$script_filename/$datestring";
+my $run_directory = "$dotswift_directory/jobs/$script_filename/$date_string";
 chdir("$run_directory") || die "Unable to chdir to $run_directory\n";
 print "Submitting job. Check $run_directory for details\n";
 system(
-    "swift -sites.file $site_filename -tc.file $run_directory/tc.data $script"
+    "swift -sites.file $site_filename -tc.file $run_directory/tc.data $option_script"
 );
 




More information about the Swift-commit mailing list