[LON-CAPA-cvs] cvs: modules /raeburn builddb_fromtext.pl

raeburn raeburn@source.lon-capa.org
Tue, 27 Jan 2009 17:37:49 -0000


raeburn		Tue Jan 27 17:37:49 2009 EDT

  Modified files:              
    /modules/raeburn	builddb_fromtext.pl 
  Log:
  - Additional option to unlink *.db.txt file after conversion to *.db
  - Logging if *.db creation was unsuccessful. 
  
  
Index: modules/raeburn/builddb_fromtext.pl
diff -u modules/raeburn/builddb_fromtext.pl:1.1 modules/raeburn/builddb_fromtext.pl:1.2
--- modules/raeburn/builddb_fromtext.pl:1.1	Tue Jan 27 06:12:44 2009
+++ modules/raeburn/builddb_fromtext.pl	Tue Jan 27 17:37:49 2009
@@ -39,9 +39,10 @@
 
 #
 # Options
-my ($help,$overwrite) = (0,0);
+my ($help,$overwrite,$removetxt) = (0,0,0);
 GetOptions("help"   => \$help,
-           "o"      => \$overwrite);
+           "o"      => \$overwrite,
+           "d"      => \$removetxt);
 
 # Help them out if they ask for it
 if ($help) {
@@ -55,6 +56,7 @@
 Options:
    --help  Display this help.
    -o      Overwrite any existing .db files (instead of renaming to *.db.save) 
+   -d      Delete *.db.txt file after building corresponding *.db file
  
 Examples:
    .\builddb_to_text.pl db_to_text.dat
@@ -103,11 +105,20 @@
                                 $count++;
                             }
                             close($fhin);
-                            &write_hash($dbfile,\%db_to_store);
-                            print $log "Built $dbfile from text - $count key=>value pairs\n"; 
+                            my $result = &write_hash($dbfile,\%db_to_store);
+                            if ($result) {
+                                print $log "Error when creating $dbfile\n";
+                            } else {
+                                print $log "Built $dbfile from text - $count key=>value pairs";
+                                if ($removetxt) {
+                                    unlink($file);
+                                    print $log " - textfile:  $file removed."; 
+                                }
+                                print $log "\n";
+                            }
                         }
                     }
-                } 
+                }
             }
             print $log localtime(time)." Ending creation of db files\n";
             close($log);