[LON-CAPA-cvs] cvs: modules /gerd/ct convert.pl

www lon-capa-cvs@mail.lon-capa.org
Thu, 22 Sep 2005 15:13:32 -0000


www		Thu Sep 22 11:13:32 2005 EDT

  Modified files:              
    /modules/gerd/ct	convert.pl 
  Log:
  Writes meta files and generates custom distribution files.
  
  
Index: modules/gerd/ct/convert.pl
diff -u modules/gerd/ct/convert.pl:1.5 modules/gerd/ct/convert.pl:1.6
--- modules/gerd/ct/convert.pl:1.5	Thu Sep 22 10:20:25 2005
+++ modules/gerd/ct/convert.pl	Thu Sep 22 11:13:31 2005
@@ -9,6 +9,7 @@
 my @CTChoices;
 my @Image;
 my @ConceptTestType;
+my @CTCopyright;
 open(IN,'ct.sql');
 while (my $line=<IN>) {
     if ($line=~/^INSERT INTO (\w+) VALUES \((\d+)\,(.*)\)\;$/) {
@@ -32,6 +33,14 @@
     }
 }
 close(IN);
+open(IN,'folders/CTCopyright.csv');
+while (my $line=<IN>) {
+    chomp($line);
+    chomp($line);
+    unless ($line=~/^(\d+)\,/) { next; }
+    $CTCopyright[$1]=$line;
+}
+close(IN);
 for (my $i=0;$i<=$#ConceptTest;$i++) {
     if ($ConceptTest[$i]=~/\w+/) {
         @needtoget=();
@@ -105,9 +114,34 @@
 	    }
             system("cd $path; wget $url");
             unless (-e "$path/$relative") {
-		print "\nWarning: Could not get $path/$relative";
+		print "\n\n----\nWarning: Could not get $path/$relative\n----\n\n";
             }
         }
+# produce the metafile
+        my $meta='';
+        my ($dummy,$dummy2,$copyid,$author,$email,$inst,$year)=split(/\,/,$CTCopyright[$i]);
+        $year=~s/\W//gs;
+        if ($author) {
+	    my $customrights=$author.$copyid;
+	    $customrights=~s/\W//g;
+	    open (OUT,">cts/$customrights.rights");
+	    print OUT '<accessrule effect="deny" realm="" role="" />'."\n";
+	    close(OUT);
+            $meta.='<author>'.$author.'</author>'."\n".
+            '<copyright>custom</copyright>'."\n".
+            "<customdistributionfile>/res/harvard/cts/$customrights.rights</customdistributionfile>\n";
+	} else {
+	    $meta.="<copyright>default</copyright>\n";
+	}
+        $meta.='<notes>';
+        if ($inst) { $meta.=$inst.", "; }
+        if ($year) { $meta.=$year.", "; }
+        if ($email) { $meta.=$email.", "; }
+        $meta=~s/\, $//;
+        $meta.="</notes>\n";
+        open(OUT,">$path/cts$i.problem.meta");
+        print OUT $meta;
+        close(OUT);
     }
 }