[LON-CAPA-cvs] cvs: loncom /debugging_tools activity_to_accesscount.pl
albertel
lon-capa-cvs@mail.lon-capa.org
Tue, 27 Jun 2006 15:01:15 -0000
albertel Tue Jun 27 11:01:15 2006 EDT
Modified files:
/loncom/debugging_tools activity_to_accesscount.pl
Log:
- morph to LONCAPA.pm
Index: loncom/debugging_tools/activity_to_accesscount.pl
diff -u loncom/debugging_tools/activity_to_accesscount.pl:1.3 loncom/debugging_tools/activity_to_accesscount.pl:1.4
--- loncom/debugging_tools/activity_to_accesscount.pl:1.3 Fri Nov 14 15:42:34 2003
+++ loncom/debugging_tools/activity_to_accesscount.pl Tue Jun 27 11:01:14 2006
@@ -2,18 +2,8 @@
#
use strict;
use GDBM_File;
-
-sub unescape {
- my $str=shift;
- $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
- return $str;
-}
-
-sub escape {
- my $str=shift;
- $str =~ s/(\W)/"%".unpack('H2',$1)/eg;
- return $str;
-}
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
my %resourceaccess;
@@ -22,19 +12,19 @@
my $target = $ARGV[1];
my ($owner) = ($target =~ m:.*/(.*)/nohist_accesscount.db:);
print STDERR "source: $file\ntarget: $target\nowner: $owner\n";
- my %accessDB;
my $accesstime = 0;
my $starttime = time;
if (-e $target) {
- if (! tie(%accessDB,'GDBM_File',$target,&GDBM_READER,0640)) {
+ my $accessDB = &LONCAPA::locking_hash_tie($target,&GDBM_READER());
+ if (! $accessDB) {
warn "Unable to tie to $target";
return;
}
#
- if (exists($accessDB{'tabulated '.$file})) {
- $accesstime = $accessDB{'tabulated '.$file};
+ if (exists($accessDB->{'tabulated '.$file})) {
+ $accesstime = $accessDB->{'tabulated '.$file};
}
- untie(%accessDB);
+ &LONCAPA::locking_hash_untie($accessDB);
}
#
my $line;
@@ -84,22 +74,24 @@
}
}
print STDERR 'done. Updating '.$target.$/;
- if (! tie(%accessDB,'GDBM_File',$target,&GDBM_WRCREAT,0640)) {
+
+ my $accessDB = &LONCAPA::locking_hash_tie($target,&GDBM_WRCREAT());
+ if (! $accessDB) {
warn "Unable to open $target to store data".$/;
return;
}
#
while (my ($resource,$count) = each(%resourceaccess)) {
$resource = &escape($resource);
- if (exists($accessDB{$resource})) {
- $accessDB{$resource}+=$count;
+ if (exists($accessDB->{$resource})) {
+ $accessDB->{$resource}+=$count;
} else {
- $accessDB{$resource} = $count;
+ $accessDB->{$resource} = $count;
}
print sprintf("%10.0f",$count).':'.$resource."\n";
}
- $accessDB{'tabulated '.$file} = $starttime;
- untie(%accessDB);
+ $accessDB->{'tabulated '.$file} = $starttime;
+ &LONCAPA::locking_hash_untie($accessDB);
}
main;