Internal Users

Related Links

University Links

How To Write A Wrapper

This page contains pseudocode and source code for the two types of wrapper: "individual page" and "collection of pages". There is enough information here to help you create your own wrappers. Simply copy an existing template and modify it to your needs.

Pseudocode for build_staff_page wrapper

BEGIN
  Read command line arguments (uid, year, template filename, filename for 
    external version of page, filename for local version of page)
  If command line arguments incorrect, print a usage message and finish

  Open connection to database (CAS)
  Get details on the member of staff specified at the command line
  If there are no details of that person that print an error message and finish
  Go through every line of the specified template and deal with $exec{}
  Get remaining details of that person from CAS (research groups, tutee list, 
    classes supervised, lectures given, responsibilities taken)

  Insert staff member details into template
  Localise the file and clean (remove #external..#endexternal). Store as new array
  Externalise the file and clean (remove #local..#endlocal). Store as new array
  Save localised and externalised copies of the filled in template.
  Close connection to database (CAS)
END

    

Source code for build_staff_page wrapper

        
#!./ingperl

# Note the use of relative pathame for ingperl. The current version/installation
# is broken and doesn't like absolute pathnames

require "/home/cur/atp/cc18-www/lib/CAS_functions.pl";
require "/home/cur/atp/cc18-www/lib/template_functions.pl";
 
$uid = $ARGV[0];
$year = $ARGV[1];
$template_file = $ARGV[2];
$external_file = $ARGV[3];
$internal_file = $ARGV[4];

if (!$uid || !$year || !$template_file || !$external_file || !$internal_file) {
  die("Usage: build_staff_page uid year template_file external_file internal_file\n\n");
}

&CAS_open_connection;
# Check to see if this there a person matching the given uid 
%data = &CAS_get_staff_info($uid);

# Got all the data we need!
# Check if we have a match first
if ($data{uid}) {
  open(FILE, "$template_file") || die ("Can't find template file $template_file\n\n");
  @file_contents = <FILE>;

  # Run exec first, so that $exec{} doesn't get lost in replacement
  @file_contents = &run_exec(@file_contents);

  $data{groups} = &CAS_get_staff_research_groups($uid);
  $data{tutees} = &CAS_get_tutees($uid);
  $data{supervisions} = &CAS_get_supervisions($uid, $year);
  $data{lectureships} = &CAS_get_lectureships($uid, $year);
  $data{responsibilities} = &CAS_get_responsibilities($uid, $year);

  # We've got all the data we need. Now do the replacment
  # Remember that %data is global
  @file_contents = &replace(@file_contents);   

  #Localise the file and clean (remove #external..#endexternal)
  @localised_file_contents = &localise(@file_contents);
  @localised_file_contents = &clean(@localised_file_contents);
  @localised_file_contents = &replace_local_path(1, @localised_file_contents);
  
  #Externalise the file and clean (remove #local..#endlocal)
  @externalised_file_contents = &externalise(@file_contents);
  @externalised_file_contents = &clean(@externalised_file_contents);
  @externalised_file_contents = &replace_local_path(0, @externalised_file_contents);

  # Finished; now save to file
  # Start with external file
  &write_file($external_file, @externalised_file_contents);

  # Now save internal (localised) file
  &write_file($internal_file, @localised_file_contents);

} else {
  print "No match found on \"$ARGV[0]\"";
}

&CAS_close_connection;
exit;

    

Pseudocode for build_staff_page wrapper

BEGIN
  Read command line arguments (year, department)
  If command line arguments incorrect, print a usage message and finish  

  Open connection to database (CAS)
  Get list of staff member logins
  Close connection to database (CAS)

  Print list of staff member logins
  Print start time index

  For every login in the list:
    - Print login
    - Check to see if use has a ~/.staff.template
    - Call build_staff_page wrapper with arguments: login, year, name of 
      template (either default, or ~/.staff.template), filename for 
      external version of page, filename for local version of page
    
  Print finish time index
END
    

Source code for build_all_staff_pages wrapper


#!./ingperl

# Note the use of relative pathame for ingperl. The current version/installation
# is broken and doesn't like absolute pathnames

require "/home/cur/atp/cc18-www/lib/CAS_functions.pl";

$year = $ARGV[0];
$department = $ARGV[1];

# Check ARGV[2] to make sure department has been entered between quotes
if (!$year || !$department || $ARGV[2]) {
  die("Usage: build_all_staff_pages year \"department_name\"\n\n");
}

&CAS_open_connection;
@staff = &CAS_get_staff_logins("$department");
&CAS_close_connection;

print "Got ", $#staff+1, " staff members for \"$department\": \n";
print "@staff\n\n";

print "Start time index: ",  `date`, "\n\n";

foreach $login (@staff) {
  print "\nBuilding $login from staff template...";

  # First check for user-tailored template
  if (-e "/home/cur/$login/.staff.template") {
    # User has their own template. Use that
    print "Tailoring...\n";
    system("build_staff_page $login $year /home/cur/$login/.staff.template \
      ../httpd/docs/people/staff/$login.html \
      ../httpd/docs/local-only/people/staff/$login.html");
  } else {
    # Use default template
    print "Using default template...\n";
    system("build_staff_page $login $year ../templates/staff.template \
      ../httpd/docs/people/staff/$login.html 
      ../httpd/docs/local-only/people/staff/$login.html");
  }
}
print "\nDone.\n\n";

print "Finish time index: ",  `date`, "\n\n";

    



 UKC Department Search Research Courses Publications