[LON-CAPA-cvs] cvs: loncom /thesaurus build_thesaurus_db.pl build_thesaurus_wrapper.sh

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 05 Aug 2003 15:51:37 -0000


matthew		Tue Aug  5 11:51:37 2003 EDT

  Modified files:              
    /loncom/thesaurus	build_thesaurus_db.pl build_thesaurus_wrapper.sh 
  Log:
  Bug 1492: build_thesaurus_db.pl has new command line switch --checkdates
  to only build the thesaurus if the dependencies are newer than the target.
  
  
Index: loncom/thesaurus/build_thesaurus_db.pl
diff -u loncom/thesaurus/build_thesaurus_db.pl:1.1 loncom/thesaurus/build_thesaurus_db.pl:1.2
--- loncom/thesaurus/build_thesaurus_db.pl:1.1	Thu Jul 11 16:48:31 2002
+++ loncom/thesaurus/build_thesaurus_db.pl	Tue Aug  5 11:51:37 2003
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 #
-# $Id: build_thesaurus_db.pl,v 1.1 2002/07/11 20:48:31 matthew Exp $
+# $Id: build_thesaurus_db.pl,v 1.2 2003/08/05 15:51:37 matthew Exp $
 #
 #
 # build_thesaurus_db.pl creates the LON-CAPA thesaurus database.
@@ -124,13 +124,15 @@
 ##
 ## Get command line parameters
 ##
-my ($badwordfile,$outputdbfile,$keywordfile,$help,$test);
+my ($badwordfile,$outputdbfile,$keywordfile,$help,$checkdates,$test);
 GetOptions( "badwordfile=s" => \$badwordfile,   # --badwordfile
             "outputdb=s"    => \$outputdbfile,  # --outputdb
             "keywordfile=s" => \$keywordfile,   # --keywordfile
             "help"          => \$help,          # --help
+            "checkdates"    => \$checkdates,    # --checkdates
             "test"          => \$test);         # --test
 
+
 ##
 ## Help! Help!
 ##
@@ -143,6 +145,9 @@
                                 put in the thesaurus.  Each word must appear
                                 on its own line and currently comments are not
                                 supported.
+   --checkdates                 Check the creation dates on the files involved
+                                and only run if the outputdb file was created
+                                prior to one of the badword or keyword files.
    --keywordfile <filename>     File containing the raw word data for the
                                 thesaurus.  Each line must be comma seperated
                                 list of related keywords.
@@ -169,6 +174,25 @@
 
 foreach my $file ($badwordfile,$keywordfile) {
     die "$file does not exist." if (! -e $file);
+}
+
+#
+# Check the dates on the input files to be sure we need to run
+if ($checkdates && -s $outputdbfile) {
+    my @Results = stat($badwordfile);
+    my $highest_dependency_ctime = $Results[10];
+    foreach ($keywordfile) {
+        if ($Results[10] > $highest_dependency_ctime) {
+            $highest_dependency_ctime = $Results[10];
+        }
+    }
+    #
+    # if the outputdbfile was made AFTER the last version of one of the
+    # dependencies, exit quietly.
+    @Results = stat($outputdbfile);
+    if ($highest_dependency_ctime < $Results[10]) { 
+        exit;
+    }
 }
 
 ##
Index: loncom/thesaurus/build_thesaurus_wrapper.sh
diff -u loncom/thesaurus/build_thesaurus_wrapper.sh:1.2 loncom/thesaurus/build_thesaurus_wrapper.sh:1.3
--- loncom/thesaurus/build_thesaurus_wrapper.sh:1.2	Fri Jul 12 09:39:13 2002
+++ loncom/thesaurus/build_thesaurus_wrapper.sh	Tue Aug  5 11:51:37 2003
@@ -1,3 +1,3 @@
 echo 'Building LON-CAPA thesaurus database (this may take a moment).';
-./build_thesaurus_db.pl --badwordfile un_keyword.tab --keywordfile rawkey.txt --outputdb thesaurus.db
+./build_thesaurus_db.pl --badwordfile un_keyword.tab --keywordfile rawkey.txt --outputdb thesaurus.db --checkdates
 echo 'Completed construction of LON-CAPA thesaurus database.';