[Swift-commit] r3447 - usertools/swift/swiftconfig/bin
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Tue Jul 20 02:18:20 CDT 2010
Author: davidk
Date: 2010-07-20 02:18:20 -0500 (Tue, 20 Jul 2010)
New Revision: 3447
Added:
usertools/swift/swiftconfig/bin/swiftrun
Log:
swiftrun
Added: usertools/swift/swiftconfig/bin/swiftrun
===================================================================
--- usertools/swift/swiftconfig/bin/swiftrun (rev 0)
+++ usertools/swift/swiftconfig/bin/swiftrun 2010-07-20 07:18:20 UTC (rev 3447)
@@ -0,0 +1,127 @@
+#!/usr/bin/perl
+
+use Cwd;
+use Cwd qw(abs_path);
+use File::Copy;
+use File::Path qw(remove_tree);
+
+my $swifthome = '';
+if ( $ENV{'SWIFT_HOME'} && -e "$ENV{'SWIFT_HOME'}/bin/swift" ) {
+ $swifthome = $ENV{'SWIFT_HOME'};
+}
+
+my @path = split( '/', abs_path($0) );
+my @path = splice( @path, 0, $#path - 1 );
+my $parent_directory = join( '/', @path );
+
+if ( !$swifthome ) {
+ if ( -e "$parent_directory/bin/swift" ) {
+ $swifthome = $parent_directory;
+ }
+
+ else {
+ @path = split( '/', which("swift") );
+ @path = splice( @path, 0, $#path - 1 );
+ my $tmp = join( '/', @path );
+ if ( -e "$tmp/bin/swift" ) {
+ $swifthome = $tmp;
+ }
+ }
+}
+
+# Create a new directory if it does not exist
+sub create_directory {
+ $directory = $_[0];
+ if ( !-d "$directory" ) {
+ mkdir "$directory", 0700
+ or die "Unable to create directory $directory\n";
+ }
+}
+
+# Append one file to another
+sub cat_file {
+ my ($src, $dst) = @_;
+ if(-e $dst){ open(DSTFILE, ">>$dst") or die "Unable to open $dst for append\n"; }
+ else { open(DSTFILE, ">$dst") or die "Unable to open $dst for writing\n"; }
+ open(SRCFILE, $src) || die "Unable to open $src for reading\n";
+ foreach $line(<SRCFILE>) {
+ print DSTFILE $line;
+ }
+}
+
+# Copy a file to a new location
+sub copy_file {
+ my ($src, $dst) = @_;
+ if(!-e $src) { die "Unable to access $src\n"; }
+ if(!-e $dst) { die "Unable to access $dst\n"; }
+ copy($src, $dst) or die "Unable to copy $src to $dst\n";
+}
+
+# Strip directory name out of script
+sub strip_directory {
+ my ($fullpath) = @_;
+ my @path = split( '/', $fullpath);
+ my $filename = @path[$#path];
+ 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;
+
+GetOptions(
+ 'site=s' => \$site,
+ 'script=s' => \$script,
+);
+
+# Verify user-created profile info exists
+my ($seconds, $minutes, $hours, $days, $months, $years, @junk) = localtime(time);
+$datestring = sprintf "%04s%02s%02s%02s%02s%02s%s", $years+1900, $months+1, $days, $hours, $minutes, $seconds, getpgrp(0);
+my $dotswift = "$ENV{'HOME'}/.swift";
+
+
+# Run job
+ at 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");
+
+# Temporarily rename existing auth.defaults
+if(-e "$ENV{'HOME'}/.ssh/auth.defaults") {
+ move("$ENV{'HOME'}/.ssh/auth.defaults", "$ENV{'HOME'}/.ssh/auth.defaults.$datestring") || die "Unable to rename $ENV{'HOME'}/.ssh/auth.defaults";
+}
+
+foreach my $s(@sites) {
+ if(!-d "$dotswift/sites/$s"){ print "$dotswift/sites/$site\n"; die "Unable to find entry for $s\n"; }
+ if(!-e "$dotswift/sites/$s/sites.xml"){ die "Unable to find sites.xml for $s\n"; }
+ if(!-e "$dotswift/sites/$s/tc.data"){ die "Unable to find tc.data for $s\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");
+ if(-e "$dotswift/sites/$s/auth.defaults"){
+ cat_file("$dotswift/sites/$s/auth.defaults", "$ENV{'HOME'}/.ssh/auth.defaults");
+ }
+}
+
+# Rename auths.default back to original
+if(-e "$ENV{'HOME'}/.ssh/auth.defaults.$datestring") {
+ move("$ENV{'HOME'}/.ssh/auth.defaults.$datestring", "$ENV{'HOME'}/.ssh/auth.defaults") || die "Unable to rename $ENV{'HOME'}/.ssh/auth.defaults.$datestring";
+}
+
+# Update XML tags
+open(SITEFILE, "$dotswift/jobs/$script_filename/$datestring/sites.xml") || die "Unable to open $dotswift/jobs/$script_filename/$datestring/sites.xml\n";
+my @sitedata = <SITEFILE>;
+close(SITEFILE);
+open(SITEFILE, ">$dotswift/jobs/$script_filename/$datestring/sites.xml") || die "Unable to open $dotswift/jobs/$script_filename/$datestring/sites.xml\n";
+print SITEFILE "<config>\n at sitedata</config>\n";
+close(SITEFILE);
+
+# Run swift
+chdir("$dotswift/jobs/$script_filename/$datestring") || die "Unable to change directories to $dotswift/job/$script_filename/$datestring\n";
+print "Submitting job. Check $dotswift/jobs/$script_filename/$datestring for details\n";
+system("swift -sites.file $dotswift/jobs/$script_filename/$datestring/sites.xml -tc.file $dotswift/jobs/$script_filename/$datestring/tc.data $script");
+
Property changes on: usertools/swift/swiftconfig/bin/swiftrun
___________________________________________________________________
Name: svn:executable
+ *
More information about the Swift-commit
mailing list