forked from andk/pause
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mldistwatch.pm
3616 lines (3231 loc) · 125 KB
/
mldistwatch.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Some POD is after __END__
use strict;
use lib "/home/k/pause/lib";
use version 0.47; # 0.46 had leading whitespace and ".47" problems
use CPAN (); # only for CPAN::Version
use CPAN::Checksums 1.050; # 1.050 introduced atomic writing
use CPAN::DistnameInfo ();
use Cwd ();
use DBI;
use Data::Dumper ();
use DirHandle ();
use Dumpvalue ();
use DynaLoader ();
use Exporter ();
use ExtUtils::MakeMaker ();
use ExtUtils::Manifest;
use Fcntl qw();
use File::Basename ();
use File::Copy ();
use File::Spec ();
use File::Temp 0.14 (); # begin of OO interface
use HTTP::Date ();
use JSON ();
use List::Util ();
use List::MoreUtils ();
use Mail::Send ();
use PAUSE ();
use PAUSE::MailAddress ();
use Safe;
use Text::Format;
{
my $HAVE_YAML = eval { require YAML; 1; };
my $HAVE_YAML_SYCK = eval { require YAML::Syck; 1; };
my $HAVE_YAML_XS = eval { require YAML::XS; 1; };
$PAUSE::dist::YAML_MODULE =
$HAVE_YAML_XS ? "YAML::XS" :
$HAVE_YAML_SYCK ? "YAML::Syck" :
$HAVE_YAML ? "YAML" :
die "Found neither YAML::XS nor YAML::Syck nor YAML installed";
}
$Data::Dumper::Indent = 1;
# "MAIN" at the end of file to guarantee all packages are inintialized
{
package PAUSE::mldistwatch::Constants;
# constants used for index_status:
use constant EDUALOLDER => 50; # pumpkings only
use constant EDUALYOUNGER => 30; # pumpkings only
use constant EOPENFILE => 21;
use constant EMISSPERM => 20;
use constant EPARSEVERSION => 10;
use constant EOLDRELEASE => 4;
use constant EMTIMEFALLING => 3; # deprecated after rev 478
use constant EVERFALLING => 2;
use constant OK => 1;
}
{
package PAUSE::mldistwatch;
###### data initialization ######
use DB_File;
use Fcntl qw(O_RDWR O_CREAT);
use File::Find;
use File::Path qw(rmtree mkpath);
our $Id = q$Id$;
# ISA_REGULAR_PERL means a perl release for public consumption
# (and must exclude developer releases like 5.9.4). I need to
# rename it from ISAPERL to ISA_REGULAR_PERL to avoid
# confusion with CPAN.pm. CPAN.pm has a different regex for
# ISAPERL because there we want to protect the user from
# developer releases too, but here we want to index a distro
# with very special treatment that is only reserved for "real"
# perl distros. (The exclusion of developer releases was
# accidentally lost in rev 815)
our $ISA_REGULAR_PERL = qr{
/
(
perl-5[._-](\d{3}(_[0-4][0-9])?|\d*[02468]\.\d+)
|
perl5[._](00\d(_[0-4][0-9])?)
|
ponie-[\d.\-]
)
(?:
\.tar[._-]gz
|
\.tar\.bz2
)
\z
}x;
}
package PAUSE::mldistwatch;
our $MAINTAIN_SYMLINKTREE = 1;
use Fcntl qw(:flock);
# this class shows that it was born as spaghetticode
sub new {
my $class = shift;
my $opt = shift;
my $fh;
unless ($opt->{pick}) { # pick files shall not block full run
my $pidfile = File::Spec->catfile( $PAUSE::Config->{PID_DIR}, 'mldistwatch.pid');
if (open $fh, "+>>", $pidfile) {
if (flock $fh, LOCK_EX|LOCK_NB) {
truncate $fh, 0 or die;
seek $fh, 0, 0;
my $ofh = select $fh;
$|=1;
print $fh $$, "\n";
select $ofh;
} else {
die "other mldistwatch job running, ".
"will not run at the same time";
}
} else {
die "Could not open pidfile[$pidfile]: $!";
}
}
my $tarbin = "/usr/local/bin/tar";
$tarbin = "/bin/tar" unless -x $tarbin;
die "No tarbin found" unless -x $tarbin;
my $unzipbin = "/usr/local/bin/unzip";
$unzipbin = "/usr/bin/unzip" unless -x $unzipbin;
die "No unzip found" unless -x $unzipbin;
my $self = bless {
TARBIN => $tarbin,
UNZIPBIN => $unzipbin,
OPT => $opt,
PIDFH => $fh,
}, $class;
$self->{VERBOSE} = -t STDOUT ? 2 : 1;
if ($opt->{pick}) {
for my $pick (@{$opt->{pick}}) {
$pick =~ s|^.*authors/id/|| if $pick =~ m|authors/id/./../|;
$self->{PICK}{$pick} = 1;
}
}
if ($opt->{'skip-locking'}) {
$self->{'SKIP-LOCKING'} = 1;
}
$self->verbose(1,"Starting");
$self;
}
sub sleep {
my($self) = @_;
my $sleep = $self->{OPT}{sleep} ||= 1;
sleep $sleep;
}
sub verbose {
my($self,$level,@what) = @_;
our $Id;
unless (@what) {
@what = ("warning: verbose called without \@what: ", $level);
$level = 1;
}
return if $level > $self->{VERBOSE};
unless (exists $self->{INTRODUCED}) {
my $now = scalar localtime;
require Data::Dumper;
unshift @what, "Running $0, $Id, $now",
Data::Dumper->new([$self],[qw()])->Indent(1)->Useqq(1)->Dump;
$self->{INTRODUCED} = undef;
}
my $logfh;
if (my $logfile = $self->{OPT}{logfile}) {
open $logfh, ">>", $logfile or die;
unshift @what, scalar localtime;
push @what, "\n";
} else {
$logfh = *STDOUT;
}
print $logfh @what;
}
sub work {
my $self = shift;
my $startdir = Cwd::cwd();
my $MLROOT = $self->mlroot;
chdir $MLROOT
or die "Couldn't chdir to $MLROOT";
$self->init_all();
$self->verbose(2,"Registering new users\n");
$self->set_ustatus_to_active();
my $testdir = File::Temp::tempdir(
"mldistwatch_work_XXXX",
DIR => "/tmp",
CLEANUP => 0,
) or die "Could not make a tmp directory";
chdir $testdir
or die("Couldn't change to $testdir: $!");
$self->checkfornew($testdir);
chdir $startdir or die "Could not chdir to '$startdir'";
rmtree $testdir;
return if $self->{OPT}{pick};
$self->work2;
}
sub work2 {
my $self = shift;
$self->rewrite02();
my $MLROOT = $self->mlroot;
chdir $MLROOT
or die "Couldn't chdir to $MLROOT: $!";
$self->rewrite01();
$self->rewrite03();
$self->rewrite06();
$self->overwrite07();
$self->verbose(1, sprintf(
"\nFinished rewrite03 and everything at %s\n",
scalar localtime
));
}
sub debug_mem {
my($self) = @_;
return unless $self->{OPT}{debug_mem};
my @caller = caller;
open my $ps, "ps -o pid,vsize -p $$ |";
open my $log, ">>", "/tmp/debug_mem.log" or die;
print $log scalar localtime, "\n";
print $log $caller[2], "\n";
print $log +<$ps>;
close $log or die;
}
sub filter_dups {
my($self,$array) = @_;
my($fh) = File::Temp->new(
DIR => "/tmp",
TEMPLATE => "mldistwatch_filterdups_XXXX",
);
print $fh map {"$_\n"} @$array;
close $fh;
my $filename = $fh->filename;
#system "wc -l $filename";
system "sort --output=$filename --unique $filename";
#system "wc -l $filename";
open $fh, $filename;
local $/ = "\n";
@$array = <$fh>;
#warn sprintf "scalar \@\$array: %d", scalar @$array;
#warn "Press RET to continue";
#<>;
chomp @$array;
return;
}
sub set_ustatus_to_active {
my $self = shift;
my $db = $self->connect;
my $active = $db->selectall_hashref("SELECT userid
FROM users
WHERE ustatus='active'",
"userid");
my %seen;
$self->debug_mem;
my @new_active_users;
while (my $file = each %{$self->{ALLfound}}) {
my($user) = $file =~ m|./../([^/]+)/|;
unless (defined $user){
$self->verbose(1,"Warning: user not defined for file[$file]\n");
next;
}
next if exists $active->{$user};
push @new_active_users, $user;
}
$self->filter_dups(\@new_active_users);
$self->debug_mem;
return unless @new_active_users;
$self->verbose(2,"Info: new_active_users[@new_active_users]");
my $sth = $db->prepare("UPDATE users
SET ustatus='active', ustatus_ch=? WHERE ustatus<>'nologin' AND userid=?");
for my $user (@new_active_users) {
$sth->execute(PAUSE->_now_string, $user);
}
$sth->finish;
}
sub connect {
my $self = shift;
return $self->{DBH} if $self->{DBH};
my $dbh = DBI->connect(
$PAUSE::Config->{MOD_DATA_SOURCE_NAME},
$PAUSE::Config->{MOD_DATA_SOURCE_USER},
$PAUSE::Config->{MOD_DATA_SOURCE_PW},
{
RaiseError => 1 }
) or die $DBI::errstr;
$self->{DBH} = $dbh;
}
sub disconnect {
my $self = shift;
return unless $self->{DBH};
$self->{DBH}->disconnect;
delete $self->{DBH};
}
sub DESTROY {
my $self = shift;
$self->disconnect;
}
sub init_all {
my $self = shift;
$self->verbose(2,"Running manifind\n");
$self->{ALLfound} = $self->manifind;
$self->verbose(2,"Collecting distmtimes from DB\n");
$self->{ALLlasttime} = $self->dbfind;
}
sub dbfind {
my($self) = @_;
my %found;
my($fh) = File::Temp->new(
DIR => "/tmp",
TEMPLATE => "mldistwatch_dbfind_XXXX",
);
tie %found, 'DB_File', $fh->filename, O_RDWR|O_CREAT, 0644, $DB_HASH;
my $dbh = $self->connect;
my $sth = $dbh->prepare("SELECT dist, distmtime FROM distmtimes");
$sth->execute;
my($dist,$distmtime);
RECORD: while (($dist,$distmtime) = $sth->fetchrow_array) {
if ($self->{PICK}){
my $hit;
for my $pd (keys %{$self->{PICK}}) {
$hit++ if $pd eq $dist;
}
next RECORD unless $hit;
}
$found{$dist} = $distmtime;
}
$sth->finish;
\%found;
}
sub clean_up_filename {
my($self,$filename) = @_;
$filename =~ s|^\./||;
return $filename;
}
sub manifind {
my($self) = @_;
my %found;
return $self->{PICK} if $self->{PICK};
my($fh) = File::Temp->new(
DIR => "/tmp",
TEMPLATE => "mldistwatch_manifind_XXXX",
);
tie %found, 'DB_File', $fh->filename, O_RDWR|O_CREAT, 0644, $DB_HASH;
my $wanted = sub {
return if m|CHECKSUMS$|;
return if -d $_;
my $name = $self->clean_up_filename($File::Find::name);
$found{$name} = undef;
};
find(
{wanted => $wanted},
"."
);
return \%found;
}
sub _newcountokay {
my ($self, $count) = @_;
my $MIN = $PAUSE::Config->{ML_MIN_FILES};
return $count >= $MIN;
}
sub checkfornew {
my($self,$testdir) = @_;
local $/ = "";
my $dbh = $self->connect;
my $time = time;
my $alert;
my @all;
my($fh) = File::Temp->new(
DIR => "/tmp",
TEMPLATE => "mldistwatch_all_XXXX",
UNLINK=>1,
);
tie @all, 'DB_File', $fh->filename, O_RDWR|O_CREAT, 0644, $DB_RECNO or die;
{
$self->debug_mem;
my %seen;
@all = keys %{$self->{ALLfound}};
push @all, keys %{$self->{ALLlasttime}};
$self->filter_dups(\@all);
$self->debug_mem;
}
my $all = scalar @all;
die "Panic: unusual small number of files involved ($all)"
if !$self->{PICK} && ! $self->_newcountokay($all);
$self->verbose(2, "Starting BIGLOOP over $all files\n");
BIGLOOP: for (my $i=0;scalar @all;$self->empty_dir($testdir)) {
my $dist = shift @all;
#
# Examine all files, even CHECKSUMS and READMEs
#
$i++;
$self->verbose(2,". $dist ..") unless $i%256;
my $dio = PAUSE::dist->new(
MAIN => $self,
DIST => $dist,
DBH => $dbh,
ALERT => "",
TIME => $time,
TARBIN => $self->{TARBIN},
UNZIPBIN => $self->{UNZIPBIN},
PICK => $self->{PICK},
'SKIP-LOCKING' => $self->{'SKIP-LOCKING'},
);
if ($dio->ignoredist){
delete $self->{ALLlasttime}{$dist};
delete $self->{ALLfound}{$dist};
next BIGLOOP;
}
if (exists $self->{ALLfound}{$dist}) {
unless ($dio->mtime_ok($self->{ALLlasttime}{$dist})){
delete $self->{ALLlasttime}{$dist};
delete $self->{ALLfound}{$dist};
next BIGLOOP;
}
} else {
$dio->delete_goner;
delete $self->{ALLlasttime}{$dist};
delete $self->{ALLfound}{$dist};
next BIGLOOP;
}
unless ($dio->lock) {
$self->verbose(1,"Could not obtain a lock on $dist\n");
next BIGLOOP;
}
$self->verbose(1,"\n Examining $dist ...\n");
$0 = "mldistwatch: $dist";
my $userid = PAUSE::dir2user($dist);
$dio->{USERID} = $userid;
# >99% of all distros are already registered by the
# newfilehook but the few coming though mirror(1) are not.
# Registering *everything* that comes here should catch them
# and if we re-register this or that it should not hurt. But
# everything older than a day does not belong here, like when
# people re-index an old distro.
{
my $MLROOT = $self->mlroot;
for my $f ("$MLROOT/$dist") {
local $^T = time;
if (-M $f < 1) {
PAUSE::newfile_hook($f);
}
}
}
$dio->examine_dist; # checks for perl, developer, version, etc. and untars
if ($dio->skip){
delete $self->{ALLlasttime}{$dist};
delete $self->{ALLfound}{$dist};
next BIGLOOP;
}
$dio->read_dist;
$dio->extract_readme_and_yaml;
if ($dio->{YAML_CONTENT}{distribution_type}
&& $dio->{YAML_CONTENT}{distribution_type} =~ m/^(script)$/) {
next BIGLOOP;
}
$dio->check_blib;
$dio->check_multiple_root;
$dio->check_world_writable;
$dio->examine_pms; # will switch user
$dio->mail_summary;
$self->sleep;
$dio->set_indexed;
$alert .= $dio->alert; # now $dio can go out of scope
}
untie @all;
undef $fh;
if ($alert) {
$self->verbose(1,$alert); # summary
if ($PAUSE::Config->{TESTHOST} || $self->{OPT}{testhost}) {
} else {
our $Id;
my($msg) = Mail::Send->new(
To => $PAUSE::Config->{ADMIN},
Subject => "Upload Permission or Version mismatch"
);
$msg->add("From", "PAUSE <$PAUSE::Config->{UPLOAD}>");
my $fh = $msg->open($PAUSE::Config->{ML_MAILER});
print $fh "Not indexed.\n\t$Id\n\n", $alert;
$fh->close;
}
}
}
sub empty_dir {
my($self,$testdir) = @_;
chdir $testdir or die "Could not chdir to '$testdir': $!"; # reassure
my($dh) = DirHandle->new(".");
for my $dirent ($dh->read) {
next if $dirent eq "." || $dirent eq "..";
rmtree $dirent;
}
$dh->close;
}
sub rewrite02 {
my $self = shift;
our $Id;
#
# Rewriting 02packages.details.txt
#
$self->verbose(1,"\n\nEntering rewrite02\n");
my $dbh = $self->connect;
my $MLROOT = $self->mlroot;
my $repfile = "$MLROOT/../../modules/02packages.details.txt";
my $list = "";
my $olist = "";
local($/) = "\n";
if (
-f "$repfile.gz" and
open F, "$PAUSE::Config->{GZIP} --stdout --uncompress $repfile.gz|"
) {
while (<F>) {
next if 1../^$/;
$olist .= $_;
}
close F;
}
my $date = HTTP::Date::time2str();
my $sth = $dbh->prepare(qq{SELECT package, version, dist, file
FROM packages
WHERE status='index'});
# the status='noindex' is there so we can manually disable
# indexing of packages if need be (2004-05-04 we had such a case)
$sth->execute;
my(@row,@listing02);
my $numrows = $sth->rows;
$self->verbose(2,"numrows[$numrows]\n");
while (@row = $sth->fetchrow_array) {
my($one,$two);
my $infile = $row[0];
$infile =~ s/^.+:://;
next unless $row[3];
next unless index($row[3],"$infile.pm")>=0
or $row[3]=~/VERSION/i # VERSION is Russ Allbery's idea to
# force inclusion
or $row[3] eq "missing in META.yml, tolerated by PAUSE indexer";
$row[1] =~ s/^\+//;
$one=30;
$two=8;
if (length($row[0])>$one) {
$one += 8 - length($row[1]);
$two = length($row[1]);
}
push @listing02, sprintf "%-${one}s %${two}s %s\n", @row;
}
my $numlines = @listing02;
die "Absurd small number of lines"
unless $numlines > $PAUSE::Config->{ML_MIN_INDEX_LINES};
my $header = qq{File: 02packages.details.txt
URL: http://www.perl.com/CPAN/modules/02packages.details.txt
Description: Package names found in directory \$CPAN/authors/id/
Columns: package name, version, path
Intended-For: Automated fetch routines, namespace documentation.
Written-By: $Id
Line-Count: $numlines
Last-Updated: $date\n\n};
$list .= join "", sort {lc $a cmp lc $b} @listing02;
if ($list ne $olist) {
my $F;
if (open $F, ">", "$repfile.new") {
print $F $header;
print $F $list;
} else {
$self->verbose(1,"Couldn't open >02packages\n");
}
close $F or die "Couldn't close: $!";
rename "$repfile.new", $repfile or
$self->verbose(1,"Couldn't rename to '$repfile': $!");
PAUSE::newfile_hook($repfile);
0==system "$PAUSE::Config->{GZIP} --best --rsyncable --stdout $repfile > $repfile.gz.new"
or $self->verbose(1,"Couldn't gzip for some reason");
rename "$repfile.gz.new", "$repfile.gz" or
$self->verbose(1,"Couldn't rename to '$repfile.gz': $!");
PAUSE::newfile_hook("$repfile.gz");
}
}
sub rewrite01 {
my($self) = shift;
#
# Rewriting 01modules.index.html
#
$self->verbose(1, "\nEntering rewrite01\n");
my $dbh = $self->connect;
my $MLROOT = $self->mlroot;
my $repfile = "$MLROOT/../../modules/01modules.index.html";
my $list = "";
my $olist = "";
local $/;
local *F;
if (open F, $repfile) {
while (<F>) {
$olist .= $_;
}
close F;
} else {
$self->verbose(1,"Couldn't open $repfile $!\n");
}
my(%firstlevel,%achapter);
my $sth = $dbh->prepare("SELECT modid, chapterid FROM mods");
$sth->execute;
while (my($modid,$chapterid) = $sth->fetchrow_array) {
my($root,$colo) = $modid =~ /^([^:]+)(::)?/;
$firstlevel{$root}++;
# the determination of %achapter was introduced with rev 211.
# Alternatives were tried in 212 and 214, but they had
# uncountable misfits. 215 then was very similar to 211 but we
# did sort above query by chapterid and got tons of misfits.
# So we do not really have a solution. Every solution is
# wrong, even the pre-211 solution. OK, I've taken out the
# order by clause and retested, cheap_chapter deviates from
# old chapter for Exception, Sort, and User, that's all.
if ($colo) {
if (! exists $achapter{$root}) {
$achapter{"$root\::"} ||= $chapterid;
}
} else {
delete $achapter{"$root\::"};
$achapter{$root} ||= $chapterid;
}
}
my(@chaptitle);
$sth = $dbh->prepare("SELECT chapterid, shorttitle FROM chapters");
$sth->execute;
while (my($chapterid, $shorttitle) = $sth->fetchrow_array) {
$chaptitle[$chapterid] = sprintf "%02d_%s", $chapterid, $shorttitle;
}
$sth = $dbh->prepare("SELECT package, dist FROM packages");
$sth->execute;
my(@listing01,%count,$count);
my(%seen);
my(%usercache,%userdircache,$i);
while (my($pkg,$pkgdist) = $sth->fetchrow_array) {
my %pkg = (rootpack => $pkg, dist => $pkgdist);
$pkg{rootpack} =~ s/:.*//;
# We don't want to list perl distribution
next if $pkg{dist} =~ m|/perl-?5|;
if ($seen{$pkg{dist},$pkg{rootpack}}++) {
next;
}
if ($firstlevel{$pkg{rootpack}}) {
#print "01 will have: $pkg{rootpack}/$pkg{dist}\n";
} else {
next;
}
$i++;
@pkg{qw/size mtime/} =
(stat "$MLROOT/$pkg{dist}")[7,9];
next unless defined $pkg{size}; # somebody removed it while we were running
$count++ unless $count{$pkg{dist}}++;
$pkg{size} =
$pkg{size} > 700000 ?
sprintf "%.1fM", $pkg{size}/1024/1024 :
$pkg{size} > 700 ?
sprintf "%dk", $pkg{size}/1024+0.5 :
"1k";
# my(@parts) = split /\//, $pkg{dist};
my $directory = File::Basename::dirname($pkg{dist});
my $user = $usercache{$directory} ||= PAUSE::dir2user($pkg{dist});
my $f = File::Basename::basename($pkg{dist});
my $userdir = $userdircache{$user} ||= PAUSE::user2dir($user);
die "no user for dist[$pkg{dist}]" unless $user;
# die "no user in database with id[$user]" unless $User{$user};
$pkg{userid} = $user;
# $pkg{fullname} = $User{$user};
$pkg{userdir} = $userdir;
$pkg{useridfiller} = " "x(10-length($user));
$pkg{filenameonly} = $f;
$pkg{filenamefiller} =
" "x(38-length($f)-length($pkg{size}));
$pkg{mtimestr} =
substr(HTTP::Date::time2str($pkg{mtime}),5,11);
$pkg{young} =
$pkg{mtime} > $^T - 60 * 60 * 24 * 14 ? " +" : "";
push @listing01, [@pkg{qw/rootpack userdir userid useridfiller
dist filenameonly filenamefiller size
mtimestr young mtime/}];
# now the symlinks.
# we just wrote something like
# Sybase MEWP sybperl-2.03.tar.gz 91.8 31 Jan 1996
# we are in authors/id/
$pkg{rootpack} =~ s/\*$//; # XXX seems stemming from already deleted code
{
my $d = CPAN::DistnameInfo->new("authors/id/$pkg{dist}");
my $exte = $d->extension;
($pkg{readme} = $pkg{dist}) =~
s/\.\Q$exte\E/.readme/;
}
$pkg{readmefn} = File::Basename::basename($pkg{readme});
$pkg{chapterid} = $achapter{$pkg{rootpack}}
|| $achapter{"$pkg{rootpack}\::"};
if (defined $pkg{chapterid}) {
if (defined $chaptitle[$pkg{chapterid}]) {
$pkg{chapter} = $chaptitle[$pkg{chapterid}]
} else {
$pkg{chapter} = "99_Not_In_Modulelist";
$self->verbose(1,"\nfound no chapterid for $pkg{rootpack}\n");
}
} else {
$pkg{chapter} = "99_Not_In_Modulelist";
$self->verbose(1,"found no chapter for $pkg{rootpack}\n");
}
$self->verbose(2,".") if !($i % 16);
if ($MAINTAIN_SYMLINKTREE) {
my $bymod = "$MLROOT/../../modules/".
"by-module/$pkg{rootpack}/$pkg{filenameonly}";
my $bycat = "$MLROOT/../../modules/".
"by-category/$pkg{chapter}/$pkg{rootpack}/$pkg{filenameonly}";
next if -e $bymod and -e $bycat;
$self->chdir_ln_chdir($MLROOT,
"../../../authors/id/$pkg{dist}",
"../../modules/by-module/$pkg{rootpack}".
"/$pkg{filenameonly}");
$self->chdir_ln_chdir($MLROOT,
"../../../authors/id/$pkg{readme}",
"../../modules/by-module/$pkg{rootpack}".
"/$pkg{readmefn}")
if -f $pkg{readme};
$self->chdir_ln_chdir($MLROOT,
"../../../authors/id/$userdir",
"../../modules/by-module/$pkg{rootpack}/$pkg{userid}");
$self->chdir_ln_chdir($MLROOT,
"../../../../authors/id/$pkg{dist}",
"../../modules/by-category/$pkg{chapter}".
"/$pkg{rootpack}/$pkg{filenameonly}");
$self->chdir_ln_chdir($MLROOT,
"../../../../authors/id/$pkg{readme}",
"../../modules/by-category/$pkg{chapter}".
"/$pkg{rootpack}/$pkg{readmefn}")
if -f $pkg{readme};
$self->chdir_ln_chdir($MLROOT,
"../../../../authors/id/$userdir",
"../../modules/by-category/$pkg{chapter}".
"/$pkg{rootpack}/$pkg{userid}");
}
}
$list = qq{<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title>Modules
on CPAN alphabetically</title></head><body>
<h1>CPAN\'s $count modules distributions</h1>
<h3>in alphabetical order by modules contained in the distributions</h3>
<i>} .
scalar gmtime() .
qq{ GMT</i>
<p>The list contains modules distribution files on CPAN for modules that
are <b>not</b> included in the perl standard distribution but
<b>are</b> included in the current release of <a
href="00modlist.long.html">Perl Module List</a>. To keep the size of
this list acceptable, it does not list which modules are in each
package. To get at those, it is recommended to use the CPAN.pm module
or read the detailed <a
href="02packages.details.txt.gz">listing</a>.</p>
<p>Column <b><code>module/category</code></b> contains the module or
category name, column <b><code>author/maintainer</code></b> the userid
of the author or maintainer which is a hyperlink to her homedirectory.
The filename in column <b><code>current distribution file</code></b>
is a link to the real file. The last column <b><code>young</code></b>
contains a plus sign if the file is younger than two weeks.</p>
<p><i>See also:</i></p>
<ul>
<li> <a href="01modules.mtime.html">Most recent uploads</a> sorted by uploadtime.</li>
<li> <a href="../CPAN.html">CPAN\'s <b>front page</b></a> by Jon Orwant.</li>
<li> <a href="00modlist.long.html">The <b>Module List</b></a>
by Tim Bunce and Andreas König</li>
<li> <a href="../authors/00whois.html"><b>Who is who</b></a></li>
<li> The detailed <a href="02packages.details.txt.gz">listing</a> of all
packages found in these distribution files</li>
</ul>
<hr />
<pre>
module/ author/ current distribution file size uploaded young
category maintainer
};
#'
$list .= join("",
map {sprintf(
qq{%-12s<a href="../authors/id/%s">%s</a>%s<a
href="../authors/id/%s">%s</a> %s %s %s%s\n},
@$_
)}
sort {lc $a->[0] cmp lc $b->[0] # package(root)
or
$a->[2] cmp $b->[2] # userid
or
lc $a->[5] cmp lc $b->[5] # filename
} @listing01
);
$list .= q{</pre></body></html>};
my($comparelist) = $list;
$comparelist =~ s/.+?<hr\b//s; # delete the intro (date!)
$olist =~ s/.+?<hr\b//s;
if ($comparelist ne $olist) {
if (open F, ">$repfile.new") {
print F $list;
close F;
rename "$repfile.new", $repfile or die;
PAUSE::newfile_hook($repfile);
$self->write_01sorted(\@listing01);
} else {
$self->verbose(1,"Couldn't open 01modules...\n");
}
}
}
sub xmlquote {
my @x = @_;
foreach my $it (@x) {
$it = '' unless defined $it;
$it =~ s<([^\n\r\t\x20\x21\x23\x27-\x3b\x3d\x3F-\x5B\x5D-\x7E])>
<'&#'.(ord($1)).';'>seg;
# turn strange things into decimal-numeric entities, no questions asked.
}
return join '', @x unless wantarray;
return @x;
}
sub write_01sorted {
my($self, $listing) = @_;
my($n) = 150;
my $html = qq{\n<html><head>
<title>Modules on CPAN sorted by upload date</title>
<link rel="alternate" type="application/rss+xml" title="RSS"
href="./01modules.mtime.rss" />
</head>
<body>
<h1>CPAN\'s $n most recent uploads</h1>
<h3>ordered by timestamp of the distributions</h3>
A description of the list can be found in
<a href="01modules.index.html">01modules.index.html</a>.
<a href="./01modules.mtime.rss"
style="
border: 3px solid;
border-color: #FC9 #630 #330 #F96;
background: #F60;
color: #FFF !important;
margin: 0;
padding: 0 3px;
font: bold .7em verdana, sans-serif;
text-decoration: none !important;
"
>RSS</a>
<hr />
<pre>
author/ distribution file size uploaded
maintainer
};
my $rss = qq{<?xml version="1.0"?>
<rss version="2.0"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
><channel>
<title>Recent CPAN Uploads</title>
<description>The $n most recent modules uploaded to CPAN</description>
<link>http://www.cpan.org/modules/01modules.mtime.html</link>
<language>en</language>
<sy:updateFrequency>3</sy:updateFrequency>
<sy:updatePeriod>daily</sy:updatePeriod>
<sy:updateBase>1970-01-01T12:24+00:00</sy:updateBase>
<ttl>480</ttl>
<webMaster>cpan@perl.org</webMaster>
};
my(%seen);
for my $l (
sort {$b->[10] <=> lc $a->[10] # mtime
} @$listing
) {
next if $seen{$l->[4]}++; # dist
my %package;
@package{qw{package userdir userid
useridfiller dist filenameonly
filenamefiller size mtimestr young mtime}}
= xmlquote( @$l );
## DB<2> x \%package
## 0 HASH(0x8c42664)
## 'dist' => 'W/WS/WSNYDER/SystemPerl-1.150.tar.gz'
## 'filenamefiller' => ' '
## 'filenameonly' => 'SystemPerl-1.150.tar.gz'
## 'mtime' => 1088685199
## 'mtimestr' => '01 Jul 2004'
## 'package' => 'SystemC'
## 'size' => '73k'
## 'userdir' => 'W/WS/WSNYDER'
## 'userid' => 'WSNYDER'
## 'useridfiller' => ' '
## 'young' => ' +'
$package{filenamefiller} =
" "x(40-length($package{filenameonly})-length($package{size}));
$package{'useridpretty'} = ucfirst(
$package{'useridlc'} = lc $package{'userid'}
);
{
my $d = CPAN::DistnameInfo->new("authors/id/$package{dist}");
my $exte = $d->extension;
($package{basename}) =
$package{filenameonly} =~ /^(.*)\.(?:\Q$exte\E)/;
}
$html .= sprintf(
qq{<a href="../authors/id/%s">%s</a>%s<a
href="../authors/id/%s">%s</a> %s %s %s\n},
@package{qw{userdir userid useridfiller dist filenameonly
filenamefiller size mtimestr}}
);
$rss .= sprintf qq{
<item>
<title>%s : %s</title>
<link>http://www.cpan.org/modules/by-authors/id/%s/%s</link>
<description>%s uploaded %s (%s) on %s</description>
<guid isPermaLink="false">%s</guid>
<comments>http://search.cpan.org/~%s/%s/</comments>
</item>
},
@package{qw{basename useridpretty
userdir filenameonly
useridpretty dist size mtimestr
filenameonly
useridlc package
}};
last unless --$n;
}
$html .= qq{</pre></body></html>\n};
$rss .= "\n</channel></rss>\n";