/[gentoo-perl]/g-cpan/branches/test-branch/bin/g-cpan
Gentoo

Contents of /g-cpan/branches/test-branch/bin/g-cpan

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20