/[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 125 - (show annotations) (download)
Sun Dec 10 12:30:23 2006 UTC (7 years, 9 months ago) by mcummings
File size: 30628 byte(s)
Bug 152604 - the grep on line 194 wasn't working as expected. Modified to a simple matching regex and now it writes correctly.


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 ( $data =~ m{gcpan}gmxi ) {
195 my $cat_write = IO::File->new($cat_file, '>>');
196 if (defined $cat_write) {
197 print $cat_write "perl-gcpan\n";
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 print_ok($prog, "OVERLAY: $gcpan_dir");
347 if (opendir PDIR, $gcpan_dir) {
348 while (my $file = readdir PDIR) {
349 $file eq '.' || $file eq '..' and next;
350 $list and print_info($prog, "perl-gcpan/$file");
351 $upgrade and print_info($prog, "Adding $file to install list");
352 $upgrade and $passed_to_install{$file} = 1;
353 $debug and print_info($prog,"Passed: $file");
354 }
355 closedir PDIR;
356 } else {
357 print_warn($prog, "Couldn't open folder $gcpan_dir: $!");
358 }
359 }
360 }
361 }
362
363 if ( $generate
364 || $install
365 || $pretend
366 || $buildpkg
367 || $buildpkgonly
368 || $ask
369 || $upgrade) {
370 generatePackageInfo($_) foreach (keys %passed_to_install)
371 }
372
373 if ($install || $pretend || $buildpkg || $buildpkgonly || $upgrade || $ask) {
374 if (keys %really_install) {
375
376 my @ebuilds = (keys %really_install);
377 $verbose and print_ok($prog, "Calling emerge for @ebuilds\n");
378 my @flags;
379 if ($pretend && $pretend > 0) {push @flags, '--pretend' }
380 if ($ask && $ask > 0) { push @flags, '--ask' }
381 if ($buildpkg && $buildpkg > 0 ) {push @flags, '--buildpkg' }
382 if ($buildpkgonly && $buildpkgonly > 0 ) { push @flags, '--buildpkgonly' }
383
384 $verbose and print_info($prog, "Calling: emerge @flags @ebuilds");
385 $gcpan_run->emerge_ebuild(@ebuilds, @flags);
386
387 } else {
388 if ($upgrade) {
389 print_info($prog, 'Everything was up to date, nothing to do!');
390 } else {
391 print_err($prog, 'Nothing to install!!');
392 }
393 }
394 }
395
396 sub generatePackageInfo {
397
398 # Since all we are concerned with is the final name of the package, this
399 # should be a safe substitution
400 my ($ebuild_wanted) = @_;
401 $ebuild_wanted =~ /ExtUtils(::|-)MakeMaker/i and
402 print_info($prog, 'Skipping ExtUtils::MakeMaker dependency'), next;
403
404 #In the event this is an upgrade, go ahead and do the lame s/-/::/
405 $upgrade and $ebuild_wanted =~ s/-/::/gxms;
406
407 # Grab specific info for this module
408 $gcpan_run->{ebuilds}{found_ebuild}{lc($ebuild_wanted)} or
409 $gcpan_run->getCPANInfo($ebuild_wanted);
410 if ( ! $gcpan_run->{cpan}{lc($ebuild_wanted)} && ! $gcpan_run->{ebuilds}{found_ebuild}{lc($ebuild_wanted)} ) {
411
412 # Fallback to trying the /-/::/ trick - we avoid this the first time
413 # in case the module actually employs a - in its name
414 $ebuild_wanted =~ s/-/::/gxms;
415 $verbose and print_info($prog,"Getting CPAN Info for $ebuild_wanted");
416 $gcpan_run->getCPANInfo($ebuild_wanted);
417 }
418
419 # If we found something on cpan, transform the portage_name
420 # It's possible to not find something on cpan at this point - we're just
421 # trying to pre-seed the portage_name
422 if ($gcpan_run->{cpan}{lc($ebuild_wanted)}) {
423 $gcpan_run->{cpan}{lc($ebuild_wanted)}{portage_name} = $gcpan_run->transformCPAN($gcpan_run->{cpan}{lc($ebuild_wanted)}{src_uri}, 'n');
424 $gcpan_run->{cpan}{lc($ebuild_wanted)}{portage_version} = $gcpan_run->transformCPAN($gcpan_run->{cpan}{lc($ebuild_wanted)}{src_uri}, 'v');
425 } else {
426 print_err($prog, "$ebuild_wanted is not a CPAN module!");
427 #MPC hold return;
428 }
429
430 # Save a copy of the originally requested name for later use
431 my $original_ebuild = $ebuild_wanted;
432
433 # Simple transform of name to something portage friendly
434 $ebuild_wanted =~ s/::/-/gxms;
435
436 # Scan portage for the ebuild name
437 if ( $upgrade && defined($passed_to_install{$ebuild_wanted}) ) { scanTree($ebuild_wanted) }
438 if ( ! ( $gcpan_run->{ebuilds}{found_ebuild}{lc($ebuild_wanted)}
439 || ($upgrade && defined($passed_to_install{$ebuild_wanted})) ) ) {
440
441 # Ebuild wasn't found - scan for the nice version of the module name
442 lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) eq 'perl' and next;
443 scanTree($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name});
444
445 # We had success in finding this module under a different name
446 if ($gcpan_run->{ebuilds}{found_ebuild}{lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name})}) {
447 $verbose and print_info($prog, 'Found ebuild under CPAN name (' . $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} . ')');
448 $ebuild_wanted = $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name};
449 }
450 } else {
451 $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} = $ebuild_wanted;
452 }
453
454 # Second round - we've looked for the package in portage two different
455 # ways now, time to get serious and create it ourselves
456 if ( ! $gcpan_run->{ebuilds}{found_ebuild}{lc($ebuild_wanted)} ) {
457
458 # Generate info - nothing found currently in the tree
459 $debug and $gcpan_run->debug;
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 if ($original_ebuild =~ m/filter-simple/mgix)
549 { print_err($prog, "$portage_name is being passed");}
550
551 # Last ditch call to scanTree to make sure we
552 # have info
553 scanTree($portage_name);
554 defined($seen_deps{$portage_name}) && $seen_deps{$portage_name} > 0 and next;
555 $seen_deps{$portage_name} = 1;
556 next unless ( defined
557 ($gcpan_run->{ebuilds}{portage}{$portage_name}{category})
558 and defined (
559 $gcpan_run->{ebuilds}{portage}{$portage_name}{name}
560 ) && (
561 $gcpan_run->{ebuilds}{portage}{$portage_name}{name}
562 =~ m/\S/));
563 $portage_name eq 'perl' ||
564 lc($portage_name) eq lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) and next;
565 if ( defined($gcpan_run->{cpan}{lc($dep)}{portage_version}) &&
566 $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep} ne '0' &&
567 $gcpan_run->{ebuilds}{portage}{$portage_name}{name} ne "module-build"
568 ) {
569 print $EBUILD "\>\="
570 . $gcpan_run->{ebuilds}{portage}{$portage_name}{category} . '/'
571 . $gcpan_run->{ebuilds}{portage}{$portage_name}{name} . '-'
572 .
573 $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep} . "\n\t";
574 } else {
575 print $EBUILD "\t"
576 . $gcpan_run->{ebuilds}{portage}{$portage_name}{category} . "/"
577 .
578 $gcpan_run->{ebuilds}{portage}{$portage_name}{name} . "\n\t";
579 }
580 }
581 print $EBUILD "dev-lang/perl\"\n";
582 undef $EBUILD;
583 autoflush STDOUT 1;
584 }
585 if (-f $gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball}) {
586 $verbose and print_info($prog, "Copying $gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball} to $gcpan_run->{sources}");
587 copy($gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball}, $gcpan_run->{sources});
588 }
589 print_info($prog, "Ebuild generated for $ebuild_wanted");
590 $gcpan_run->generate_digest($ebuild);
591 if (
592 !$upgrade
593 or ($upgrade
594 &&
595 defined($passed_to_install{$gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'name'}})
596 )
597 ) {
598 my $portage_name = $gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'portage_name'};
599 $really_install{ $portage_name } = 1;
600 }
601 last;
602 } else {
603 $upgrade and print_info($prog, "$ebuild_wanted already up to date");
604 last;
605 }
606 }
607 }
608 }
609 } else {
610 print_ok($prog, "Ebuild already exists for $ebuild_wanted");
611 defined $passed_to_install{$ebuild_wanted} || defined $passed_to_install{$original_ebuild} and
612 $really_install{$gcpan_run->{'ebuilds'}{'portage'}{lc($ebuild_wanted)}{'name'}} = 1;
613 }
614 }
615
616 sub scanTree {
617 my ($module) = @_;
618 $module or return;
619
620 if ($module =~ /pathtools/gimx) { $module = "File-Spec" }
621 foreach my $portage_root (keys %{$gcpan_run->{portage_bases}}) {
622 $verbose and print_info($prog, "Looking at $portage_root");
623 if (-d $portage_root) {
624 $verbose and print_ok($prog, "Scanning $portage_root for $module");
625 $gcpan_run->getAvailableVersions($portage_root, $module);
626 }
627
628 # Pop out of the loop if we've found the module
629 $gcpan_run->{ebuilds}{found_ebuild}{lc($module)} and last;
630 }
631 }
632
633 # cab - Takes care of system's sanity
634 END {
635
636 #Clean out the /tmp tree we were using
637 #I know this looks weird, but since clean_up is invoked on a search, where OVERLAYS isn't ever defined,
638 # we first need to see if it exists, then need to remove only if it has content (the old exists vs. defined)
639
640 if (defined($ENV{TMPDIR})) {
641 $verbose and print_info($prog, 'Cleaning temporary overlay');
642 my ($startdir) = cwd();
643 chdir("$ENV{TMPDIR}/.cpan");
644 opendir(CURD, '.');
645 my @dirs = readdir(CURD);
646 closedir(CURD);
647 foreach my $dir (@dirs) {
648 $dir eq '.' and next;
649 $dir eq '..' and next;
650 $dir eq 'sources' and next;
651 -d $dir and rmtree(["$ENV{TMPDIR}/$dir"]);
652 }
653 }
654 }
655
656 # cab - nice help message ! ;)
657 sub exit_usage
658 {
659 print <<"USAGE";
660 ${white}Usage : ${cyan}$prog ${green}<Switch(es)> ${cyan}Module Name(s)${reset}
661
662 ${green}--generate,-g${reset}
663 Generate ebuilds only (Requires working overlays)
664
665 ${green}--install,-i${reset}
666 Try to generate ebuild for the given module name
667 and, if successful, emerge it. Important : installation
668 requires exact CPAN Module Name.
669
670 ${green}--list,-l${reset}
671 This command generates a list of the Perl modules and ebuilds
672 handled by $prog.
673
674 ${green}--log,-L${reset}
675 Log the output of $prog.
676
677 ${green}--search,-s${reset}
678 Search CPAN for the given expression (similar to
679 the "m /EXPR/" from the CPAN Shell). Searches are
680 case insensitive.
681
682 ${green}--upgrade,-u${reset}
683 Try to list and upgrade all Perl modules managed by $prog.
684 It generate up-to-date ebuilds, then emerge then.
685
686 ${green}--verbose,-v${reset}
687 Enable (some) verbose output.
688
689 ${green}--cpan_reload${reset}
690 Reload the CPAN index
691
692 ${white}Portage related options${reset}
693
694 ${green}--ask,-a${reset}
695 Ask before installing
696
697 ${green}--buildpkg,-b${reset}
698 Tells emerge to build binary packages for all ebuilds processed
699 in addition to actually merging the packages.
700
701 ${green}--buildpkgonly,-B${reset}
702 Creates binary packages for all ebuilds processed without actu-
703 ally merging the packages.
704
705 ${green}--pretend,-p${reset}
706 Pretend (show actions, but don't emerge). This still generates
707 new ebuilds.
708
709
710 USAGE
711
712 exit;
713 }
714
715 exit;
716
717 ##############
718
719 __END__
720
721 =pod
722
723 =head1 NAME
724
725 g-cpan - install CPAN-provided Perl modules using Gentoo's Portage
726
727 =head1 SYNOPSIS
728
729 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>>
730
731 =head1 DESCRIPTION
732
733 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.
734
735 =head1 CPAN Configuration
736
737 B<~/.cpan/CPAN/MyConfig.pm>
738 B</path/to/perl/CPAN/Config.pm>
739
740 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.
741
742 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.
743
744 =head1 g-cpan and Overlays
745
746 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).
747
748 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.
749
750 =head1 Arguments
751
752 The following arguments are accepted by g-cpan.
753
754 =over 4
755
756 =item B<-g,--generate>
757
758 Generate ebuilds and drop them in the overlay, but never call portage. Useful for generating a tree of ebuilds without having permissions to portage.
759
760 =item B<-i,--install>
761
762 Install the (list of) modules provided.
763
764 =item B<-l,--list>
765
766 List ebuilds that have been generated by g-cpan and reside in your overlay.
767
768 =item B<-L,--log>
769
770 Log all output to /var/log/g-cpan/g-cpan.log and g-cpan.err
771
772 =item B<-s,--search>
773
774 Search CPAN for the provided module.
775
776 =item B<--cpan_reload>
777
778 Reload CPAN's index online
779
780 =item B<-u,--upgrade>
781
782 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.
783
784 =item B<-v,--verbose>
785
786 Enable verbose mode for more feedback on the step by step processes that g-cpan is running
787
788 =back
789
790 =head1 Portage Arguments
791
792 The following portage arguments can be passed to g-cpan. Please read the portage documentation for more information on how they work.
793
794 =over 4
795
796 =item B<-a,--ask>
797
798 Pass the "ask" argument to portage. This will cause portage to prompt you to confirm your installation prior to issuing an emerge
799
800 =item B<-b,--buildpkg>
801
802 Tells emerge to build binary packages for all ebuilds processed in addition to actually merging the packages.
803
804 =item B<-B,--buildpkgonly>
805
806 Creates binary packages for all ebuilds processed without actually merging the packages.
807
808 =item B<-p,--pretend>
809
810 Create ebuilds as needed for the (list of) modules provided, but don't perform the actual emerge.
811
812
813 =back
814
815 =head1 Usage
816
817
818 =head2 Here we install Jabber::RPC
819
820 # g-cpan -i Jabber::RPC
821
822 =head2 Performing a search
823
824 # g-cpan -s Clone::Any
825
826 =head2 Upgrading overlay from g-cpan
827
828 # g-cpan -u
829
830 =head2 Upgrading specifc ebuild in overlay from g-cpan
831
832 # g-cpan -u Mickey-Mouse
833
834 =head1 Todo
835
836 =head1 See Also
837
838 L<B<emerge>(1)>, L<B<ebuild>(5)>, L<B<make.conf>(5)>, L<B<perl>(1)>
839
840 =head1 Authors
841
842 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>
843
844 =head1 Reporting Bugs
845
846 Please report bugs via http://bugs.gentoo.org/ or https://bugs.gentoo.org/
847
848 =head1 svn Id $Id$
849
850 =cut

Properties

Name Value
svn:executable *
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20