[Swift-commit] r3542 - in usertools/swift/swiftconfig: bin lib/perl

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Mon Aug 16 10:57:42 CDT 2010


Author: davidk
Date: 2010-08-16 10:57:42 -0500 (Mon, 16 Aug 2010)
New Revision: 3542

Modified:
   usertools/swift/swiftconfig/bin/swiftconfig
   usertools/swift/swiftconfig/bin/swiftrun
   usertools/swift/swiftconfig/lib/perl/SwiftConfig.pm
Log:
Application sets per host


Modified: usertools/swift/swiftconfig/bin/swiftconfig
===================================================================
--- usertools/swift/swiftconfig/bin/swiftconfig	2010-08-16 06:56:02 UTC (rev 3541)
+++ usertools/swift/swiftconfig/bin/swiftconfig	2010-08-16 15:57:42 UTC (rev 3542)
@@ -62,7 +62,7 @@
     my $from_directory   = "$template_directory/$option_template";
     my $sites_input_file = "$from_directory/sites.xml";
     if ( !-e "$sites_input_file" ) {
-        die "Unable to find configuration for $sites_input_file\n";
+        die "Unable to find template for $option_template\n";
     }
     my $xml_ref          = update_xml("$sites_input_file", 0, $option_default);
     my $new_sitename     = $xml_ref->{handle};
@@ -84,10 +84,11 @@
     );
     write_file( "$output_directory/sites.xml", $xml_out_ref );
 
-    if ( $option_template ne $new_sitename ) {
-        my $tc_filename = "$output_directory/tc.data";
-        update_tc_hostname( "$tc_filename", $new_sitename );
-    }
+    update_site_applications($new_sitename);
+    #if ( $option_template ne $new_sitename ) {
+    #    my $tc_filename = "$output_directory/tc.data";
+    #    update_tc_hostname( "$tc_filename", $new_sitename );
+    #}
 
     # Handle SSH
     if ( $xml_ref->{execution}{provider} eq 'ssh' ) {
@@ -164,6 +165,8 @@
     );
     write_file( "$output_directory/sites.xml", $xml_out_ref );
 
+    update_site_applications($option_edit);
+    
     # Add/modify/remove ssh entries as needed
     if ( $xml_ref->{execution}{provider} eq 'ssh' ) {
         add_ssh( $xml_ref->{handle}, $xml_ref->{execution}{url} );

Modified: usertools/swift/swiftconfig/bin/swiftrun
===================================================================
--- usertools/swift/swiftconfig/bin/swiftrun	2010-08-16 06:56:02 UTC (rev 3541)
+++ usertools/swift/swiftconfig/bin/swiftrun	2010-08-16 15:57:42 UTC (rev 3542)
@@ -25,8 +25,14 @@
     'help|man'              => sub { pod2usage(-verbose => 2); },
 );
 
+# Check arguments
+initialize_swiftconfig();
+if(!$option_script || !@option_sites) {
+    print "Incorrect usage. Try swiftrun -help\n";
+    exit;
+}
+
 # Create run directory
-initialize_swiftconfig();
 my $script_filename = strip_directory($option_script);
 my $dotswift_directory = "$ENV{'HOME'}/.swift";
 my @run_directories = <run.????>;
@@ -55,8 +61,23 @@
         push(@sites_xml, @current_site_data);
         close(CURRENT_SITE);
         # Add applications
-        my @all_apps = glob("$dotswift_directory/apps/*.apps");
+        my @all_apps;
+        if(-e "$all_site/apps") {
+            open(APPFILE, "$all_site/apps")
+                || die "Unable to open $all_site/apps";
+            @all_apps = <APPFILE>;
+            close(APPFILE);
+            foreach(@all_apps) {
+                chomp($_);
+                $_ = "$dotswift_directory/apps/$_.apps\n";
+            }
+        }
+        else {   
+            @all_apps = glob("$dotswift_directory/apps/*.apps");
+        }
         foreach my $current_app_file(@all_apps) {
+            chomp($current_app_file);
+            print "About to open $current_app_file\n";
             open(CURRENT_APP, $current_app_file) || die "Unable to open app file $current_app_file\n";
             my @current_app_data = <CURRENT_APP>;
             close(CURRENT_APP);
@@ -85,8 +106,22 @@
         my @current_site_data = <CURRENT_SITE>;
         close(CURRENT_SITE);
         push(@sites_xml,  @current_site_data);
+        
         # Add applications
-        my @all_apps = glob("$dotswift_directory/apps/*.apps");
+        my @all_apps;
+        if(-e "$dotswift_directory/sites/$site/apps") {
+            open(APPFILE, "$dotswift_directory/sites/$site/apps")
+                || die "Unable to open $site/apps";
+            @all_apps = <APPFILE>;
+            close(APPFILE);
+            foreach(@all_apps) {
+                chomp($_);
+                $_ = "$dotswift_directory/apps/$_.apps";
+            }
+        }
+        else {   
+            @all_apps = glob("$dotswift_directory/apps/*.apps");
+        }
         foreach my $current_app_file(@all_apps) {
             open(CURRENT_APP, $current_app_file) || die "Unable to open app file $current_app_file\n";
             my @current_app_data = <CURRENT_APP>;

Modified: usertools/swift/swiftconfig/lib/perl/SwiftConfig.pm
===================================================================
--- usertools/swift/swiftconfig/lib/perl/SwiftConfig.pm	2010-08-16 06:56:02 UTC (rev 3541)
+++ usertools/swift/swiftconfig/lib/perl/SwiftConfig.pm	2010-08-16 15:57:42 UTC (rev 3542)
@@ -21,7 +21,7 @@
 our @EXPORT = qw(create_directory get_entry add_ssh remove_ssh 
 update_tc_hostname update_xml write_file print_directory strip_directory
 copy_file cat_file add_application edit_application remove_application
-list_applications initialize_swiftconfig
+list_applications initialize_swiftconfig update_site_applications
 );
 our $VERSION = '0.01';
 
@@ -546,6 +546,50 @@
     }
 }
 
+sub update_site_applications {
+    my ($site) = @_;
+    my $apps = '';
+    
+    if(! -d "$ENV{'HOME'}/.swift/sites/$site") {
+        print "Unable to find configuration for $site\n";
+        return;
+    }
+    
+    if(-e "$ENV{'HOME'}/.swift/sites/apps") {
+        open(APPLIST, "$ENV{'HOME'}/.swift/sites/apps")
+            || die "Unable to open app list $ENV{'HOME'}/.swift/sites/apps";
+        my @apps_file_data = <APPLIST>;
+        close(APPLIST);
+        foreach my $current_app (@apps_file_data) {
+            if($apps) { 
+                $apps = "$apps $current_app";
+            }
+            else {
+                $apps = "$current_app";
+            }
+       }       
+    }
+    
+    my @all_available_appsets = glob("$ENV{'HOME'}/.swift/apps/*.apps");
+    print "Available application sets are: ";
+    foreach(@all_available_appsets) {
+        $_ = strip_directory($_);
+        ($_, my $junk) = split('\.');
+        print "$_ ";
+    }
+    print "\n";
+    
+    print "Enter applications sets for $site: ";
+    $apps = <STDIN>;
+    chomp($apps);
+    my @all_list = split(/ /, $apps);
+    open(APPFILE, ">$ENV{'HOME'}/.swift/sites/$site/apps")
+        || die "Unable to open $ENV{'HOME'}/.swift/sites/$site/apps for writing!\n";
+    foreach(@all_list) {
+        print APPFILE "$_\n";
+    }
+    close(APPFILE);
+}
 1;
 __END__
 




More information about the Swift-commit mailing list