]> xenbits.xensource.com Git - people/iwj/colo-for-testing.git/commitdiff
convert-cabinet-layout: csv abstract, wip
authorIan Jackson <ian.jackson@eu.citrix.com>
Mon, 9 Mar 2015 18:07:45 +0000 (18:07 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 9 Mar 2015 18:07:45 +0000 (18:07 +0000)
convert-cabinet-layout

index 7b3277fae0c1a511fbb0f657467dea6790b4206c..cbd04ee28e576f4d265001e9dfb33555c4cc8816 100755 (executable)
@@ -3,8 +3,10 @@
 # * "Save as" the file "COLO Cabinet Layout.*" as .csv with the default
 #   settings from LibreOffice Calc, generating "COLO Cabinet Layout.csv"
 #
+# * Likewise for "selections.ods"
+#
 # * Run
-#      ./convert-cabinet-layout "COLO Cabinet Layout.csv";
+#      ./convert-cabinet-layout "COLO Cabinet Layout.csv" "selections.csv";
 #
 # * Paste the output in appropriate places
 #
@@ -55,15 +57,25 @@ while (@ARGV && $ARGV[0] =~ m/^-/) {
 
 die unless @ARGV==1;
 
-our $inputfile = shift @ARGV;
+our ($csv,$csv_fh);
 
-my $csv = Text::CSV->new or die $!;
+sub csv_start ($) {
+    my ($inputfile) = @_;
+    $csv = Text::CSV->new or die $!;
+    $csv_fh = new IO::File $inputfile, "<:encoding(utf8)"
+        or die "$inputfile $!";
+    my $headings = $csv->getline($csv_fh);
+    die $! unless $headings;
+    $csv->column_names($headings);
+}
 
-my $fh = new IO::File $inputfile, "<:encoding(utf8)" or die "$inputfile $!";
+sub csv_row () {
+    $csv->getline_hr($csv_fh)
+}
 
-my $headings = $csv->getline($fh);
-die $! unless $headings;
-$csv->column_names($headings);
+sub csv_end () {
+    close $csv_fh or die $!;
+}
 
 our $machine;
 
@@ -91,7 +103,9 @@ sub setprop ($$) {
 
 our @machines;
 
-while (my $row = $csv->getline_hr($fh)) {
+csv_start($ARGV[0]);
+
+while (my $row = csv_row()) {
     print DEBUG Dumper($row);
 
     $machine = $row->{'Server / Appliance'};
@@ -156,7 +170,7 @@ if (@flags) {
     "./mg-hosts setflags @machines -- @flags\n";
 }
 
-close $fh or die $!;
+csv_end();
 
 foreach my $dest (sort { $dests{$a} <=> $dests{$b} } keys %dests) {
     print "\n#-------------------- $dest --------------------\n" or die $!;