/[Search-Estraier]/trunk/scripts/estcp-mt.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

Diff of /trunk/scripts/estcp-mt.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 86 by dpavlin, Thu Jan 19 14:33:33 2006 UTC revision 141 by dpavlin, Wed May 10 14:52:28 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
4  use Search::Estraier;  use Search::Estraier 0.06;
5  use URI::Escape qw/uri_escape/;  use URI::Escape qw/uri_escape/;
6  use Time::HiRes;  use Time::HiRes;
7  use POSIX qw/strftime/;  use POSIX qw/strftime/;
# Line 30  my $from_n = new Search::Estraier::Node( Line 30  my $from_n = new Search::Estraier::Node(
30          url => $from,          url => $from,
31          croak_on_error => 1,          croak_on_error => 1,
32          debug => $debug,          debug => $debug,
33            user => 'admin',
34            passwd => 'admin',
35  );  );
36  my $to_n = new Search::Estraier::Node(  my $to_n = new Search::Estraier::Node(
37          url => $to,          url => $to,
38          croak_on_error => 1,          croak_on_error => 1,
39          debug => $debug,          debug => $debug,
40            user => 'admin',
41            passwd => 'admin',
42            create => 1,
43            label => $from_n->label,
44  );  );
45    
46  unless(eval{ $to_n->name }) {  unless(eval{ $to_n->name }) {
47          if ($to =~ m#^(http://.+)/node/(\w+)$#) {          if ($to =~ m#^(http://.+)/node/([^/]+)$#) {
48                  my ($url,$name) = ($1,$2);                  my ($url,$name) = ($1,$2);
49                  print "Creating '$name' on $url\n";                  print "Creating '$name' on $url\n";
50                  $to_n->shuttle_url( $url . '/master?action=nodeadd',                  $to_n->shuttle_url( $url . '/master?action=nodeadd',
# Line 59  my $q_drafts = Thread::Queue->new; Line 65  my $q_drafts = Thread::Queue->new;
65    
66  my $get_thr = threads->new( sub {  my $get_thr = threads->new( sub {
67          while (my $id = $q_id->dequeue) {          while (my $id = $q_id->dequeue) {
68                    #warn "get ", $id || 'undef',"\n";
69                    if ($id < 0) {
70                            $q_drafts->enqueue( '' );       # abort put thread
71                            last;
72                    };
73                  print STDERR "get_thr, id: $id\n" if ($debug);                  print STDERR "get_thr, id: $id\n" if ($debug);
74                  my $doc_draft = $from_n->_fetch_doc( id => $id, chomp_resbody => 1 );                  my $doc_draft = $from_n->_fetch_doc( id => $id, chomp_resbody => 1 );
75                  $q_drafts->enqueue( $doc_draft );                  $q_drafts->enqueue( $doc_draft );
# Line 71  my $doc_num = $from_n->doc_num || 1; Line 82  my $doc_num = $from_n->doc_num || 1;
82    
83  my $put_thr = threads->new( sub {  my $put_thr = threads->new( sub {
84          while (my $doc_draft = $q_drafts->dequeue) {          while (my $doc_draft = $q_drafts->dequeue) {
85                    last unless ($doc_draft);
86                  print STDERR "put_thr, $doc_draft\n" if ($debug);                  print STDERR "put_thr, $doc_draft\n" if ($debug);
87                  $to_n->shuttle_url( $to_n->{url} . '/put_doc', 'text/x-estraier-draft', $doc_draft, undef) == 200 or die "can't insert $doc_draft\n";                  $to_n->shuttle_url( $to_n->{url} . '/put_doc', 'text/x-estraier-draft', $doc_draft, undef) == 200 or die "can't insert $doc_draft\n";
88    
# Line 115  while($more) { Line 127  while($more) {
127    
128                  $q_id->enqueue( $id );                  $q_id->enqueue( $id );
129          }          }
130          warn "$prev\n";          warn "$prev\n" if ($debug);
131    
132  }  }
133    $q_id->enqueue( -1 );   # last one
134    
135  $get_thr->join;  $get_thr->join;
136  $put_thr->join;  $put_thr->join;
137    
138  print "Copy completed.\n";  printf "Copy of %d records completed [%1.2f rec/s]\n", $i,
139            ( $i / ((time() - $t) || 1) );
140    

Legend:
Removed from v.86  
changed lines
  Added in v.141

  ViewVC Help
Powered by ViewVC 1.1.26