forked from tokuhirom/OrePAN
/
orepan_index.pl
executable file
·130 lines (88 loc) · 2.97 KB
/
orepan_index.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use lib 'lib';
use 5.008001;
use OrePAN::Package::Index;
use OrePAN::Archive;
use OrePAN::Package::Whois;
use Carp ();
use Pod::Usage qw/pod2usage/;
use Data::Dumper; sub p { print STDERR Dumper(@_) }
use Getopt::Long;
use File::Basename;
use Path::Class;
use Log::Minimal;
use File::Find;
our $VERSION='0.01';
GetOptions(
'r|repository=s' => \my $repository,
'h|help' => \my $help,
);
pod2usage(-verbose=>1) if $help;
$repository or pod2usage(-verbose=>1);
$repository = dir($repository);
my $authordir = $repository->subdir('authors');
$repository->subdir('modules')->mkpath;
my $pkg_file = $repository->file('modules', '02packages.details.txt.gz');
my $index = OrePAN::Package::Index->new(filename => "$pkg_file");
my $whois_file = $repository->file('authors', '00whois.xml');
my $whois = OrePAN::Package::Whois->new(filename => "$whois_file");
sub build_index {
my $file = $_;
return if ! -f $file;
return if $file !~ m!(?:\.zip|\.tar|\.tar\.gz|\.tgz)$!i;
(my $parsed = $file) =~ s/^\Q$authordir\E\/id\///;
my $pauseid = [split /\//, $parsed]->[2];
my $archive = OrePAN::Archive->new(filename => $file);
infof("get package names of %s", $file);
my %packages = $archive->get_packages;
# make index
infof('make index');
$index->add(
$parsed,
\%packages
);
$whois->add(cpanid => $pauseid);
}
find({ wanted => \&build_index, no_chdir => 1 }, $authordir );
$index->save();
$whois->save();
__END__
=encoding utf8
=head1 NAME
orepan_index.pl - yet another CPAN mirror aka DarkPAN index builder
=head1 SYNOPSIS
# make directory
% mkdir -p /path/to/repository/{modules,authors}
# copy CPAN mouldes to the directory
% cp MyModule-0.03.tar.gz /path/to/repository/authors/id/A/AB/ABC/
# make index file
% orepan_index.pl --repository=/path/to/repository
# remove module and recreate index
% rm /path/to/repository/authors/id/A/AB/ABC/MyModule-0.04.tar.gz
% orepan_index.pl --repository=/path/to/repository
# and use it
% cpanm --mirror-only --mirror=file:///path/to/repository Foo
=head1 DESCRIPTION
OrePAN is yet another CPAN mirror aka DarkPAN repository manager.
orepan_index.pl is CPAN mirror aka DarkPAN index builder.
orepan_index.pl parses all tarballs in specified repository directory, and makes 02packages.txt.gz file.
You can use the directory aka DarkPAN with `cpanm --mirror`.
If you want to add other mouldes to repository in one command, you can use L<orepan.pl>
=head1 OPTIONS
=over 4
=item B<--repository>
Set a directory that use as DarkPAN repository
=back
=head1 AUTHOR
Tokuhiro Matsuno E<lt>tokuhirom AAJKLFJEF GMAIL COME<gt>
Masahiro Nagano E<lt>kazeburo AAJKLFJEF GMAIL COME<gt>
=head1 SEE ALSO
L<CPAN::Mini::Inject>, L<App::cpanminus>, L<OrePAN>
=head1 LICENSE
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut