Gentoo Archives: gentoo-perl

From: antoine.raillon@××××××.net
To: gentoo-perl@l.g.o
Subject: [gentoo-perl] r29 - in trunk: bin extra-docs
Date: Sun, 15 May 2005 16:44:45
Message-Id: 20050515164407.CF7988280EA@gredin.dragou.net
1 Author: cab
2 Date: 2005-05-15 18:44:07 +0200 (Sun, 15 May 2005)
3 New Revision: 29
4
5 Modified:
6 trunk/bin/g-cpan.pl
7 trunk/extra-docs/Changes
8 Log:
9 - Lots of colours everywhere !
10 - new subs for text formatting
11 - replaced all simple print() call by print_x() ones
12
13
14 Modified: trunk/bin/g-cpan.pl
15 ===================================================================
16 --- trunk/bin/g-cpan.pl 2005-05-15 12:29:15 UTC (rev 28)
17 +++ trunk/bin/g-cpan.pl 2005-05-15 16:44:07 UTC (rev 29)
18 @@ -80,14 +80,14 @@
19
20 # Output error if more than one switch is activated
21 if ( $search + $list + $install + $upgrade > 1 ) {
22 - print
23 -"You can't combine search, list, install or upgrade with each other. Pick up one !\n\n";
24 + print_err(
25 +"You can't combine search, list, install or upgrade with each other. Pick up one !\n");
26 exit_usage();
27 }
28
29 # Output error if no arguments
30 if ( !( defined( $ARGV[0] ) ) and !( defined($upgrade) or defined($list) ) ) {
31 - print "Not even one module name or expression given !\n\n";
32 + print_err ("Not even one module name or expression given !\n");
33 exit_usage();
34 }
35
36 @@ -130,7 +130,7 @@
37 if ( $expr !~ m|::| ) {
38 $expr =~ s/-/::/g;
39 }
40 - print "Searching for $expr on CPAN\n\n";
41 + print_ok ("Searching for $expr on CPAN");
42 CPAN::Shell->m("/$expr/");
43 }
44
45 @@ -172,13 +172,12 @@
46 if ( $OVERLAYS[0] ) {
47 $tmp_overlay_dir = $OVERLAYS[0];
48 if ($verbose) {
49 - print
50 - "Setting $tmp_overlay_dir as the PORTDIR_OVERLAY for this session.\n";
51 + print_info ("Setting $tmp_overlay_dir as the PORTDIR_OVERLAY for this session.");
52 }
53 }
54
55 # Grab the whole available arches list, to include them later in ebuilds
56 -print "Grabbing arch list\n" if $verbose;
57 +print "Grabbing arch list" if $verbose;
58 my $arches = do {
59 open my $tmp, "<$PORTAGE_DIR/profiles/arch.list"
60 or fatal(ERR_OPEN_READ, "$PORTAGE_DIR/profiles/arch.list", $!);
61 @@ -205,7 +204,7 @@
62
63 # Take care of List requests. This should return all the ebuilds managed by g-cpan
64 if ($list) {
65 - printbig "Generating list of modules managed by g-cpan";
66 + print_ok ("Generating list of modules managed by g-cpan");
67 my @managed = get_gcpans();
68 }
69
70 @@ -261,7 +260,7 @@
71 if(lc $file eq lc $dir) {
72 my $cat = basename($sdir);
73 $found = "$cat/$file";
74 - print "$prog: Looking for ebuilds in $sdir, found $found so far.\n" if $verbose;
75 + print_info ("$prog: Looking for ebuilds in $sdir, found $found so far.") if $verbose;
76 close PDIR;
77 last SOURCE_FOLDER;
78 }
79 @@ -288,14 +287,14 @@
80 # Yes - this is potentially a large list of dirs, and we only want the ones containing the tail perl-gcpan
81 # - mcummings
82 if ( basename($sdir) eq "perl-gcpan" ) {
83 - print "OVERLAY: $sdir\n" if $list;
84 + print_info ("OVERLAY: $sdir") if $list;
85 # FIXME Sniper
86 # maybee replace fatal by "warn and next folder" ?
87 opendir PDIR, $sdir or fatal(ERR_FOLDER_OPEN, $sdir, $!);
88 while(my $file = readdir PDIR) {
89 next if $file eq '.'
90 or $file eq '..';
91 - print "perl-gcpan/$file\n" if $list;
92 + print_info ("perl-gcpan/$file") if $list;
93 push @g_list, $file;
94 }
95 closedir PDIR;
96 @@ -333,11 +332,11 @@
97 my $fulldir = File::Spec->catdir( $perldev_overlay, $dir );
98 my $filesdir = File::Spec->catdir( $fulldir, 'files' );
99 unless ( -d $fulldir ) {
100 - print "Create folder '$fulldir'\n" if $verbose;
101 + print_info ("Create folder '$fulldir'") if $verbose;
102 mkdir($fulldir, 0755) or fatal(ERR_FOLDER_CREATE, $fulldir, $!);
103 }
104 unless ( -d $filesdir ) {
105 - print "Create folder '$filesdir'\n" if $verbose;
106 + print_info ("Create folder '$filesdir'") if $verbose;
107 mkdir($filesdir, 0755) or fatal(ERR_FOLDER_CREATE, $filesdir, $!);
108 }
109
110 @@ -346,7 +345,7 @@
111 # CGI::Builder's '1.26+' version breaks portage
112 #unless ( $file =~ m/(.*)\/(.*?)(-?)([0-9\.]+).*\.(?:tar|tgz|zip|bz2|gz)/ ) { MPC
113 unless ( $file =~ m/.*\/.*?-?[0-9\.]+.*\.?:tar|tgz|zip|bz2|gz/ ) {
114 - warn("Couldn't turn '$file' into an ebuild name\n");
115 + warn("Couldn't turn '$file' into an ebuild name");
116 return;
117 }
118
119 @@ -372,7 +371,7 @@
120
121 my $desc = $module->description || 'No description available.';
122
123 - print "Writing to $ebuild\n" if ($verbose);
124 + print_ok ("Writing to $ebuild") if ($verbose);
125 open EBUILD, ">$ebuild" or fatal(ERR_OPEN_WRITE, $ebuild, $!);
126 print EBUILD <<"HERE";
127
128 @@ -447,7 +446,7 @@
129
130 my $file = $obj->cpan_file;
131 my $dir = portage_dir($obj);
132 - print "$prog: portage_dir returned $dir\n" if ($verbose);
133 + print_info ("$prog: portage_dir returned $dir") if ($verbose);
134 unless ($dir) {
135 warn("Couldn't turn '$file' into a directory name\n");
136 return;
137 @@ -465,15 +464,15 @@
138 return;
139 }
140 elsif ( !defined $recursive && module_check($module_name) ) {
141 - printbig "Module already installed for '$module_name'\n";
142 + print_warn ("Module already installed for '$module_name'");
143 return;
144 }
145 elsif ( $dir eq 'perl' ) {
146 - printbig "Module '$module_name' is part of the base perl install\n";
147 + print_warn ("Module '$module_name' is part of the base perl install");
148 return;
149 }
150
151 - printbig "Need to create ebuild for '$module_name': $dir\n";
152 + print_ok ("Need to create ebuild for '$module_name': $dir");
153
154 # check depends ... with CPAN have to make the module
155 # before it can tell us what the depends are, this stinks
156 @@ -527,7 +526,7 @@
157 if ( $module_name !~ m|::| ) {
158 $module_name =~ s/-/::/g;
159 } # Assume they gave us module-name instead of module::name
160 - print "Looking for $module_name...\n";
161 + print_info ("Looking for $module_name...");
162 my $obj = CPAN::Shell->expandany($module_name);
163 unless ( ( ref $obj eq "CPAN::Module" ) || ( ref $obj eq "CPAN::Bundle" ) )
164 {
165 @@ -537,72 +536,74 @@
166
167 my $file = $obj->cpan_file;
168 my $dir = portage_dir($obj);
169 - print "$prog: portage_dir returned $dir\n" if ($verbose);
170 + print_info ("$prog: portage_dir returned $dir") if ($verbose);
171 unless ($dir) {
172 warn("Couldn't turn '$file' into a directory name\n");
173 return;
174 }
175
176 unless ( ebuild_exists($dir) ) {
177 - printbig "No ebuild available for '$module_name': "
178 - . &ebuild_exists($dir) . "\n";
179 + print_warn ("No ebuild available for '$module_name': " . &ebuild_exists($dir));
180 return;
181 }
182 elsif ( defined $recursive && !module_check($module_name) ) {
183 - printbig "No module installed for '$module_name'\n";
184 + print_warn ("No module installed for '$module_name'");
185 return;
186 }
187 elsif ( $dir eq 'perl' ) {
188 - printbig
189 -"Module '$module_name' is part of the base perl install - we don't touch perl here\n";
190 + print_err
191 +("Module '$module_name' is part of the base perl install - we don't touch perl here");
192 return;
193 }
194
195 - printbig "Checking ebuild for '$module_name': $dir\n";
196 + print_info ("Checking ebuild for '$module_name': $dir");
197 my $fullname = ebuild_exists($dir);
198
199 if (dirname($fullname) eq "perl-gcpan") {
200 - # check depends ... with CPAN have to make the module
201 - # before it can tell us what the depends are, this stinks
202 +
203 + # check depends ... with CPAN have to make the module
204 + # before it can tell us what the depends are, this stinks
205
206 - $CPAN::Config->{prerequisites_policy} = "";
207 - $CPAN::Config->{inactivity_timeout} = 30;
208 + $CPAN::Config->{prerequisites_policy} = "";
209 + $CPAN::Config->{inactivity_timeout} = 30;
210
211 - my $pack = $CPAN::META->instance( 'CPAN::Distribution', $file );
212 - $pack->called_for( $obj->id );
213 - $pack->make;
214 + my $pack = $CPAN::META->instance( 'CPAN::Distribution', $file );
215 + $pack->called_for( $obj->id );
216 + $pack->make;
217
218 - # A cheap ploy, but this lets us add module-build as needed
219 - # instead of forcing it on everyone
220 - my $add_mb = 0;
221 - if ( -f "Build.PL" ) { $add_mb = 1 }
222 - $pack->unforce if $pack->can("unforce") && exists $obj->{'force_update'};
223 - delete $obj->{'force_update'};
224 + # A cheap ploy, but this lets us add module-build as needed
225 + # instead of forcing it on everyone
226 + my $add_mb = 0;
227 + if ( -f "Build.PL" ) { $add_mb = 1 }
228 + $pack->unforce if $pack->can("unforce") && exists $obj->{'force_update'};
229 + delete $obj->{'force_update'};
230
231 - # grab the MD5 checksum for the source file now
232 + # grab the MD5 checksum for the source file now
233
234 - my $localfile = $pack->{localfile};
235 - ( my $base = $file ) =~ s/.*\/(.*)/$1/;
236 + my $localfile = $pack->{localfile};
237 + ( my $base = $file ) =~ s/.*\/(.*)/$1/;
238
239 + my $md5string = sprintf "MD5 %s %s %d", file_md5sum($localfile), $base, -s $localfile;
240
241 - my $md5string = sprintf "MD5 %s %s %d", file_md5sum($localfile), $base, -s $localfile;
242 + # make ebuilds for all the prereqs
243 + my $prereq_pm = $pack->prereq_pm;
244 + if ($add_mb) { $prereq_pm->{'Module::Build'} = "0" }
245 + install_module( $_, 1 ) for ( keys %$prereq_pm );
246
247 - # make ebuilds for all the prereqs
248 - my $prereq_pm = $pack->prereq_pm;
249 - if ($add_mb) { $prereq_pm->{'Module::Build'} = "0" }
250 - install_module( $_, 1 ) for ( keys %$prereq_pm );
251 + # get the build dir from CPAN, this will tell us definitively
252 + # what we should set S to in the ebuild
253 + # strip off the path element
254 + ( my $build_dir = $pack->{build_dir} ) =~ s|.*/||;
255
256 - # get the build dir from CPAN, this will tell us definitively
257 - # what we should set S to in the ebuild
258 - # strip off the path element
259 - ( my $build_dir = $pack->{build_dir} ) =~ s|.*/||;
260 -
261 - create_ebuild( $obj, $dir, $file, $build_dir, $prereq_pm, $md5string );
262 - unless ( -f "$PORTAGE_DISTDIR/$localfile" ) {
263 - system( '/bin/mv', '-f', $localfile, $PORTAGE_DISTDIR );
264 + create_ebuild( $obj, $dir, $file, $build_dir, $prereq_pm, $md5string );
265 + unless ( -f "$PORTAGE_DISTDIR/$localfile" ) {
266 + system( '/bin/mv', '-f', $localfile, $PORTAGE_DISTDIR );
267 + }
268 + push @ebuild_list, "perl-gcpan/$dir";
269 }
270 - push @ebuild_list, "perl-gcpan/$dir";
271 - } else { push @ebuild_list, "$fullname" }
272 + else {
273 + push @ebuild_list, "$fullname";
274 + }
275
276 }
277
278 @@ -611,10 +612,10 @@
279 push @flags, "-p" if $pretend > 0;
280 push @flags, "-u" if $upgrade > 0;
281 push @flags, "--ask" if $ask > 0;
282 - print "Calling: emerge --oneshot --digest @ebuild_list\n" if ($verbose);
283 - # FIXME Sniper
284 - # check return values
285 - system( "emerge",@flags, "--oneshot", "--digest", @ebuild_list );
286 + print_info ("Calling: emerge --oneshot --digest @ebuild_list") if ($verbose);
287 + # FIXME Sniper
288 + # check return values
289 + system( "emerge", @flags, "--oneshot", "--digest", @ebuild_list );
290 }
291
292 sub get_globals {
293 @@ -688,7 +689,7 @@
294 my $cpan_cfg_dir = File::Spec->catfile($ENV{HOME}, CPAN_CFG_DIR);
295 my $cpan_cfg_file = File::Spec->catfile($cpan_cfg_dir, CPAN_CFG_NAME);
296
297 - printbig "No CPAN Config found, auto-generating a basic one in $cpan_cfg_dir\n";
298 + print_warn ("No CPAN Config found, auto-generating a basic one in $cpan_cfg_dir");
299 if(not -d $cpan_cfg_dir) {
300 mkpath($cpan_cfg_dir, 1, 0755 ) or fatal(ERR_FOLDER_CREATE, $cpan_cfg_dir, $!);
301 }
302 @@ -767,6 +768,8 @@
303 sub printbig {
304 # FIXME cab
305 # Rewrite using colors !
306 +# FIXING - cab
307 +# This sub should'nt be used now.
308 # FIXME Sniper
309 # 72 hard coded is bad
310 print '*' x 72, "\n";
311 @@ -778,6 +781,24 @@
312 print '*' x 72, "\n";
313 }
314
315 +
316 +# cab - four (very fast) subs to help formating text output. Guess they could be improved a lot
317 +# maybe i should add a FIXME - Sniper around here.. :)
318 +# anyway, they expect a string and add a colored star at the beginning and the CR/LF
319 +# at the end of the line. oh, shiny world ;)
320 +sub print_ok {
321 + print color("bold green"), "* ", color("reset"), @_, "\n";
322 +}
323 +sub print_info {
324 + print color("bold cyan"), "* ", color("reset"), @_, "\n";
325 +}
326 +sub print_warn {
327 + print color("bold yellow"), "* ", color("reset"), @_, "\n";
328 +}
329 +sub print_err{
330 + print color("bold red"), "* ", color("reset"), @_, "\n";
331 +}
332 +
333 #################################################
334 # NAME : fatal
335 # AUTHOR: David "Sniper" Rigaudiere
336 @@ -798,7 +819,7 @@
337 # FIXME cab : add a test (if -f $file) ?
338 sub file_md5sum {
339 my ($file) = @_;;
340 - print "Computing MD5 Sum of $file\n" if $verbose;
341 + print_info ("Computing MD5 Sum of $file") if $verbose;
342
343 open DIGIFILE, $file or fatal(ERR_OPEN_READ, $file, $!);
344 my $md5digest = Digest::MD5->new->addfile(*DIGIFILE)->hexdigest;
345 @@ -835,7 +856,7 @@
346 # should try to see if it can be merged with clean_up()
347 sub clean_the_mess {
348 if ($verbose) {
349 - print "Now cleaning up the system of all the junk we put in !\n";
350 + print_info ("Now cleaning up the system of all the junk we put in !");
351 }
352 if ($needs_cpan_stub) {
353 unlink "$ENV{HOME}/.cpan/CPAN/MyConfig.pm";
354
355 Modified: trunk/extra-docs/Changes
356 ===================================================================
357 --- trunk/extra-docs/Changes 2005-05-15 12:29:15 UTC (rev 28)
358 +++ trunk/extra-docs/Changes 2005-05-15 16:44:07 UTC (rev 29)
359 @@ -1,3 +1,9 @@
360 +15/05/2005 - cab in wonderland
361 +
362 +- Lots of colours everywhere !
363 +- new subs for text formatting
364 +- replaced all simple print() call by print_x() ones
365 +
366 15/05/2005 - mcummings
367
368 - Removed sub that was no longer being invoked (had cleaned up the code for this last week)
369
370
371 --
372 gentoo-perl@g.o mailing list