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

Stuart Peter Raeburn lon-capa-dev@mail.lon-capa.org
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

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. 


(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: 

(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 

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 

/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): 

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:

   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) {
      return OK;


   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) = 

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


This could be activated using the following addition to 

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

> 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.