/[pub]/suikawiki/script/bin/referer2to3.pl
Suika

Contents of /suikawiki/script/bin/referer2to3.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Sat Apr 17 04:15:17 2004 UTC (20 years, 6 months ago) by wakaba
Branch: MAIN
CVS Tags: suikawiki3-redirect, release-3-0-0, HEAD
Branch point for: paragraph-200404, helowiki, helowiki-2005
Changes since 1.2: +16 -20 lines
File MIME type: text/plain
Use SuikaWiki::DB::FileSystem::Count instead of BerkleyDB tying hash.

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     use Getopt::Long;
4     use lib qw<lib ../lib>;
5     use BerkeleyDB;
6 wakaba 1.3 our $VERSION = do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
7 wakaba 1.1
8     my %opt = (
9     db => q<wikidata>,
10     );
11     GetOptions (
12     'database-dir=s' => \$opt{db},
13     'input-file=s' => \$opt{src},
14 wakaba 1.3 'output-dir=s' => \$opt{output},
15 wakaba 1.1 );
16    
17 wakaba 1.3 $opt{output} ||= $opt{db} . q</page/>;
18 wakaba 1.1 $opt{src} ||= $opt{db} . q</page/mt--52656665726572.dat>;
19    
20     print STDERR "Reading $opt{src}...\n";
21     open my $src, '<', $opt{src} or die "$0: $opt{src}: $!";
22     local $/ = undef;
23    
24     print STDERR "Output: $opt{output}\n";
25 wakaba 1.3 require SuikaWiki::DB::FileSystem::Count;
26     my $out = SuikaWiki::DB::FileSystem::Count->new
27     (base_directory => $opt{output},
28     directory_suffix => '.ns',
29     file_suffix => '.ref',
30     auto_mkdir => 1);
31 wakaba 1.1
32     my $source = scalar <$src>;
33     $source =~ s!^\#\?SuikaWikiMetaInfo/0.9[^\x02]*\x02!!;
34    
35     my $i = 0;
36     for my $old (map {[split /\x1F/, $_, 2]} split /\x1E/, $source) {
37     my $page = [split m#//#, $old->[0]];
38 wakaba 1.3 my $referer = $out->get ('referer', $page);
39 wakaba 1.1 my %newref = split /"/, $old->[1];
40 wakaba 1.2 for (grep {$_} keys %newref) {
41 wakaba 1.3 $referer->{$_} += $newref{$_} if $_ and $newref{$_};
42 wakaba 1.1 }
43 wakaba 1.3 $out->set ('referer', $page => $referer);
44 wakaba 1.1
45     print STDERR '*' unless ++$i % 10;
46     print STDERR "\n" unless $i % 500;
47     }
48    
49     close $src;
50     $out->close;
51    
52     print STDERR "\n";
53    
54     =head1 NAME
55    
56     referer2to3.pl - SuikaWiki: Converting SuikaWiki 2 Referer Database into SuikaWiki 3 Referer Database
57    
58     =head1 SYNOPSIS
59    
60 wakaba 1.3 referer2to3.pl [--database-dir=<dir>] [--input-file=<file>] [--output-dir=<dir>]
61 wakaba 1.1
62     =head1 DESCRIPTION
63    
64     C<referer2to3.pl> converts SuikaWiki 2 referer database into SuikaWiki 3
65     database. SuikaWiki 2 stores received HTTP Referer information
66     into SuikaWikiMetaInfo/0.9 database in wiki database directory.
67     Referer module of SuikaWiki 3 stores them, in default configuration,
68     into BerkeleyDB with different sub-format, so convertion required
69     to upgrade to SuikaWiki 3.
70    
71     This script is part of SuikaWiki.
72    
73     =head1 OPTIONS
74    
75     =over 4
76    
77     =item --database-dir=I<database-dir> (Default: C<./wikidata>)
78    
79     Wiki database directory. This option only used when either
80     C<--input-file> or C<--output-file> option is not specified.
81    
82     =item --input-file=I<file> (Default: C<I<database-dir>/page/mt--52656665726572.dat>)
83    
84     Source (SuikaWiki 2) referer database file.
85    
86 wakaba 1.3 =item --output-dir=I<dir> (Default: C<I<database-dir>/page/>)
87 wakaba 1.1
88 wakaba 1.3 New (SuikaWiki 3 BerkeleyDB) referer database directory.
89 wakaba 1.1
90     =back
91    
92     =head1 SEE ALSO
93    
94     C<SuikaWiki::Plugin>, SuikaWiki:WikiPlugin
95     <http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiPlugin>.
96    
97     =head1 LICENSE
98    
99     Copyright 2004 Wakaba <w@suika.fam.cx>. All rights reserved.
100    
101     This program is free software; you can redistribute it and/or
102     modify it under the same terms as Perl itself.
103    
104     =cut
105    
106 wakaba 1.3 1; # $Date: 2004/03/11 08:06:26 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24