Skip to content

Commit

Permalink
Merge pull request #251 from openwebwork/release-2.11
Browse files Browse the repository at this point in the history
Release 2.11 Pull Request
  • Loading branch information
goehle committed Dec 22, 2015
2 parents ec5ba36 + 6d9134a commit 6f19816
Show file tree
Hide file tree
Showing 49 changed files with 1,958 additions and 3,700 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Online Homework Delivery System
Version 2.*

Copyright 2000-2015, The WeBWorK Project
Copyright 2000-2016, The WeBWorK Project
All rights reserved.

This program is free software; you can redistribute it and/or modify
Expand Down
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$PG_VERSION ='2.10';
$PG_COPYRIGHT_YEARS = '1996-2015';
$PG_VERSION ='2.11';
$PG_COPYRIGHT_YEARS = '1996-2016';

1;
54 changes: 39 additions & 15 deletions lib/AnswerHash.pm
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ The answer hash class is guaranteed to contain the following instance variables:
=cut

BEGIN {
be_strict(); # an alias for use strict. This means that all global variable must contain main:: as a prefix.
# main::be_strict(); # an alias for use strict. This means that all global variable must contain main:: as a prefix.

}

Expand Down Expand Up @@ -245,6 +245,23 @@ sub score {
$self->{score}
}

=head4 stringify_hash
Usage: $rh_ans->stringify_hash;
Turns all values in the hash into strings (so they won't cause trouble outside
the safe compartment).
=cut

sub stringify_hash {
my $self = shift;
Parser::Context->current(undef,$self->{correct_value}->context) if $self->{correct_value};
foreach my $key (keys %$self) {
$self->{$key} = "$self->{$key}" if ref($self->{$key});
}
}

# error methods

=head4 throw_error
Expand Down Expand Up @@ -332,16 +349,16 @@ sub error_message {

# error print out method

=head4 pretty_print
Useage: $rh_ans -> pretty_print();
Returns a string containing a representation of the AnswerHash as an HTML table.
=cut

# =head4 pretty_print
#
#
# Useage: $rh_ans -> pretty_print();
#
#
# Returns a string containing a representation of the AnswerHash as an HTML table.
#
# =cut
#
# sub pretty_print {
# my $r_input = shift;
# my $level = shift;
Expand Down Expand Up @@ -503,7 +520,7 @@ sub get_student_answer {
my %answer_options = @_;
my $display_input = $input;
$display_input =~ s/\0/\\0/g; # make null spacings visible
warn "Raw student answer is |$display_input|" if $self->{debug};
eval (q!main::DEBUG_MESSAGE( "Raw student answer is |$display_input|")!) if $self->{debug};
$input = '' unless defined($input);
if (ref($input) =~/AnswerHash/) {
# in this case nothing needs to be done, since the student's answer is already in an answerhash.
Expand Down Expand Up @@ -544,7 +561,7 @@ sub evaluate {
$rh_ans->{error_flag}=undef; #reset the error flags in case
$rh_ans->{done}=undef; #the answer evaluator is called twice

warn "<H3> Answer evaluator information: </H3>\n" if defined($self->{debug}) and $self->{debug}>0;
eval (q!main::DEBUG_MESSAGE( "<H3> Answer evaluator information: </H3>")!) if defined($self->{debug}) and $self->{debug}>0;
$self->print_result_if_debug('pre_filter',$rh_ans);

my @prefilters = @{$self -> {pre_filters}};
Expand Down Expand Up @@ -576,7 +593,8 @@ sub evaluate {
}
$rh_ans = $self->dereference_array_ans($rh_ans);
# make sure that the student answer is not an array so that it is reported correctly in answer section.
warn "<h4>final result: </h4>", $rh_ans->pretty_print() if defined($self->{debug}) and $self->{debug}>0;
eval (q!main::DEBUG_MESSAGE( `<h4>final result: </h4>`, pretty_print($rh_ans,'html'))!)
if defined($self->{debug}) and $self->{debug}>0;
# re-refrence $rh_ans;
$self ->{rh_ans} = $rh_ans;
$rh_ans;
Expand All @@ -586,10 +604,16 @@ sub print_result_if_debug {
my $queue = shift; # the name of the queue we are in
my $rh_ans= shift;
my %options = @_;
unless ( ref($rh_ans) eq 'AnswerHash' ) {
warn "$rh_ans is not an answerHash in queue $queue\n";
return;
}
;
if (defined($self->{debug}) and $self->{debug}>0) {
$rh_ans->{rh_options} = \%options; #include the options in the debug information
my $name = (defined($rh_ans->{_filter_name})) ? $rh_ans->{_filter_name}: 'unnamed';
warn "$count. Result from \"$name\" $queue:", $rh_ans->pretty_print();
eval (q! main::DEBUG_MESSAGE( "\n $count. Result from queue $queue: name: \"$name\"n", pretty_print($rh_ans,'html',4))
!);
++$count;
}
$rh_ans->{_filter_name} = undef;
Expand Down
12 changes: 6 additions & 6 deletions lib/Applet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,9 @@ sub insertHeader {
########################################################

use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
<script src="/webwork2_files/js/legacy/Base64.js" language="javascript">
<script src="/webwork2_files/js/apps/Base64/Base64.js" language="javascript">
</script>
<script src="/webwork2_files/js/legacy/ww_applet_support.js" language="javascript">
<script src="/webwork2_files/js/apps/AppletSupport/ww_applet_support.js" language="javascript">
//upload functions stored in /opt/webwork/webwork2/htdocs/js ...
</script>
Expand Down Expand Up @@ -999,9 +999,9 @@ END_OBJECT_TEXT


use constant CANVAS_OBJECT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
<script src="/webwork2_files/js/legacy/Base64.js" language="javascript">
<script src="/webwork2_files/js/apps/Base64/Base64.js" language="javascript">
</script>
<script src="/webwork2_files/js/legacy/ww_applet_support.js" language="javascript">
<script src="/webwork2_files/js/apps/AppletSupport/ww_applet_support.js" language="javascript">
//upload functions stored in /opt/webwork/webwork2/htdocs/js ...
</script>
Expand Down Expand Up @@ -1097,9 +1097,9 @@ END_OBJECT_TEXT


use constant GEOGEBRAWEB_OBJECT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
<script src="/webwork2_files/js/legacy/Base64.js" language="javascript">
<script src="/webwork2_files/js/apps/Base64/Base64.js" language="javascript">
</script>
<script src="/webwork2_files/js/legacy/ww_applet_support.js" language="javascript">
<script src="/webwork2_files/js/apps/AppletSupport/ww_applet_support.js" language="javascript">
//upload functions stored in /opt/webwork/webwork2/htdocs/js ...
</script>
Expand Down
9 changes: 8 additions & 1 deletion lib/Chromatic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ BEGIN {
package Chromatic;

our $webwork_directory = $WeBWorK::Constants::WEBWORK_DIRECTORY; #'/opt/webwork/webwork2';
our $seed_ce = new WeBWorK::CourseEnvironment({ webwork_dir => $webwork_directory });
# fake course name 'foobar' prevents undefined courseName warnings
# FIXME is there a more efficient way to find the location of the PG directory? Perhaps an ENV variable?
# or a WEBWORK_PG_DIRECTORY variable? -- perhaps not since all of those are in the defaults.config file
# we would have to read that at compile time.

our $seed_ce = new WeBWorK::CourseEnvironment({ webwork_dir => $webwork_directory, courseName =>'foobar'});
die "Can't create seed course environment for webwork in $webwork_directory" unless ref($seed_ce);
our $PGdirectory = $seed_ce->{pg_dir};

# now that we have the PGdirectory we can get to work compiling color
our $command = "$PGdirectory/lib/chromatic/color";
our $compileCommand = "/usr/bin/gcc -O3 -o $PGdirectory/lib/chromatic/color $PGdirectory/lib/chromatic/color.c";
unless (-x $command) {
Expand Down
63 changes: 55 additions & 8 deletions lib/PGUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ sub not_null { # empty arrays, empty hashes and strings containing only w

=head4 pretty_print
Usage: warn pretty_print( $rh_hash_input)
TEXT(pretty_print($ans_hash));
TEXT(pretty_print(~~%envir ));
Usage: warn pretty_print( $rh_hash_input, displayMode, level)
TEXT(pretty_print($ans_hash, displayMode, level));
TEXT(pretty_print(~~%envir, displayMode, level ));
This can be very useful for printing out HTML messages about objects while debugging
Expand All @@ -71,22 +71,24 @@ This can be very useful for printing out HTML messages about objects while debug

sub pretty_print {
my $r_input = shift;
my $displayMode = shift;
my $displayMode = shift//'html'; # default printing style is html
my $level = shift//5 ; # default is 5 levels deep
my $out = '';
if ($displayMode eq 'TeX' ) {
$out .="{\\tiny";
$out .= pretty_print_tex($r_input);
$out .= pretty_print_tex($r_input,$level);
$out .="}";
} elsif ($displayMode eq 'text' ) {
$out = pretty_print_text($r_input, $level);
} else {
$out =pretty_print_html($r_input); #default
$out = pretty_print_html($r_input, $level); #default
}
$out;
}

sub pretty_print_html { # provides html output -- NOT a method
my $r_input = shift;
my $level = shift;
$level = 5 unless defined($level);
$level--;
return "PGalias has too much info. Try \$PG->{PG_alias}->{resource_list}" if ref($r_input) eq 'PGalias'; # PGalias just has too much information
return 'too deep' unless $level > 0; # only print four levels of hashes (safety feature)
Expand Down Expand Up @@ -123,7 +125,6 @@ sub pretty_print_html { # provides html output -- NOT a method
sub pretty_print_tex {
my $r_input = shift;
my $level = shift;
$level = 5 unless defined($level);
$level--;
return "PGalias has too much info. Try \\\$PG->{PG\\_alias}->{resource\\_list}" if ref($r_input) eq 'PGalias'; # PGalias just has too much information
return 'too deep' unless $level>0; #only print four levels of hashes (safety feature)
Expand Down Expand Up @@ -163,4 +164,50 @@ sub pretty_print_tex {
$out;
}

sub pretty_print_text {
my $r_input = shift;
my $level = shift;

$level--;
return "PGalias has too much info. Try \\\$PG->{PG\\_alias}->{resource\\_list}" if ref($r_input) eq 'PGalias'; # PGalias just has too much information
return 'too deep' unless $level>0; #only print four levels of hashes (safety feature)

my $out = "";
my $type = ref($r_input);

if (defined($type) and $type) {
$out .= " type = $type; ";
} elsif (! defined($r_input )) {
$out .= " type = UNDEFINED; ";
}
return $out." " unless defined($r_input);

if ( ref($r_input) =~/HASH/ or "$r_input" =~/HASH/ ) {
$out .= "{\n";
$level++;
foreach my $key (sort keys %{$r_input}) {
$out .= " "x$level."$key => " . pretty_print_text( $r_input->{$key}, $level ) . "\n";
}
$level--;
$out .= "\n"." "x$level."}\n";

} elsif (ref($r_input) =~ /ARRAY/ or "$r_input" =~/ARRAY/) {
$out .= " ( ";
foreach my $elem ( @{$r_input} ) {
$out .= pretty_print_text($elem, $level);

}
$out .= " ) \n";
} elsif ( ref($r_input) =~ /SCALAR/ ) {
$out .= "scalar reference ". ${$r_input};
} elsif ( ref($r_input) =~/Base64/ ) {
$out .= "base64 reference " .$$r_input;
} else {
$out .= $r_input;
}

return $out." ";
}


1;
65 changes: 39 additions & 26 deletions lib/PGalias.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ sub initialize {
$self->{externalGif2EpsPath} = $envir->{externalGif2EpsPath};
$self->{externalPng2EpsPath} = $envir->{externalPng2EpsPath};
$self->{externalGif2PngPath} = $envir->{externalGif2PngPath};
$self->{courseID} = $envir->{courseName};
$self->{courseID} = $envir->{courseName};
$self->{problemSeed} = $envir->{problemSeed};

$self->{appletPath} = $self->{envir}->{pgDirectories}->{appletPath};
#
Expand All @@ -110,13 +111,14 @@ sub initialize {

$self->{ext} = "";

my $unique_id_seed = join("-",
$self->{studentLogin},
$self->{psvn},
$self->{courseID},
'set'.$self->{setNumber},
'prob'.$self->{probNum},
);
my $unique_id_seed = join("-",
$self->{studentLogin},
$self->{psvn},
$self->{courseID},
'set'.$self->{setNumber},
'prob'.$self->{probNum},
$self->{problemSeed}
);

##################################
# Cached vs. uncached uuid's -- or should the uuid be unique to each file/psvn/login, but always the same?
Expand Down Expand Up @@ -158,7 +160,19 @@ sub check_parameters {
warn "htmlURL is not defined." unless $self->{htmlURL};
warn "tempURL is not defined." unless $self->{tempURL};
}

sub make_resource_object {
my $self = shift;
my $aux_file_id =shift;
my $ext = shift;
my $resource = PGresource->new(
$self, #parent alias of resource
$aux_file_id, # resource file name
$ext, # resource type
WARNING_messages => $self->{WARNING_messages}, #connect warning message channels
DEBUG_messages => $self->{DEBUG_messages},
);
return $resource;
}
sub make_alias {
my $self = shift;
my $aux_file_id = shift;
Expand All @@ -168,7 +182,6 @@ sub make_alias {
my $envir = $self->{envir};
my $displayMode = $self->{displayMode};
my $pgFileName = $self->{pgFileName}; # name of .pg file
my $envir = $self->{envir};
my $htmlDirectory = $self->{htmlDirectory};
my $htmlURL = $self->{htmlURL};
my $tempDirectory = $self->{tempDirectory};
Expand Down Expand Up @@ -227,13 +240,12 @@ sub make_alias {
###################################################################
unless ( defined $self->get_resource($aux_file_id.".$ext") ) {
$self->add_resource($aux_file_id.".$ext",
PGresource->new(
$self, #parent alias of resource
$aux_file_id, # resource file name
$ext, # resource type
WARNING_messages => $self->{WARNING_messages}, #connect warning message channels
DEBUG_messages => $self->{DEBUG_messages},
));
$self->make_resource_object(
$aux_file_id, # resource file name
$ext # resource type
)

);

} else {
#$self->debug_message( "found existing resource_object $aux_file_id");
Expand All @@ -251,6 +263,7 @@ sub make_alias {
} elsif ( $ext eq 'gif'
or $ext eq 'jpg'
or $ext eq 'png'
or $ext eq 'pdf'
) {
if ($displayMode =~ /^HTML/ ) {
################################################################################
Expand Down Expand Up @@ -280,14 +293,14 @@ sub make_alias {
die "Error in alias: PGalias.pm: unrecognizable displayMode = $displayMode";
}

} elsif ($ext eq 'pdf') {
if ($displayMode =~/HTML/) {
$self->warning_message("The image $aux_file_id of type pdf cannot yet be displayed in HTML mode");
} elsif ($displayMode eq 'TeX') {
$adr_output=$self->alias_for_image_in_tex_mode($aux_file_id, $ext);
} else {
die "Error in alias: PGalias.pm: unrecognizable displayMode = $displayMode";
}
#} elsif ($ext eq 'pdf') {
# if ($displayMode =~/HTML/) {
# $self->warning_message("The image $aux_file_id of type pdf cannot yet be displayed in HTML mode");
# } elsif ($displayMode eq 'TeX') {
# $adr_output=$self->alias_for_image_in_tex_mode($aux_file_id, $ext);
# } else {
# die "Error in alias: PGalias.pm: unrecognizable displayMode = $displayMode";
# }

} else { # $ext is not recognized
################################################################################
Expand Down Expand Up @@ -909,7 +922,7 @@ sub check_url {
# unless (-x $check_url_command );
my $response = `$check_url_command $url`;
# $self->debug_message("check_url: response for url $url is $response");
return ($response =~ /^$OK_CONSTANT/) ? 1 : 0;
return ($response =~ /$OK_CONSTANT/) ? 1 : 0;
}

# ^variable our %appletCodebaseLocations
Expand Down
Loading

0 comments on commit 6f19816

Please sign in to comment.