File:
[LON-CAPA] /
loncom /
debugging_tools /
seed_accesscount.pl
Revision
1.5:
download - view:
text,
annotated -
select for diffs
Tue Jun 27 15:21:46 2006 UTC (18 years, 2 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_X,
version_2_2_99_1,
version_2_2_99_0,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
bz6209-base,
bz6209,
bz5969,
bz2851,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
- morph to use LONCAPA.pm
1: #!/usr/bin/perl -w
2: #
3: # The LearningOnline Network
4: #
5: # $Id: seed_accesscount.pl,v 1.5 2006/06/27 15:21:46 albertel Exp $
6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29: #################################################
30: use strict;
31: use Getopt::Long;
32: use GDBM_File;
33: use lib '/home/httpd/lib/perl/';
34: use LONCAPA;
35:
36: #
37: # Options
38: my ($verbose,$help) = (0);
39: GetOptions("v" => \$verbose,
40: "help" => \$help);
41:
42: #
43: # Help them out if they ask for it
44: if ($help) {
45: print <<END;
46: seed_accesscount.pl
47: END
48: exit;
49: }
50:
51: #
52: # Loop through ARGV getting files.
53: $|=1;
54: while (my $resDBname = shift()) {
55: my ($path) = ($resDBname =~ /^(.*)nohist_resevaldata.db$/);
56: print STDERR $path.$/;
57: my $resevalDB = &LONCAPA::locking_hash_tie($resDBname,&GDBM_READER());
58: if (! $resevalDB) {
59: warn "Unable to tie to $resDBname";
60: next;
61: }
62: &LONCAPA::push_locking_hash_tie();
63: #
64: my $accessDBname = $path.'nohist_accesscount.db';
65: my $accessDB = &LONCAPA::locking_hash_tie($accessDBname,&GDBM_WRCREAT());
66: if (! $accessDB) {
67: warn "Unable to tie to $accessDBname";
68: next;
69: }
70: #
71: my @Keys;
72: my ($basekey,$value);
73: #
74: $! = 0;
75: while (eval('($basekey,$value) = each(%{$resevalDB});')) {
76: if ($!) {
77: print STDERR $1.$/;
78: $!=0;
79: }
80: my $key = &unescape($basekey);
81: my $src;
82: next if (! ((undef,$src) = ($key =~ /^(.*)___(.*)___count/)));
83: my $value = &unescape($value);
84: $src = &escape($src);
85: if (exists($accessDB->{$src})) {
86: $accessDB->{$src}+=$value;
87: } else {
88: $accessDB->{$src}=$value;
89: }
90: push (@Keys,$basekey);
91: }
92: #
93: &LONCAPA::locking_hash_untie($accessDB);
94: &LONCAPA::pop_locking_hash_tie();
95: &LONCAPA::locking_hash_untie($resevalDB);
96: system("chown www:www $accessDBname");
97: # remove the keys we saved.
98: next if (! scalar(@Keys)); # skip it if we did not get anything...
99: my $dbptr = &LONCAPA::locking_hash_tie($resDBname,&GDBM_READER());
100: if (! $dbptr ) {
101: die "Unable to re-tie to $resDBname. No deletes occured.";
102: }
103: foreach my $basekey (@Keys) {
104: delete($resevalDB->{$basekey});
105: }
106: # Squish the file down
107: &LONCAPA::locking_hash_untie($resevalDB);
108: system("chown www:www $resDBname");
109: }
110: exit;
111:
112: ######################################
113:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>