[LON-CAPA-cvs] cvs: modules /albertel/cse101 assignmass_role.pl

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sun, 26 Aug 2007 08:51:27 -0000


raeburn		Sun Aug 26 04:51:27 2007 EDT

  Modified files:              
    /modules/albertel/cse101	assignmass_role.pl 
  Log:
  - adding a cmdline option interface
  
  
Index: modules/albertel/cse101/assignmass_role.pl
diff -u modules/albertel/cse101/assignmass_role.pl:1.1 modules/albertel/cse101/assignmass_role.pl:1.2
--- modules/albertel/cse101/assignmass_role.pl:1.1	Thu May 10 16:04:31 2007
+++ modules/albertel/cse101/assignmass_role.pl	Sun Aug 26 04:51:25 2007
@@ -4,10 +4,34 @@
 use Apache::longroup();
 use Apache::loncommon();
 use Date::Manip;
+use Getopt::Long;
 
+my ($file,$course_url,$test,$quiet,$help);
+GetOptions("file=s"   => \$file,
+           "course=s" => \$course_url,
+           "test"     => \$test,
+           "quiet"    => \$quiet,
+           "help"     => \$help);
+
+if (!-e $file || $help) {
+    die("Usage is $0 --file=<filename> --course=<course url> <--test>");
+}
+
+my %course_info = 
+    &Apache::lonnet::coursedescription($course_url, {'one_time' => 1});
+
+if (!exists($course_info{'description'})) {
+    die("Usage is $0 --file=<filename> --course=<course url> <--test>
+         Unable to find requested course $course_url");
+    
+}
+
+print("Doing course $course_info{'description'}\n");
 my @data;
-open(DATA,'<ss07_role_assignments.csv');
-while(my $line = <DATA>) {
+open(my $fh ,'<', $file);
+my $headers = <$fh>;
+
+while(my $line = <$fh>) {
     chomp($line);
     my @array = map { $_=~s/\"//g;$_ } (split(',',$line));
     $array[3] =~ tr{-}{/};
@@ -17,7 +41,6 @@
 $env{'allowed.ccr'} = 'F';
 $env{'allowed.mdg'} = 'F';
 
-my $course_url = '/msu/9x15968462088459fmsul1';
 my $start_date = time();
 foreach my $line (@data) {
     my ($user,$section,$role,$end_date) = @{ $line };
@@ -31,6 +54,15 @@
 	print("Skipping ($user,$section,$role,$end_date)\n");
 	next;
     }
+    if ($test && !$quiet) {
+	print("
+Would modify $user:msu (on $home)
+Course $url
+For role /msu/josmith/$role  starting ".localtime($start_date)." Ending ".localtime($end_date)."
+");
+    }
+    next if ($test);
+
     my $result =
 	&Apache::lonnet::assigncustomrole('msu',$user,$url,'msu','josmith',
 					  $role,$end_date,$start_date,undef);