Subject: [LON-CAPA-dev] loncom /automation batchcreatecourse.pm

From: "Stuart Peter Raeburn" <[email-masked]>
Date: Fri, 04 Mar 2005 17:16:35 -0500

Hon Kie, 

First, you should get the latest version of 
loncom/automation/batchcreatecourse.pm (1.3 - recently committed).  You will 
also need a copy of Autocreate.pl, which you should be store in 
/home/httpd/perl, and set to be owned by (and executable by) www. 

This can be retrieved from
http://zaphod.lite.msu.edu/cgi-bin/cvsweb.cgi/loncom/automation/Autocreate.p 
l?rev=1.1;content-type=text%2Fplain

You will also need lonnet.pm v. 1.602 (or later) if you want to run batch 
course creation using Autocreate.pl. Note: this update affects other code 
(e.g., londocs.pm, londefdef.pm, lonuploadrep.pm, lonrep.pm -- see my commit 
to CVS on 3/2 for details).  Furthermore, the changes in this particular 
commit may be partly reversed in future (discussions are currently ongoing 
with Guy). 

The plan is to support batch course creation in two modes.
(a) A DC uploads an XML file containing course descriptions via a web-based 
GUI, and creates the courses.  This will most likely be a modified version 
of the existing /adm/createcourse interface. 

or 

(b) A course request form (which includes authentication and authorization)  
generates the XML files containing course descriptions.  Cron then 
periodically runs Autocreate.pl to process XML files generated by the 
request form.  These files should have been stored in: 
/home/httpd/perl/tmp/addcourse/$dom/pending 

(where $dom is the course domain, e.g., fsu). 

Autocreate.pl takes two arguments: course domain, and username:domain of DC,
and should be run by www.  A suitable cron entry in /etc/cron.d/loncapa 
would be: 

30 * * * *    www    /home/httpd/perl/Autocreate.pl fsu hkng:fsu 

For a multi-domain library server you could have multiple entries (one per 
domain). 

In both (a) and (b) the XML files that contain the course descriptions 
should follow the format described in loncom/automation/batchcreatecourse.pm 

The location of the XML course description files will be as follows 

/home/httpd/perl/tmp/addcourse/$dom/web/$udom_$uname - files uploaded by DC 
$user 

/home/httpd/perl/tmp/addcourse/$dom/auto/pending  - files generated by 
request form 

where $dom is the domain where the course will exist, e.g., fsu, and $uname 
and $udom are the username and domain of the requesting Domain Coordinator. 
(e.g., fsu_hkng). 

In addition you should create a directory (owned by www): 
/home/httpd/perl/tmp/addcourse/$dom/auto/processed 

where XML files in the pending directory will be moved after they have been 
processed by Autocreate.pl 

Although loncreatecourse.pm has not been modified to support mode (a), a 
minimal module to run course creation from the web would be:
/home/httpd/lib/perl/Apache/batchcreate.pm: 

   package Apache::batchcreate;
   use strict;
   use lib '/home/httpd/lib/perl';
   use LONCAPA::batchcreatecourse;
   use Apache::Constants qw(:common);
   use Apache::lonnet;
   use Apache::loncommon

# ================================================================= Handler
sub handler {
   my $r = shift;

   if ($r->header_only) {
      &Apache::loncommon::content_type($r,'text/html');
      $r->send_http_header;
      return OK;
   }

   &Apache::loncommon::content_type($r,'text/html');
   $r->send_http_header;

   if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
       my @requests = readdir($Apache:: # Your array of filenames of course 
description XML files
       my %courseids = ();

       my ($output,$logmsg) = 
&LONCAPA::batchcreatecourse::create_courses(\@requests,\%courseids,'web',$EN 
V{'request.role.domain'},$ENV{'user.name'});

       foreach (keys %courseids) {
           $r->print("course created was $_ <br />");
       }
       $r->print($output);
       $r->print("<br />messages were $logmsg");
   }
   return OK;
}

1; 

This could be activated using the following addition to 
/etc/httpd/conf/loncapa_apache.conf: 

<Location /adm/batchcreate>
PerlAccessHandler       Apache::lonacc
SetHandler perl-script
PerlHandler Apache::batchcreate
ErrorDocument     403 /adm/login
ErrorDocument     406 /adm/roles
ErrorDocument     500 /adm/errorhandler
</Location> 

> Hi Stuart, 
>
> A while back you committed the following on cvs. Is there a way I can try 
> this out? I like to see what I need to do on my end to tie it to the fsu 
> course request form.

> Thanks,
> -hk 
>
>At 10:37 AM 1/30/2005, you wrote:
>>raeburn           Sun Jan 30 10:37:03 2005 EDT 
>>
>>   Added files:
>>     /loncom/automation  batchcreatecourse.pm
>>   Log:
>>   Collection of routines for batch creation of courses from file(s) 
>> containing XML description of courses.  Intended to be called from 
>> command line script, or from a web page by a Domain Coordinator.

---

From: "H. K. Ng" <[email-masked]>
Date: Wed, 09 Mar 2005 15:18:11 -0500

Hi Stuart,

>generates the XML files containing course descriptions.

Is there an existing form where one can try this out. Here at fsu, an 
instructor requests a course from a well established web-site. Currently, 
the instructor has the option to request a BB course or a web-MC course. I 
like to have lon-capa added as one of the option. Now since the instructor 
has to sign in to get to this request form, the username and course or 
courses he/she is teaching will then be passed on to the lon-capa course 
request form. If this form resides on the library server, then the course 
info can be saved directly to /home/httpd/perl/tmp/addcourse/$dom/pending 
after which the Autocreate.pl can take over.

-hk

>_______________________________________________
>LON-CAPA-dev mailing list
>[email-masked]
>http://mail.lon-capa.org/mailman/listinfo/lon-capa-dev

---

From: "H. K. Ng" <[email-masked]>
Date: Fri, 11 Mar 2005 09:44:25 -0500

Hi Stuart,

I had a discussion with the person in charge of putting together the course 
request form for fsu and it looks like the scripts that you have written 
will work without any additional form. Basically, the intend is that 
regardless of which system an instructor chooses to use, he/she login to a 
common web site. Currently, the system automatically checks the user and 
then list the course(s)/sections the person is teaching. So all the front 
end work has already been done.

So question: What is the schedule making the scripts available? I plan to 
start testing it over the summer.

Thanks,
-hk

>>>A while back you committed the following on cvs. Is there a way I can 
>>>try this out? I like to see what I need to do on my end to tie it to the 
>>>fsu course request form.
>>
>>>Thanks,
>>>-hk