/[gentoo-perl]/g-cpan/trunk/bin/g-cpan
Gentoo

Contents of /g-cpan/trunk/bin/g-cpan

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations) (download)
Sat Nov 25 16:58:17 2006 UTC (10 years, 10 months ago) by mcummings
File size: 30181 byte(s)
Committing basic fixes


1 #!/usr/bin/perl -w
2 package main;
3
4 # Copyright 1999-2005 Gentoo Foundation
5 # Distributed under the terms of the GNU General Public License v2
6 #
7
8 use lib "../lib";
9 # modules to use - these will need to be marked as
10 # dependencies, and installable by portage
11 use strict;
12 use File::Spec;
13 use File::Path;
14 use File::Basename;
15 use File::Copy;
16 use Term::ANSIColor;
17 use Cwd qw(getcwd abs_path cwd);
18 use YAML;
19 use YAML::Node;
20 use Carp;
21 use IO::File;
22
23 use Gentoo;
24 use Gentoo::UI::Console;
25 use Log::Agent;
26 use Log::Agent::Driver::File;
27 use Log::Agent::Driver::Silent;
28
29 use constant PATH_PKG_VAR => '/var/db/pkg/';
30
31 ##### Establish our tmpdir
32 unless ($ENV{TMPDIR}) { $ENV{TMPDIR} = '/var/tmp/g-cpan' }
33
34 our $VERSION = "0.14.1-rc1";
35 my $prog = basename($0);
36
37 my %dep_list = ();
38 my @perl_dirs = ("dev-perl", "perl-core", "perl-gcpan", "perl-text", "perl-tools", "perl-xml", "perl-dev", "dev-lang",);
39
40 ###############################
41 # Command line interpretation #
42 ###############################
43
44 # Module load & configure
45 use Getopt::Long;
46 Getopt::Long::Configure("bundling");
47
48 # Declare options
49 # First, the main switches
50 my @main_switches = \my ($search, $list, $install, $generate, $buildpkgonly);
51 # Then, additional switches
52 my @additional_switches = \my ($upgrade, $pretend, $buildpkg, $ask);
53 # Then, the normal options
54 my ($debug, $verbose, $cpan_reload, $log);
55
56 # Set colors here so we can use them at will anywhere :)
57 my $green = color("bold green");
58 my $white = color("bold white");
59 my $cyan = color("bold cyan");
60 my $reset = color("reset");
61
62 #Get & Parse them
63 GetOptions(
64 'verbose|v' => \$verbose,
65 'search|s' => \$search,
66 'install|i' => \$install,
67 'upgrade|u' => \$upgrade,
68 'list|l' => \$list,
69 'log|L' => \$log,
70 'pretend|p' => \$pretend,
71 'buildpkg|b' => \$buildpkg,
72 'buildpkgonly|B' => \$buildpkgonly,
73 'ask|a' => \$ask,
74 'generate|g' => \$generate,
75 'debug|d' => \$debug,
76 'cpan_reload' => \$cpan_reload,
77 'help|h' => sub { exit_usage(); }
78 ) or exit_usage();
79
80 if ($log) {
81 open my $log_test, q{>>}, "/var/log/$prog/$prog.err" or
82 fatal(print_err("You don't have permission to perform logging to /var/log/$prog/$prog.err: $!"));
83 close($log_test);
84
85 my $log_driver = Log::Agent::Driver::File->make(
86 -prefix => "$prog",
87 -magic_open => 0,
88 -stampfmt => 'date',
89 -channels => {
90 'error' => "/var/log/$prog/$prog.err",
91 'output' => "/var/log/$prog/$prog.log",
92 }
93 );
94 logconfig(-driver => $log_driver);
95 } else {
96 my $log_driver = Log::Agent::Driver::Silent->make();
97 logconfig(-driver => $log_driver);
98 }
99
100 $log && $debug and
101 print_warn($prog, "*WARNING* - logging debug output can create large logs");
102
103 if ( ($install || $ask || $buildpkg || $buildpkgonly || $upgrade) && $> > 0 && !$pretend) {
104 print_err($prog, "ERROR - INSUFFICIENT PERMISSIONS TO RUN EMERGE");
105 logerr("ERROR - INSUFFICIENT PERMISSIONS TO RUN EMERGE");
106 exit();
107 }
108
109 if (! $install && defined($ask))
110 {
111 $install = 1
112 }
113
114 # Array containing the original values passed for installing
115 my %passed_to_install;
116
117 @ARGV > 0 and
118 %passed_to_install = map { $_ => 1 } @ARGV;
119
120
121 # Array that will contain the portage friendly version of the values passed to install
122 my %really_install;
123
124 # Output error if more than one main switch is activated
125 #
126
127 if ( (grep { defined $$_ } @main_switches) > 1) {
128 print_err($prog, "You can't combine actions with each other.\n");
129 print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} or ${cyan}man $prog${reset} for more information\n\n");
130 exit();
131 }
132
133 if ( ! grep { defined $$_ } @main_switches, @additional_switches ) {
134 print_err($prog, "You haven't told $prog what to do.\n");
135 print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} or ${cyan}man $prog${reset} for more information\n\n");
136 exit();
137 }
138
139 # Output error if no arguments
140 if (@ARGV == 0 && !(defined $upgrade || defined $list )) {
141 print_err($prog, "Not even one module name or expression given!\n");
142 print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} for more information\n\n");
143 exit();
144 }
145
146 ######################
147 # CPAN Special Stuff #
148 ######################
149
150 my $GentooCPAN = Gentoo->new();
151
152 # Don't do autointalls via ExtUtils::AutoInstall
153 $ENV{PERL_EXTUTILS_AUTOINSTALL} = "--skipdeps";
154 $ENV{PERL_MM_USE_DEFAULT} = 1;
155
156 # Do we need to generate a config ?
157 eval "use CPAN::Config;";
158 my $needs_cpan_stub = $@ ? 1 : 0;
159
160 # Test Replacement - ((A&B)or(C&B)) should be the same as ((A or C) and B)
161 if ( ($needs_cpan_stub || $> > 0) && ! -f "$ENV{HOME}/.cpan/CPAN/MyConfig.pm") {
162
163 # In case match comes from the UID test
164 $needs_cpan_stub = 1;
165
166 print_warn("No CPAN Config found, auto-generating a basic one");
167
168 # Generate a fake config for CPAN
169 $GentooCPAN->makeCPANstub();
170 } else {
171 $needs_cpan_stub = 0;
172 }
173
174 use CPAN;
175
176 ##########
177 # main() #
178 ##########
179
180 # Confirm that there is an /etc/portage/categories file
181 # and that we have an entry for perl-gcpan in it.
182 my $cat_file = "/etc/portage/categories";
183 if (-f "$cat_file") {
184
185 #
186 # Use braces to localize the $/ assignment, so we don't get bitten later.
187 #
188 local $/ = undef;
189 my $cat_read = IO::File->new($cat_file, '<');
190 if (defined $cat_read) {
191 my $data = <$cat_read>;
192 undef $cat_read;
193 autoflush STDOUT 1;
194 unless (grep "gcpan", $data) {
195 my $cat_write = IO::File->new($cat_file, '>>');
196 if (defined $cat_write) {
197 print $cat_write "perl-gcpan";
198 undef $cat_write;
199 autoflush STDOUT 1;
200 } else {
201 print_err("Insufficient permissions to edit /etc/portage/categories");
202 print_err("Please run $prog as a user with sufficient permissions");
203 exit;
204 }
205 }
206 }
207 } else {
208 my $cat_write = IO::File->new($cat_file, '>');
209 if (defined $cat_write) {
210 print $cat_write "perl-gcpan";
211 } else {
212 print_err("Insufficient permissions to edit /etc/portage/categories");
213 print_err("Please run $prog as a user with sufficient permissions");
214 exit;
215 }
216 }
217
218 my $gcpan_run = Gentoo->new(
219 'cpan_reload' => $cpan_reload,
220 'DEBUG' => $debug,
221 );
222
223 # Get the main portdir
224 my $PORTAGE_DIR = $gcpan_run->getValue('PORTDIR');
225 $gcpan_run->{portage_bases}{$PORTAGE_DIR} = 1;
226
227 # Grab the keywords - we'll need these when we build the ebuild
228 my $keywords = $gcpan_run->getValue('ACCEPT_KEYWORDS');
229
230 $keywords ||= do {
231 open my $tmp, '<', "$PORTAGE_DIR/profiles/arch.list"
232 or fatal(print_err($prog,"ERROR READING $PORTAGE_DIR/profiles/arch.list: $!"));
233 join ' ', map { chomp; $_ } <$tmp>;
234 };
235
236
237 # Get the overlays
238 my $overlay = $gcpan_run->getValue('PORTDIR_OVERLAY') || undef;
239
240 # Get the DISTDIR - we'd like store the tarballs in here the one time
241 $gcpan_run->{sources} = $gcpan_run->getValue('DISTDIR');
242
243 # Make sure we have write access to the DISTDIR
244 if ( $generate
245 || $install
246 || $pretend
247 || $buildpkg
248 || $buildpkgonly
249 || $ask
250 || $upgrade) {
251 my $test_dist_writes = $gcpan_run->{sources} . '/test-gcpan';
252 my $test_distdir = IO::File->new($test_dist_writes, '>');
253 if ($test_distdir) {
254 undef $test_distdir;
255 unlink $test_dist_writes;
256 } else {
257 undef $test_distdir;
258 fatal(print_err($prog, "No write access to DISTDIR: $!"));
259 }
260 }
261
262 if ($overlay) {
263 if ($overlay =~ /\S+\s+\S+/) {
264 my @overlays = split ' ', $overlay;
265 $gcpan_run->{portage_bases}{$_} = 1 foreach (@overlays)
266 } else {
267 $gcpan_run->{portage_bases}{$overlay} = 1;
268 }
269 } elsif ($generate || $pretend) {
270 print_err($prog, "The option you have chosen isn't supported without a configured overlay.\n");
271 exit();
272 }
273
274 # Set portage_categories to our defined list of perl_dirs
275 $gcpan_run->{portage_categories} = \@perl_dirs;
276
277 # Taking care of Searches.
278 if ($search) {
279 foreach my $expr (@ARGV) {
280 my $tree_expr = $expr;
281 $tree_expr =~ s/::/-/gxms;
282 scanTree(lc($tree_expr));
283 if ($gcpan_run->{ebuilds}{found_ebuild}{lc($tree_expr)}) {
284 print_info($prog, "Ebuild exists for $expr");
285 } else {
286 print_info($prog, "No ebuild exists, pulling up CPAN listings for $expr");
287
288 # Assume they gave us module-name instead of module::name
289 # which is bad, because CPAN can't convert it ;p
290
291 $verbose and print_ok($prog, "Searching for $expr on CPAN");
292
293 my @search_results;
294
295 # Let's define a CPAN::Frontend to use our printing methods
296 {
297 package Gentoo::CPAN::FakeFrontend;
298 my $spin = 0;
299 sub myprint {
300 my ($self, $text) = @_;
301 print "\r".('/', '-', '\\', '|')[$spin++%4];
302 # if there is only one result, the string is different
303 $text =~ /Module id = (.*)/ and push(@search_results, $1), return;
304 # in the case of multiple result
305 if ($text =~ /Module\s+(\S+)/) {
306 foreach (split(/\n/, $text)) {
307 $_ =~ /Module\s+(\S+)/ or next;
308 push @search_results, $1;
309 }
310 }
311 }
312 }
313
314 $CPAN::Frontend = "Gentoo::CPAN::FakeFrontend";
315
316 CPAN::Shell->i("/$expr/");
317 if (!@search_results) {
318 $expr =~ s/-/::/g;
319 CPAN::Shell->i("/$expr/");
320 }
321
322 # remove the spin
323 print "\r \r";
324
325 # now, @search_results should contain the matching modules strings, if any
326 if (@search_results) {
327 print_info('g-cpan', @search_results . " results found : @search_results");
328 } else {
329 print_warn('no result found.');
330 }
331
332 }
333 }
334
335 exit;
336 }
337
338 if ($list || $upgrade) {
339 if ($upgrade && @ARGV > 0) {
340 %passed_to_install = map { $_ => 1 } @ARGV;
341 } else {
342 my @overlays = split ' ', $overlay;
343 foreach my $overlay_dir (@overlays) {
344 my $gcpan_dir = File::Spec->catdir($overlay_dir, 'perl-gcpan');
345 $list and print_ok($prog, "OVERLAY: $gcpan_dir");
346 if (opendir PDIR, $gcpan_dir) {
347 while (my $file = readdir PDIR) {
348 $file eq '.' || $file eq '..' and next;
349 $list and print_info($prog, "perl-gcpan/$file");
350 $upgrade and $passed_to_install{$file} = 1;
351 }
352 closedir PDIR;
353 } else {
354 print_warn($prog, "Couldn't open folder $gcpan_dir: $!");
355 }
356 }
357 }
358 }
359
360 if ( $generate
361 || $install
362 || $pretend
363 || $buildpkg
364 || $buildpkgonly
365 || $ask
366 || $upgrade) {
367 generatePackageInfo($_) foreach (keys %passed_to_install)
368 }
369
370 if ($install || $pretend || $buildpkg || $buildpkgonly || $upgrade || $ask) {
371 if (keys %really_install) {
372
373 foreach my $ebuild (keys %really_install) {
374 $verbose and print_ok($prog, "Calling emerge for $ebuild\n");
375 my @flags;
376 if ($pretend && $pretend > 0) {push @flags, '--pretend' }
377 if ($ask && $ask > 0) { push @flags, '--ask' }
378 if ($buildpkg && $buildpkg > 0 ) {push @flags, '--buildpkg' }
379 if ($buildpkgonly && $buildpkgonly > 0 ) { push @flags, '--buildpkgonly' }
380
381 $verbose and print_info($prog, "Calling: emerge @flags $ebuild");
382 $gcpan_run->emerge_ebuild($ebuild, @flags);
383
384 }
385 } else {
386 if ($upgrade) {
387 print_info($prog, 'Everything was up to date, nothing to do!');
388 } else {
389 print_err($prog, 'Nothing to install!!');
390 }
391 }
392 }
393
394 sub generatePackageInfo {
395
396 # Since all we are concerned with is the final name of the package, this
397 # should be a safe substitution
398 my ($ebuild_wanted) = @_;
399 $ebuild_wanted =~ /ExtUtils(::|-)MakeMaker/i and
400 print_info($prog, 'Skipping ExtUtils::MakeMaker dependency'), next;
401
402 #In the event this is an upgrade, go ahead and do the lame s/-/::/
403 $upgrade and $ebuild_wanted =~ s/-/::/gxms;
404
405 # Grab specific info for this module
406 $gcpan_run->{ebuilds}{found_ebuild}{lc($ebuild_wanted)} or
407 $gcpan_run->getCPANInfo($ebuild_wanted);
408 if ( ! $gcpan_run->{cpan}{lc($ebuild_wanted)} && ! $gcpan_run->{ebuilds}{found_ebuild}{lc($ebuild_wanted)} ) {
409
410 # Fallback to trying the /-/::/ trick - we avoid this the first time
411 # in case the module actually employs a - in its name
412 $ebuild_wanted =~ s/-/::/gxms;
413 $gcpan_run->getCPANInfo($ebuild_wanted);
414 }
415
416 # If we found something on cpan, transform the portage_name
417 # It's possible to not find something on cpan at this point - we're just
418 # trying to pre-seed the portage_name
419 if ($gcpan_run->{cpan}{lc($ebuild_wanted)}) {
420 $gcpan_run->{cpan}{lc($ebuild_wanted)}{portage_name} =
421 $gcpan_run->transformCPAN($gcpan_run->{cpan}{lc($ebuild_wanted)}{src_uri}, 'n');
422 $gcpan_run->{cpan}{lc($ebuild_wanted)}{portage_version} =
423 $gcpan_run->transformCPAN($gcpan_run->{cpan}{lc($ebuild_wanted)}{src_uri}, 'v');
424 } else {
425 print_err($prog, "$ebuild_wanted is not a CPAN module!");
426 #MPC hold return;
427 }
428
429 # Save a copy of the originally requested name for later use
430 my $original_ebuild = $ebuild_wanted;
431
432 # Simple transform of name to something portage friendly
433 $ebuild_wanted =~ s/::/-/gxms;
434
435 # Scan portage for the ebuild name
436 $upgrade && defined($passed_to_install{$ebuild_wanted}) or scanTree($ebuild_wanted);
437 if ( ! ( $gcpan_run->{ebuilds}{found_ebuild}{lc($ebuild_wanted)}
438 || ($upgrade && defined($passed_to_install{$ebuild_wanted})) ) ) {
439
440 # Ebuild wasn't found - scan for the nice version of the module name
441 lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) eq 'perl' and next;
442 scanTree($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name});
443
444 # We had success in finding this module under a different name
445 if ($gcpan_run->{ebuilds}{found_ebuild}{lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name})}) {
446 $verbose and print_info($prog, 'Found ebuild under CPAN name (' . $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} . ')');
447 $ebuild_wanted = $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name};
448 }
449 } else {
450 $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} = $ebuild_wanted;
451 }
452
453 # Second round - we've looked for the package in portage two different
454 # ways now, time to get serious and create it ourselves
455 if ( ! $gcpan_run->{ebuilds}{found_ebuild}{lc($ebuild_wanted)} ) {
456
457 # Generate info - nothing found currently in the tree
458 $debug and $gcpan_run->debug;
459 print_warn($prog,"Looking for $original_ebuild");
460 if ( $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} &&
461 lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) ne 'perl') {
462
463 # We have a cpan package that matches the request.
464 # Let's unpack it and get all the deps out of it.
465 $gcpan_run->unpackModule($gcpan_run->{cpan}{lc($original_ebuild)}{name});
466
467 foreach my $dep (keys %{$gcpan_run->{cpan}{lc($original_ebuild)}{depends}}) {
468 defined $dep && $dep ne '' or next;
469 $dep eq 'perl' and delete $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep};
470
471 $dep =~ /ExtUtils(::|-)MakeMaker/i and print_info($prog,"Skipping ExtUtils::MakeMaker dependency"), next;
472
473 # Make sure we have information relevant to each of the deps
474 $verbose and print_info($prog, "Checking on dependency $dep for $original_ebuild");
475 $passed_to_install{$dep} or generatePackageInfo($dep);
476
477 # Remove dep from list of modules to install later on - no
478 # more dup'd installs!
479 defined $passed_to_install{$dep} and delete $really_install{$dep};
480
481 # Reindex one last time for anything we build after the fact
482 scanTree($gcpan_run->{cpan}{lc($dep)}{portage_name});
483 }
484
485 # Write ebuild here?
486 $debug and $gcpan_run->debug;
487 my @overlays = split ' ', $overlay;
488 foreach my $target_dir (@overlays) {
489 if (-d $target_dir) {
490 my $gcpan_dir = File::Spec->catdir($target_dir, 'perl-gcpan');
491 if (! -d $gcpan_dir) {
492 $verbose and print_info($prog, "Create directory '$gcpan_dir'");
493 mkdir($gcpan_dir, 0755) or
494 fatal(print_err($prog, "Couldn't create folder $gcpan_dir: $!"));
495 }
496 my $ebuild_dir = File::Spec->catdir($gcpan_dir, $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name});
497 if (! -d $ebuild_dir) {
498 $verbose and print_info($prog, "Create directory '$ebuild_dir'");
499 mkdir($ebuild_dir, 0755) or
500 fatal(print_err($prog, "Couldn't create folder $gcpan_dir: $!"));
501 }
502 my $files_dir = File::Spec->catdir($ebuild_dir, 'files');
503 if (! -d $files_dir) {
504 $verbose and print_info($prog, "Create directory '$files_dir'");
505 mkdir($files_dir, 0755) or
506 fatal(print_err($prog, "Couldn't create folder $gcpan_dir: $!"));
507 }
508 my $ebuild = File::Spec->catdir($ebuild_dir,
509 $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} . '-'
510 . $gcpan_run->{cpan}{lc($original_ebuild)}{portage_version}
511 . '.ebuild');
512
513 # Break out if we already have an ebuild (upgrade or
514 # mistake in the code)
515 if ( ! -f $ebuild) {
516 print_info($prog, 'Generating ebuild for ' . $gcpan_run->{cpan}{lc($original_ebuild)}{name});
517 my $EBUILD = IO::File->new($ebuild, '>') or
518 fatal(print_err($prog, "Couldn't open(write) file $ebuild: $!"));
519 print $EBUILD <<"HERE";
520 # Copyright 1999-2006 Gentoo Foundation
521 # Distributed under the terms of the GNU General Public License v2
522 # This ebuild generated by $prog $VERSION
523
524 inherit perl-module
525
526 S=\${WORKDIR}/$gcpan_run->{'cpan'}{lc($original_ebuild)}{'portage_sdir'}
527
528 DESCRIPTION="$gcpan_run->{'cpan'}{lc($original_ebuild)}{'description'}"
529 HOMEPAGE="http://search.cpan.org/search?query=\${PN}"
530 SRC_URI="mirror://cpan/authors/id/$gcpan_run->{'cpan'}{lc($original_ebuild)}{'src_uri'}"
531
532
533 IUSE=""
534
535 SLOT="0"
536 LICENSE="|| ( Artistic GPL-2 )"
537 KEYWORDS="$keywords"
538
539 HERE
540
541 if (my @deps = keys %{$gcpan_run->{cpan}{lc($original_ebuild)}{depends}}) {
542 print $EBUILD "DEPEND=\"";
543 my %seen_deps;
544 foreach my $dep (@deps) {
545 defined $dep && $dep ne '' or next;
546 my $portage_name = lc($gcpan_run->{cpan}{lc($dep)}{portage_name});
547 $portage_name =~ /\S/ or next;
548
549 # Last ditch call to scanTree to make sure we
550 # have info
551 scanTree($portage_name);
552 defined($seen_deps{$portage_name}) && $seen_deps{$portage_name} > 0 and next;
553 $seen_deps{$portage_name} = 1;
554 $portage_name eq 'perl' ||
555 lc($portage_name) eq lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) and next;
556 if ( defined($gcpan_run->{cpan}{lc($dep)}{portage_version}) &&
557 $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep} ne '0' &&
558 $gcpan_run->{ebuilds}{portage}{$portage_name}{name} ne "module-build"
559 ) {
560 print $EBUILD "\>\="
561 . $gcpan_run->{ebuilds}{portage}{$portage_name}{category} . '/'
562 . $gcpan_run->{ebuilds}{portage}{$portage_name}{name} . '-'
563 .
564 $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep} . "\n\t";
565 } else {
566 print $EBUILD "\t"
567 . $gcpan_run->{ebuilds}{portage}{$portage_name}{category} . "/"
568 .
569 $gcpan_run->{ebuilds}{portage}{$portage_name}{name} . "\n\t";
570 }
571 }
572 print $EBUILD "dev-lang/perl\"\n";
573 undef $EBUILD;
574 autoflush STDOUT 1;
575 }
576 if (-f $gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball}) {
577 $verbose and print_info($prog, "Copying $gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball} to $gcpan_run->{sources}");
578 copy($gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball}, $gcpan_run->{sources});
579 }
580 print_info($prog, "Ebuild generated for $ebuild_wanted");
581 $gcpan_run->generate_digest($ebuild);
582 if (
583 #MPC!$upgrade
584 #MPCor ($upgrade
585 #MPC&&
586 defined($passed_to_install{$gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'name'}})
587 #MPC )
588 ) {
589 my $portage_name = $gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'portage_name'};
590 $really_install{ $portage_name } = 1;
591 }
592 last;
593 } else {
594 $upgrade and print_info($prog, "$ebuild_wanted already up to date");
595 last;
596 }
597 }
598 }
599 }
600 } else {
601 print_ok($prog, "Ebuild already exists for $ebuild_wanted");
602 defined $passed_to_install{$ebuild_wanted} || defined $passed_to_install{$original_ebuild} and
603 $really_install{$gcpan_run->{'ebuilds'}{'portage'}{lc($ebuild_wanted)}{'name'}} = 1;
604 }
605 }
606
607 sub scanTree {
608 my ($module) = @_;
609 $module or return;
610
611 if ($module =~ /pathtools/gimx) { $module = "File-Spec" }
612 foreach my $portage_root (keys %{$gcpan_run->{portage_bases}}) {
613 $verbose and print_info($prog, "Looking at $portage_root");
614 if (-d $portage_root) {
615 $verbose and print_ok($prog, "Scanning $portage_root for $module");
616 $gcpan_run->getAvailableVersions($portage_root, $module);
617 }
618
619 # Pop out of the loop if we've found the module
620 $gcpan_run->{ebuilds}{found_ebuild}{lc($module)} and last;
621 }
622 }
623
624 # cab - Takes care of system's sanity
625 END {
626
627 #Clean out the /tmp tree we were using
628 #I know this looks weird, but since clean_up is invoked on a search, where OVERLAYS isn't ever defined,
629 # we first need to see if it exists, then need to remove only if it has content (the old exists vs. defined)
630
631 if (defined($ENV{TMPDIR})) {
632 $verbose and print_info($prog, 'Cleaning temporary overlay');
633 my ($startdir) = cwd();
634 chdir("$ENV{TMPDIR}/.cpan");
635 opendir(CURD, '.');
636 my @dirs = readdir(CURD);
637 closedir(CURD);
638 foreach my $dir (@dirs) {
639 $dir eq '.' and next;
640 $dir eq '..' and next;
641 $dir eq 'sources' and next;
642 -d $dir and rmtree(["$ENV{TMPDIR}/$dir"]);
643 }
644 }
645 }
646
647 # cab - nice help message ! ;)
648 sub exit_usage
649 {
650 print <<"USAGE";
651 ${white}Usage : ${cyan}$prog ${green}<Switch(es)> ${cyan}Module Name(s)${reset}
652
653 ${green}--generate,-g${reset}
654 Generate ebuilds only (Requires working overlays)
655
656 ${green}--install,-i${reset}
657 Try to generate ebuild for the given module name
658 and, if successful, emerge it. Important : installation
659 requires exact CPAN Module Name.
660
661 ${green}--list,-l${reset}
662 This command generates a list of the Perl modules and ebuilds
663 handled by $prog.
664
665 ${green}--log,-L${reset}
666 Log the output of $prog.
667
668 ${green}--search,-s${reset}
669 Search CPAN for the given expression (similar to
670 the "m /EXPR/" from the CPAN Shell). Searches are
671 case insensitive.
672
673 ${green}--upgrade,-u${reset}
674 Try to list and upgrade all Perl modules managed by $prog.
675 It generate up-to-date ebuilds, then emerge then.
676
677 ${green}--verbose,-v${reset}
678 Enable (some) verbose output.
679
680 ${green}--cpan_reload${reset}
681 Reload the CPAN index
682
683 ${white}Portage related options${reset}
684
685 ${green}--ask,-a${reset}
686 Ask before installing
687
688 ${green}--buildpkg,-b${reset}
689 Tells emerge to build binary packages for all ebuilds processed
690 in addition to actually merging the packages.
691
692 ${green}--buildpkgonly,-B${reset}
693 Creates binary packages for all ebuilds processed without actu-
694 ally merging the packages.
695
696 ${green}--pretend,-p${reset}
697 Pretend (show actions, but don't emerge). This still generates
698 new ebuilds.
699
700
701 USAGE
702
703 exit;
704 }
705
706 exit;
707
708 ##############
709
710 __END__
711
712 =pod
713
714 =head1 NAME
715
716 g-cpan - install CPAN-provided Perl modules using Gentoo's Portage
717
718 =head1 SYNOPSIS
719
720 B<g-cpan> [B<-a>| B<--ask>] [B<-g>| B<--generate>] [B<-i>| B<--install>] [B<-l>| B<--list >] [B<-p>| B<--pretend >] [B<-s>| B<--search>] [B<-u>| B<--upgrade >] [B<-v>| B<--verbose>] <I<module-name>>
721
722 =head1 DESCRIPTION
723
724 B<g-cpan> is a perl script that installs a CPAN module (including its dependencies) using Gentoo's Portage. It saves dependency information and stored files as if they were installed through a regular ebuild.
725
726 =head1 CPAN Configuration
727
728 B<~/.cpan/CPAN/MyConfig.pm>
729 B</path/to/perl/CPAN/Config.pm>
730
731 When you run B<g-cpan>, it will check for two configuration files. If you are root, it will check for the presense of an already configured CPAN under your perl install path. If CPAN is not configured, or you are not root, g-cpan will create a generic configuration for CPAN in ~/.cpan/CPAN/ called MyConfig.pm. You can modify this file as needed at any time.
732
733 The CPAN configuration file is used for interacting with CPAN, determining what modules are available, what modules are needed, and performing all basic CPAN functions.
734
735 =head1 g-cpan and Overlays
736
737 B<g-cpan> is now overlay "friendly." B<g-cpan> will scan both the overlays provided in your make.conf as well as any you have set via environment variables, to help determine its course of action. If you have defined overlays, B<g-cpan> will use the first overlay in your list that the user running it can write to. Any ebuilds generated by B<g-cpan> will be stored in this overlay for future use (such as upgrading).
738
739 If no overlays are defined, or the user operating B<g-cpan> cannot write to an overlay, then anything generated will be written to a temporary space and wiped on exit.
740
741 =head1 Arguments
742
743 The following arguments are accepted by g-cpan.
744
745 =over 4
746
747 =item B<-g,--generate>
748
749 Generate ebuilds and drop them in the overlay, but never call portage. Useful for generating a tree of ebuilds without having permissions to portage.
750
751 =item B<-i,--install>
752
753 Install the (list of) modules provided.
754
755 =item B<-l,--list>
756
757 List ebuilds that have been generated by g-cpan and reside in your overlay.
758
759 =item B<-L,--log>
760
761 Log all output to /var/log/g-cpan/g-cpan.log and g-cpan.err
762
763 =item B<-s,--search>
764
765 Search CPAN for the provided module.
766
767 =item B<--cpan_reload>
768
769 Reload CPAN's index online
770
771 =item B<-u,--upgrade>
772
773 Attempt to upgrade any ebuilds generated by g-cpan to newer versions. This option will create new ebuilds for those that exist in your overlay already. If a module name is given, it will attempt to only upgrade the requested module. If no arguments are given, all modules in your g-cpan overlay will be checked.
774
775 =item B<-v,--verbose>
776
777 Enable verbose mode for more feedback on the step by step processes that g-cpan is running
778
779 =back
780
781 =head1 Portage Arguments
782
783 The following portage arguments can be passed to g-cpan. Please read the portage documentation for more information on how they work.
784
785 =over 4
786
787 =item B<-a,--ask>
788
789 Pass the "ask" argument to portage. This will cause portage to prompt you to confirm your installation prior to issuing an emerge
790
791 =item B<-b,--buildpkg>
792
793 Tells emerge to build binary packages for all ebuilds processed in addition to actually merging the packages.
794
795 =item B<-B,--buildpkgonly>
796
797 Creates binary packages for all ebuilds processed without actually merging the packages.
798
799 =item B<-p,--pretend>
800
801 Create ebuilds as needed for the (list of) modules provided, but don't perform the actual emerge.
802
803
804 =back
805
806 =head1 Usage
807
808
809 =head2 Here we install Jabber::RPC
810
811 # g-cpan -i Jabber::RPC
812
813 =head2 Performing a search
814
815 # g-cpan -s Clone::Any
816
817 =head2 Upgrading overlay from g-cpan
818
819 # g-cpan -u
820
821 =head2 Upgrading specifc ebuild in overlay from g-cpan
822
823 # g-cpan -u Mickey-Mouse
824
825 =head1 Todo
826
827 =head1 See Also
828
829 L<B<emerge>(1)>, L<B<ebuild>(5)>, L<B<make.conf>(5)>, L<B<perl>(1)>
830
831 =head1 Authors
832
833 mcummings <mcummings@gentoo.org> cab <cab@dragou.net> sniper <sniper@mongueurs.net> beu <beu@gentoo.org> J Robert Ray <jrray@gentoo.org> (g-cpan) RAC <rac@gentoo.org> Sven Vermeulen <swift@gentoo.org> (Original manpage) Damien Krotkine <dams@gentoo.org>
834
835 =head1 Reporting Bugs
836
837 Please report bugs via http://bugs.gentoo.org/ or https://bugs.gentoo.org/
838
839 =head1 svn Id $Id$
840
841 =cut

Properties

Name Value
svn:executable *
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20