/[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 90 - (show annotations) (download)
Wed Aug 2 01:27:42 2006 UTC (8 years ago) by mcummings
File size: 30931 byte(s)
Last commit for 0.14.0. 


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20