| … | |
… | |
| 34 | our $COURSENAME = $WebworkWebservice::COURSENAME; |
34 | our $COURSENAME = $WebworkWebservice::COURSENAME; |
| 35 | our $HOST_NAME = $WebworkWebservice::HOST_NAME; |
35 | our $HOST_NAME = $WebworkWebservice::HOST_NAME; |
| 36 | our $PASSWORD = $WebworkWebservice::PASSWORD; |
36 | our $PASSWORD = $WebworkWebservice::PASSWORD; |
| 37 | our $ce = WeBWorK::CourseEnvironment->new($WW_DIRECTORY, "", "", $COURSENAME); |
37 | our $ce = WeBWorK::CourseEnvironment->new($WW_DIRECTORY, "", "", $COURSENAME); |
| 38 | #warn "library ce \n ", WebworkWebservice::pretty_print_rh($ce); |
38 | #warn "library ce \n ", WebworkWebservice::pretty_print_rh($ce); |
| 39 | warn "LibraryActions is ready"; |
39 | #warn "LibraryActions is ready"; |
| 40 | |
40 | |
| 41 | ############################################## |
41 | ############################################## |
| 42 | # Obtain basic information about local libraries |
42 | # Obtain basic information about local libraries |
| 43 | ############################################## |
43 | ############################################## |
| 44 | my %prob_libs = %{$ce->{courseFiles}->{problibs} }; |
44 | my %prob_libs = %{$ce->{courseFiles}->{problibs} }; |
| 45 | |
45 | |
| 46 | warn pretty_print_rh(\%prob_libs); |
46 | #warn pretty_print_rh(\%prob_libs); |
| 47 | # replace library names with full paths |
47 | # replace library names with full paths |
| 48 | |
48 | |
| 49 | my $templateDir = $ce->{courseDirs}->{templates}; |
49 | my $templateDir = $ce->{courseDirs}->{templates}; |
| 50 | # warn "template Directory is $templateDir"; |
50 | # warn "template Directory is $templateDir"; |
| 51 | foreach my $key (keys %prob_libs) { |
51 | foreach my $key (keys %prob_libs) { |
| … | |
… | |
| 108 | $dirPath = $prob_libs{$rh->{library_name}} ; |
108 | $dirPath = $prob_libs{$rh->{library_name}} ; |
| 109 | } else { |
109 | } else { |
| 110 | $out->{error} = "Could not find library:".$rh->{library_name}.":"; |
110 | $out->{error} = "Could not find library:".$rh->{library_name}.":"; |
| 111 | return($out); |
111 | return($out); |
| 112 | } |
112 | } |
| 113 | warn "library directory path is $dirPath"; |
113 | #warn "library directory path is $dirPath"; |
| 114 | my @outListLib; |
114 | my @outListLib; |
| 115 | my $wanted = sub { |
115 | my $wanted = sub { |
| 116 | my $name = $File::Find::name; |
116 | my $name = $File::Find::name; |
| 117 | my @out=(); |
117 | my @out=(); |
| 118 | if ($name =~/\S/ ) { |
118 | if ($name =~/\S/ ) { |
| … | |
… | |
| 123 | } |
123 | } |
| 124 | }; |
124 | }; |
| 125 | |
125 | |
| 126 | my $command = $rh->{command}; |
126 | my $command = $rh->{command}; |
| 127 | $command = 'all' unless defined($command); |
127 | $command = 'all' unless defined($command); |
| 128 | $command eq 'all' && do {print "$dirPath\n\n"; |
128 | $command eq 'all' && do {#print "$dirPath\n\n"; |
| 129 | find($wanted, $dirPath); |
129 | find($wanted, $dirPath); |
| 130 | @outListLib = sort @outListLib; |
130 | @outListLib = sort @outListLib; |
| 131 | $out->{ra_out} = \@outListLib; |
131 | $out->{ra_out} = \@outListLib; |
| 132 | $out->{text} = join("\n", @outListLib); |
132 | $out->{text} = join("\n", @outListLib); |
| 133 | return($out); |
133 | return($out); |
| … | |
… | |
| 146 | } |
146 | } |
| 147 | return($out); |
147 | return($out); |
| 148 | }; |
148 | }; |
| 149 | |
149 | |
| 150 | $command eq 'listSet' && do {@outListLib=(); |
150 | $command eq 'listSet' && do {@outListLib=(); |
|
|
151 | my $separator = ($dirPath =~m|/$|) ?'' : '/'; |
| 151 | my $dirPath2 = $dirPath . $rh->{set}; |
152 | my $dirPath2 = $dirPath . $separator . $rh->{set}; |
| 152 | |
153 | |
| 153 | if ( -e $dirPath2) { |
154 | if ( -e $dirPath2) { |
| 154 | find($wanted, $dirPath2); |
155 | find($wanted, $dirPath2); |
| 155 | $out ->{text} = join("\n", sort @outListLib ); |
156 | $out ->{text} = join("\n", sort @outListLib ); |
| 156 | } else { |
157 | } else { |
| 157 | $out->{error} = "Can't open directory $dirPath2"; |
158 | $out->{error} = "Can't open directory $dirPath2"; |
| 158 | } |
159 | } |
| 159 | return($out); |
160 | return($out); |
| 160 | |
161 | |
| 161 | }; |
162 | }; |
| 162 | # else |
163 | # else |