Medium sized Internalization made by flattener against megalog-2017-10-28
[andk-cpan-tools.git] / bin / relocate-reports.pl
blob11a4c771293bb01a1f4679c737a9caa2644fbb31
1 #!/usr/bin/perl
3 # use 5.010;
4 use strict;
5 use warnings;
7 =head1 NAME
11 =head1 SYNOPSIS
15 =head1 OPTIONS
17 =over 8
19 =cut
21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
23 =item B<--fromdir=s>
25 =item B<--help|h!>
27 =item B<--todir=s>
29 This help
31 =back
33 =head1 DESCRIPTION
35 Quick oneliner
37 For the record: whatever we pass to ctgetreports as --cachedir will
38 then be populated with two subdirectories, cpantesters-show/ and
39 nntp-testers/
41 So in the past we had one cpantesters-show/ and one nntp-testers/
42 directory and now need tens of thousands of such directories.
44 When this program was written, we did it wrongly because the above
45 knowledge was lost.
47 So after the first iteration we have
49 top-cachedir/nntp-testers/a/autobox-2.55/
51 But what we wanted was
53 top-cachedir/a/autobox-2.55/nntp-testers
55 What's the transformation in the second step?
57 cd top-cachedir/nntp-testers
58 for f in ?/*; do
59 mkdir -p ../$f
60 mv $f ../$f/nntp-testers
61 done
64 =cut
67 use FindBin;
68 use lib "$FindBin::Bin/../lib";
69 BEGIN {
70 push @INC, qw( );
73 use Dumpvalue;
74 use File::Basename qw(dirname);
75 use File::Path qw(mkpath);
76 use File::Spec;
77 use File::Temp;
78 use Getopt::Long;
79 use Hash::Util qw(lock_keys);
81 our %Opt;
82 lock_keys %Opt, map { /([^=]+)/ } @opt;
83 GetOptions(\%Opt,
84 @opt,
85 ) or pod2usage(1);
87 my $olddir = $Opt{fromdir} ||= "nntp-testers-20111125";
88 $Opt{todir} ||= "nntp-testers";
89 opendir my $dh, $olddir or die;
90 my $i = 0;
91 for my $dirent (readdir $dh) {
92 next if $dirent =~ /^\.\.?$/;
93 my $fh;
94 if ($dirent =~ /\.gz$/) {
95 open $fh, "-|", "zcat", "$olddir/$dirent" or die;
96 } else {
97 open $fh, "<", "$olddir/$dirent" or die;
99 my $distv;
100 while (<$fh>) {
101 next unless /CPAN Testers Reports: Report for (\S+?)</;
102 $distv = $1;
103 last;
105 next unless $distv;
106 close $fh;
107 my $todir = sprintf "$Opt{todir}/%s/%s", substr($distv,0,1), $distv;
108 mkpath $todir;
109 rename "$olddir/$dirent", "$todir/$dirent";
110 print ".";
111 $i++;
112 print "($i)" unless $i % 1000;
115 # Local Variables:
116 # mode: cperl
117 # cperl-indent-level: 4
118 # End: