1 |
commit: 86cf3771522cae084ec11a50aa85401504489cfc |
2 |
Author: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
3 |
AuthorDate: Sun Apr 8 13:14:30 2012 +0000 |
4 |
Commit: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
5 |
CommitDate: Sun Apr 8 13:14:30 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/perl-overlay.git;a=commit;h=86cf3771 |
7 |
|
8 |
[scripts] add scripts/package_map.pl which emits all useful metadata for all versions of a given distribution |
9 |
|
10 |
--- |
11 |
scripts/package_map.pl | 132 ++++++++++++++++++++++++++++++++++++++++++++++++ |
12 |
1 files changed, 132 insertions(+), 0 deletions(-) |
13 |
|
14 |
diff --git a/scripts/package_map.pl b/scripts/package_map.pl |
15 |
new file mode 100755 |
16 |
index 0000000..cdc306f |
17 |
--- /dev/null |
18 |
+++ b/scripts/package_map.pl |
19 |
@@ -0,0 +1,132 @@ |
20 |
+#!/usr/bin/env perl |
21 |
+ |
22 |
+eval 'echo "Called with something not perl"' && exit 1 # Non-Perl protection. |
23 |
+ if 0; |
24 |
+ |
25 |
+use 5.14.2; |
26 |
+use strict; |
27 |
+use warnings; |
28 |
+ |
29 |
+use FindBin; |
30 |
+use lib "$FindBin::Bin/lib"; |
31 |
+ |
32 |
+use env::gentoo::perl_experimental; |
33 |
+use metacpan qw( mcpan ); |
34 |
+use Try::Tiny; |
35 |
+use optparse; |
36 |
+ |
37 |
+# FILENAME: pvlist.pl |
38 |
+# CREATED: 16/10/11 20:16:03 by Kent Fredric (kentnl) <kentfredric@×××××.com> |
39 |
+# ABSTRACT: Show dist metadata for interesting perl dists |
40 |
+ |
41 |
+# DEPENDENCIES: |
42 |
+# |
43 |
+# * MetaCPAN::API |
44 |
+# * CHI |
45 |
+# * WWW::Mechanize::Cached |
46 |
+# * HTTP::Tiny::Mech |
47 |
+# * Data::Dump |
48 |
+# * Gentoo::PerlMod::Version |
49 |
+# |
50 |
+ |
51 |
+my $optparse = optparse->new( |
52 |
+ argv => \@ARGV, |
53 |
+ help => sub { print help(); }, |
54 |
+); |
55 |
+my $search = {}; |
56 |
+$search->{query} = { constant_score => { filter => { terms => { distribution => $optparse->extra_opts } } } }; |
57 |
+$search->{sort} = [ { 'date' => 'desc', }, ]; |
58 |
+$search->{size} = 5000; |
59 |
+$search->{fields} = [qw( |
60 |
+ abstract |
61 |
+ archive |
62 |
+ author |
63 |
+ authorized |
64 |
+ date |
65 |
+ distribution |
66 |
+ download_url |
67 |
+ license |
68 |
+ maturity |
69 |
+ name |
70 |
+ status |
71 |
+ version |
72 |
+)]; |
73 |
+ |
74 |
+_log( ['initialized: fetching search results'] ); |
75 |
+ |
76 |
+my $results = mcpan->post( 'release/_search', $search ); |
77 |
+ |
78 |
+_log( [ 'fetched %s results', scalar @{ $results->{hits}->{hits} } ] ); |
79 |
+ |
80 |
+my $data = {}; |
81 |
+ |
82 |
+ |
83 |
+for my $result ( @{ $results->{hits}->{hits} } ) { |
84 |
+ if ( not $result->{fields} ) { |
85 |
+ $result->{fields} = $result->{_source}; |
86 |
+ } |
87 |
+ delete $result->{fields}->{dependency} if exists $result->{fields}->{dependency}; |
88 |
+ my $fields = $result->{fields}; |
89 |
+ |
90 |
+ my $cversion = $fields->{name}; |
91 |
+ my $cdistrib = $fields->{distribution}; |
92 |
+ $cversion =~ s/^${cdistrib}-//; |
93 |
+ |
94 |
+ $fields->{canon_version} = $cversion; |
95 |
+ $fields->{gentoo_version} = scalar try { gv( $cversion , { lax => 1 } ) }; |
96 |
+ $data->{ $cdistrib } = [] unless exists $data->{ $cdistrib }; |
97 |
+ push @{ $data->{ $cdistrib } }, $fields ; |
98 |
+} |
99 |
+ |
100 |
+require JSON; |
101 |
+ |
102 |
+my $encode = JSON->new->pretty->utf8->canonical; |
103 |
+say $encode->encode( $data ); |
104 |
+ |
105 |
+exit 0; |
106 |
+ |
107 |
+# Utils |
108 |
+ |
109 |
+sub pp { require Data::Dump; goto \&Data::Dump::pp } |
110 |
+sub gv { require Gentoo::PerlMod::Version; goto \&Gentoo::PerlMod::Version::gentooize_version } |
111 |
+ |
112 |
+sub _log { |
113 |
+ return unless $optparse->long_opts->{trace}; |
114 |
+ return *STDERR->print(@_) if ( not ref $_[0] ); |
115 |
+ |
116 |
+ state $prefix = "\e[7m* package_map.pl:\e[0m "; |
117 |
+ |
118 |
+ my ( $str, @args ) = @{ $_[0] }; |
119 |
+ $str =~ s/\n?$/\n/; |
120 |
+ |
121 |
+ *STDERR->print($prefix); |
122 |
+ *STDERR->printf( $str, @args ); |
123 |
+ return; |
124 |
+ |
125 |
+} |
126 |
+ |
127 |
+ |
128 |
+ |
129 |
+sub help { |
130 |
+ return <<"EOF"; |
131 |
+package_map.pl |
132 |
+ |
133 |
+USAGE: |
134 |
+ |
135 |
+ package_map.pl PACKAGE [PACKAGE*][--help] [--trace] |
136 |
+ |
137 |
+ ie: |
138 |
+ |
139 |
+ # Show full metadata for Moose, Catalyst-Runtime and Dist-Zilla |
140 |
+ package_log.pl Moose Catalyst-Runtime Dist-Zilla |
141 |
+ |
142 |
+ # Be verbose about what we're doing |
143 |
+ package_log.pl Moose --trace |
144 |
+ |
145 |
+ --help Show this message |
146 |
+ --trace Turn on extra debugging. |
147 |
+ |
148 |
+EOF |
149 |
+ |
150 |
+} |
151 |
+ |