Log Message:
-----------
New module for comparing two pg files in webwork. You get both rendered
versions of the files and diffs. This initial version is pretty much
just bare-bones.
Added Files:
-----------
webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor:
Compare.pm
Revision Data
-------------
--- /dev/null
+++ lib/WeBWorK/ContentGenerator/Instructor/Compare.pm
@@ -0,0 +1,136 @@
+########################################################################=
########
+# WeBWorK Online Homework Delivery System
+# Copyright =A9 2000-2003 The WeBWorK Project, http://openwebwork.sf.net=
/
+# $ $
+#=20
+# This program is free software; you can redistribute it and/or modify i=
t under
+# the terms of either: (a) the GNU General Public License as published b=
y the
+# Free Software Foundation; either version 2, or (at your option) any la=
ter
+# version, or (b) the "Artistic License" which comes with this package.
+#=20
+# This program is distributed in the hope that it will be useful, but WI=
THOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or =
FITNESS
+# FOR A PARTICULAR PURPOSE. See either the GNU General Public License o=
r the
+# Artistic License for more details.
+########################################################################=
########
+
+# TODO
+
+# background on rendered parts
+# search for files by regex name
+# get "similar" files by chardiff
+
+package WeBWorK::ContentGenerator::Instructor::Compare;
+use base qw(WeBWorK::ContentGenerator::Instructor);
+
+=3Dhead1 NAME
+
+WeBWorK::ContentGenerator::Instructor::Compare - Compare problems
+
+=3Dcut
+
+use strict;
+use warnings;
+
+use CGI::Pretty qw();
+use WeBWorK::Form;
+use WeBWorK::Utils qw(readDirectory max);
+use WeBWorK::Utils::Tasks qw(renderProblems);
+
+require WeBWorK::Utils::ListingDB;
+
+
+
+#sub pre_header_initialize {
+# my ($self) =3D @_;
+# my $r =3D $self->r;
+#}
+
+sub body {
+ my ($self) =3D @_;
+
+ my $r =3D $self->r;
+ my $ce =3D $r->ce; # course environment
+ my $db =3D $r->db; # database
+ my $j; # garden variety counter
+
+ my $userName =3D $r->param('user');
+
+ my $user =3D $db->getUser($userName); # checked
+ die "record for user $userName (real user) does not exist."
+ unless defined $user;
+
+ ### Check that this is a professor
+ my $authz =3D $r->authz;
+ unless ($authz->hasPermissions($userName, "modify_problem_sets")) {
+ print "User $userName returned " .
+ $authz->hasPermissions($user, "modify_problem_sets") .
+ " for permission";
+ return(CGI::div({class=3D>'ResultsWithError'},
+ CGI::em("You are not authorized to access the Instructor tools.")));
+ }
+
+ my $path1 =3D $r->param('path1') || '';
+ my $path2 =3D $r->param('path2') || '';
+ if ($r->param('clear')) {
+ $path1 =3D '';
+ $path2 =3D '';
+ }
+ my @pathlist =3D ();
+ push @pathlist, $path1 if $path1;
+ push @pathlist, $path2 if $path2;
+ my @rendered =3D renderProblems(r=3D> $r,
+ user =3D> $user,
+ problem_list =3D> \@pathlist,
+ displayMode =3D> 'images');
+
+ ########## Extract information computed in pre_header_initialize
+ print CGI::startform({-method=3D>"POST", -action=3D>$r->uri, -name=3D>'=
mainform'}),
+ $self->hidden_authen_fields;
+ print CGI::p('File 1: ', CGI::textfield(-name=3D>"path1",
+ -default=3D>"$path1",
+ -override=3D>1, -size=3D>90));
+ print CGI::p('File 2: ', CGI::textfield(-name=3D>"path2",
+ -default=3D>"$path2",
+ -override=3D>1, -size=3D>90));
+ print CGI::p(CGI::submit(-name=3D>"show_me",
+ -value=3D>"Show Files"));
+ print CGI::p(CGI::submit(-name=3D>"clear",
+ -value=3D>"Clear"));
+ print CGI::endform(), "\n";
+
+ for $j (@rendered) {
+ print '<hr size=3D"5" color=3D"blue" />';
+ if ($j->{flags}->{error_flag}) {
+ print CGI::p('Error');
+ } else {
+ print $j->{body_text}
+ }
+ }
+ print '<hr size=3D"5" color=3D"blue" />';
+ if (scalar(@pathlist)>1) {
+ print CGI::h2('Diff output');
+ # Here we call diff. Basic version first
+ my $diffout =3D `diff -u $ce->{courseDirs}->{templates}/$pathlist[0] $=
ce->{courseDirs}->{templates}/$pathlist[1]`;
+ print "\n<pre>\n";
+ print $diffout;
+ print "</pre>\n";
+
+ # If you have hdiff installed, you can get colorized diffs
+ #my $diffout =3D `hdiff -t " " -c "File 1" -C "File 2" -N $ce->{course=
Dirs}->{templates}/$pathlist[0] $ce->{courseDirs}->{templates}/$pathlist[=
1]`;
+ #print $diffout;
+ }
+
+ return "";=09
+}
+
+
+=3Dhead1 AUTHOR
+
+Written by John Jones, jj (at) asu.edu.
+
+=3Dcut
+
+
+
+1;
|