/[Sack]/trunk/bin/sack.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/bin/sack.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations)
Mon Sep 21 19:36:32 2009 UTC (14 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 1918 byte(s)
make in-memory cache local

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Time::HiRes qw(time);
7 use Data::Dump qw(dump);
8 use File::Slurp;
9 use Getopt::Long;
10
11
12 my $path = '/data/isi/full.txt';
13 my $limit = 10000;
14 my $offset = 0;
15 my @views;
16
17
18 GetOptions(
19 'path=s' => \$path,
20 'offset=i' => \$offset,
21 'limit=i' => \$limit,
22 'view=s' => \@views,
23 ) or die $!;
24
25 my $t = time;
26
27 use lib '/srv/webpac2/lib/';
28 use WebPAC::Input::ISI;
29 my $input = WebPAC::Input::ISI->new(
30 path => $path,
31 offset => $offset,
32 limit => $limit,
33 );
34
35
36 sub report {
37 my $description = shift;
38 my $dt = time - $t;
39 printf "%s in %1.4fs %.2f/s\n", $description, $dt, $input->size / $dt;
40 }
41
42
43 report $input->size . ' records loaded';
44
45 mkdir 'out' unless -e 'out';
46
47 our $out;
48
49 our $cache;
50
51 sub run_views {
52 @views = sort glob 'views/*.pl' unless @views;
53 warn "# views ", dump @views;
54
55 foreach my $view ( @views ) {
56
57 my ( $nr, $package ) = ( $1, $2 )
58 if $view =~ m{/(\d+)\.([^/]+(\.pl)?$)};
59
60 undef $out;
61
62 next if system("perl -c $view") != 0;
63
64 my $code = read_file $view;
65 warn "## CODE\n$code\n## CODE\n";
66
67 my $affected = 0;
68 $t = time;
69
70 foreach my $pos ( $offset + 1 .. $input->size ) {
71 my $rec = $cache->{$pos} ||= $input->fetch_rec($pos);
72 if ( ! $rec ) {
73 warn "END at $pos";
74 last;
75 }
76
77 eval "$code";
78 if ( $@ ) {
79 warn "ERROR [$pos] $@\n";
80 } else {
81 $affected++;
82 }
83 };
84
85 report "$affected affected records $view";
86
87 if ( defined $out ) {
88 my $dump = dump $out;
89 my $len = length $dump;
90 my $path = "out/$nr.$package";
91 print "out $view $offset/$limit $len bytes $path"
92 , ( $len < 10000 ? " \$out = $dump" : ' SAVED ONLY' )
93 , "\n"
94 ;
95
96 write_file $path, $dump;
97 report "save $path";
98 } else {
99 warn "W: no \$out defined!";
100 }
101
102 }
103 }
104
105 run_views;
106
107 while ( 1 ) {
108
109 print "sack> ";
110 my $cmd = <STDIN>;
111
112 if ( $cmd =~ m{(vi|\\e|out)}i ) {
113 system "vi out/*";
114 } else {
115 run_views;
116 }
117
118 }
119

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26