#!/usr/bin/perl =head1 NAME coursedb-make - generate the annual directories and associated files for lecture-course materials based on data from coursedb.txt =head1 USAGE coursedb-make [options] coursedb.txt [course ...] coursedb-make [options] -a coursedb.txt =head1 SUMMARY Reads the coursedb.txt file and writes to the current working directory the output files uconfig.txt, chown.sh, index-b.html, lecturers-b.html, $class-b.html. It also produces a subdirectory for each course listed, containing an index-b.html and a Makefile, or for all courses if option -a is used instead. =cut use FindBin qw($RealBin); # find directory where this file is located ... use lib '/anfs/www/tools/share/ucampas/perl-PlexTree', $RealBin; use bytes; use strict; use PlexTree; use CourseDB; sub usage() { print STDERR "usage: coursedb-make [options] coursedb.txt [courses ...]\n\n"; print STDERR "For more documentation run: "; print STDERR "perldoc $0\n\n"; exit 1; } my @generated_html = (); # list of files that ucampas needs to postprocess # write a HTML page (open file, add headers, etc.) sub write_htmlpage { my ($fn, $title, $body, %param) = @_; my $f; open($f, '>', $fn) or die("$fn:$!\n"); print $f '' . "\n"; print $f ("\n\n\n") unless $param{'edit'}; print $f '
Please check the official timetables for timetable details.\n"; } foreach my $term (@terms) { push @body, "\n
$synopsis\n" if defined $synopsis; } push @body, "
Please check the official timetables for timetable details.\n"; } foreach my $lecturer ($db->lecturers) { my @courses = $lecturer->teaches; next unless @courses; print $lecturer->fullname . " <" . $lecturer->code . ">\n" if $verbose; push @body, "
');
my @proprietors = $course->proprietors;
if (@proprietors) {
push @data, 'Principal lecturer'.
(@proprietors > 1 ? 's' : '').': ';
push @data, join(', ', map {$_->html} @proprietors);
push @data, "
\n";
}
my @contributors = $course->contributors;
if (@contributors) {
push @data, 'Additional lecturer'.
(@contributors > 1 ? 's' : '').': ';
push @data, join(', ', map {$_->html} @contributors);
push @data, "
\n";
}
push @data, 'Taken by: ' .
join(', ', map { $_->html('../') } $course->classes);
push @data, "
\n";
push @data, 'Code: ' . $course->code . "
\n"
if $course->param('showcode');
my $hours = $course->cd('hours');
if (defined $hours) {
push @data, 'Hours:';
push @data, ' ' . $hours->str_text if $hours->str_text;
push @data, ' (' . $hours->getl(0) . ')' if $hours->listlen;
push @data, "
\n";
}
my $prerequisites = $course->cd('prerequisites');
if (defined $prerequisites) {
push @data, 'Prerequisites: ' . $prerequisites->str_text;
push @data, "
\n";
}
# syllabus link
my $syllabustype = $course->param('syllabus');
if ($syllabustype eq 'latexhtmllink') {
push @data, "Syllabus
\n";
} elsif ($syllabustype eq 'localpdflink') {
push @data, "Syllabus
\n";
}
# past exam questions link
if ($course->param('triposexam')) {
my @examlinks = $course->examlinks;
if (@examlinks == 2) {
push @data, "Past exam questions
\n";
} elsif (@examlinks >= 2) {
my @l;
while (@examlinks) {
my $title = shift @examlinks;
my $url = shift @examlinks;
push @l, "$title";
}
push @data, "Past exam questions: " . join(', ', @l) . "
\n";
} else {
print $course->code . ": no past exam questions!\n";
}
}
# information for supervisors link
if ($course->param('supervisions')) {
push @data, "Information for supervisors ".
"(contact lecturer for access permission)
\n";
}
my $mainpage = 'materials'; # materials | syllabus
$mainpage = 'syllabus' if $syllabustype =~ /include$/;
# syllabus page
if ($syllabustype eq 'htmlinclude' ||
$syllabustype eq 'latexhtmlinclude') {
my $fn="syllabus";
my @body = ();
my $title = $course->title . ' – Syllabus';
if ($mainpage eq 'syllabus') {
push @body, @data;
$fn="index";
$u2->addkey('tabtopinclude' => text 'Syllabus');
$title = $course->title;
} else {
$u2->append((text "$fn.html")->setatt('navtitle' => 'Syllabus'));
}
if ($syllabustype eq 'htmlinclude') {
push @body,
("\n\n");
push @body, "\n
If you are reading this then no extra material has yet been\n".
"placed on the Web for this course.";
push @body, "\n
Last year’s course materials are still available."
if -d "../$shortlastyear/" . $course->code . "/";
push @body, "\n";
# write out the course materials page
write_htmlpage("$cdir/$fn-b.html", $title, \@body,
tabs => 1, h1 => $course->title, edit => 1);
# assessment page
if ($course->param('assessmentpage')) {
my @body = ();
# placeholder
push @body, "\n\n
The course lecturer will provide here shortly information about assessed work for this course, such as exercise/essay/project deadlines, exam dates, etc."; write_htmlpage("$cdir/assessment-b.html", $course->title . ' – Assessment', \@body, tabs => 1, h1 => $course->title, edit => 1); $u2->append((text 'assessment.html')->setatt('navtitle' => 'Assessment')); } # create restricted supervisors subdirectory if ($course->param('supervisions')) { # placeholder body my @body = ( "\n\n
If you are reading this then no extra material has yet been\n".
"placed on the Web for this course.");
my $lastfn = "../$shortlastyear/" . $course->code . "/supervisors/";
push @body, "\n
Last year’s course materials are still available."
if -d $lastfn;
push @body, "\n";
`mkdir -p "$cdir/supervisors"`;
write_htmlpage("$cdir/supervisors/index-b.html",
$course->title . ' – Information for supervisors',
\@body, tabs => 1, h1 => $course->title, edit => 1);
# uconfig.txt
$u2->append((text 'supervisors')->setatt('navtitle' => 'Information for supervisors'));
# supervisors/.htaccess
my @htaccess = (
"# Access control settings for the supervisors subdirectory\n",
"# Documentation: http://www.cl.cam.ac.uk/local/web/htaccess.html\n",
"Order Allow,Deny\n",
"Satisfy Any\n",
"# allow access by Lab members and DoS:\n",
"Require group all-cl-users undergrad-directors-of-studies\n",
"# allow access by other supervisors:\n",
"# (uncomment line below, then edit list of Raven IDs of your supervisors):\n",
"#Require user abc12 def34 gh567\n",
"# allow access by students:\n",
"# (uncomment line below after the end of lectures and supervisions):\n",
"#Require group ". join(' ',
map { "students-" . $_->code .
"-$shortyear" }
$course->classes) ."\n"
);
write_textfile("$cdir/supervisors/.htaccess", @htaccess);
}
# create makefile
write_textfile("$cdir/Makefile",
"%.html: %-b.html\n\t/anfs/www/tools/bin/ucampas \$*\n\n",
"all:\n\t/anfs/www/tools/bin/ucampas -r\n");
# output uconfig.txt
write_textfile("$cdir/uconfig.txt",
$u2->print(oneline => 3, implicitlist => 1))
unless $u2->isempty;
}
# write uconfig.txt file
write_textfile('uconfig.txt',
$u->print(oneline => 3, implicitlist => 1));
push @generated_html, 'index'; # because we may have changed uconfig.txt
system '/anfs/www/tools/bin/ucampas', @generated_html;