1 |
Author: mcummings |
2 |
Date: 2005-05-12 01:24:06 +0200 (Thu, 12 May 2005) |
3 |
New Revision: 19 |
4 |
|
5 |
Modified: |
6 |
Changes |
7 |
code/g-cpan.pl |
8 |
Log: |
9 |
Need sleep at this point, read Changes for the highlights, mostly working on fixing bugs with emerging multiple packages, and cleaner call to emerge in general, plus actually cutting out some of my horrid regex's for already used modules |
10 |
|
11 |
|
12 |
|
13 |
Modified: Changes |
14 |
=================================================================== |
15 |
--- Changes 2005-05-11 18:58:05 UTC (rev 18) |
16 |
+++ Changes 2005-05-11 23:24:06 UTC (rev 19) |
17 |
@@ -1,5 +1,8 @@ |
18 |
11/05/2005 - mcummings makes weird changes |
19 |
|
20 |
+- cleaned up calls to merge, added -p,-a,-n,-u flags to respective portions |
21 |
+- Removed the "for (@ARGV) to the call for emerge*module subs - all this was doing was forcing us to call emerge multiple times; the actual subs weren't using @ARGV, but using @ebuild_list, which was already populated elsewhere with all of the modules we wanted plus their generated deps. |
22 |
+- moved list function so that it was called *after* we define the list of dirs to check |
23 |
- added basename so program name was pretty (beu) |
24 |
- To explain my changes for that dir read -noticed when traversing for multiple files that the directory list checked was decreasing in size each pass until it was only checking one directory chain in the end. Pushing it all into a single array that's built temporarily, while ugly, seems to work. This was all due to a bug in modules like Bundle-W3C-Validator (go ahead and try with the old code). Sorry for the kludges, thanks snip for the regex help |
25 |
|
26 |
|
27 |
Modified: code/g-cpan.pl |
28 |
=================================================================== |
29 |
--- code/g-cpan.pl 2005-05-11 18:58:05 UTC (rev 18) |
30 |
+++ code/g-cpan.pl 2005-05-11 23:24:06 UTC (rev 19) |
31 |
@@ -82,7 +82,7 @@ |
32 |
############################### |
33 |
|
34 |
# Init all options |
35 |
-my ( $verbose, $search, $install, $upgrade, $list ) = ( 0, 0, 0, 0, 0 ); |
36 |
+my ( $verbose, $search, $install, $upgrade, $list, $pretend, $ask, $noclean ) = ( 0, 0, 0, 0, 0, 0, 0, 0 ); |
37 |
|
38 |
#Get & Parse them |
39 |
GetOptions( |
40 |
@@ -91,6 +91,9 @@ |
41 |
'install|i' => \$install, |
42 |
'upgrade|u' => \$upgrade, |
43 |
'list|l' => \$list, |
44 |
+ 'pretend|p' => \$pretend, |
45 |
+ 'ask|a' => \$ask, |
46 |
+ 'noclean|n' => \$noclean, |
47 |
'help|h' => sub { exit_usage(); } |
48 |
) |
49 |
or exit_usage(); |
50 |
@@ -103,7 +106,7 @@ |
51 |
} |
52 |
|
53 |
# Output error if no arguments |
54 |
-if ( !( defined( $ARGV[0] ) ) and ( !($upgrade) or !($list) ) ) { |
55 |
+if ( !( defined( $ARGV[0] ) ) and !( defined($upgrade) or defined($list) ) ) { |
56 |
print "Not even one module name or expression given !\n\n"; |
57 |
exit_usage(); |
58 |
} |
59 |
@@ -126,16 +129,10 @@ |
60 |
CPAN::Shell->m("/$expr/"); |
61 |
} |
62 |
|
63 |
- clean_the_mess(); |
64 |
+ clean_the_mess() unless $noclean; |
65 |
exit; |
66 |
} |
67 |
|
68 |
-# Take care of List requests. This should return all the ebuilds managed by g-cpan |
69 |
-if ($list) { |
70 |
- print "List function not implemented yet.\n"; |
71 |
- exit_usage(); |
72 |
-} |
73 |
- |
74 |
# Set our temporary overlay directory for the scope of this run. |
75 |
# By setting an overlay directory, we bypass the predefined portage |
76 |
# directory and allow portage to build a package outside of its |
77 |
@@ -202,25 +199,34 @@ |
78 |
$ENV{PORTDIR_OVERLAY} = $tmp_overlay_dir; |
79 |
|
80 |
# sub main.. well, sort of ;p |
81 |
+# Take care of List requests. This should return all the ebuilds managed by g-cpan |
82 |
+if ($list) { |
83 |
+ printbig "Generating list of modules managed by g-cpan"; |
84 |
+ my @managed = get_gcpans(); |
85 |
+# print "@managed \n" for @managed; |
86 |
+# print "List function not implemented yet.\n"; |
87 |
+# exit_usage(); |
88 |
+} |
89 |
+ |
90 |
if ($install) { |
91 |
install_module($_) for (@ARGV); |
92 |
- emerge_module($_) for (@ARGV); |
93 |
+ emerge_module(); |
94 |
} |
95 |
|
96 |
if ($upgrade) { |
97 |
if (@ARGV) { |
98 |
upgrade_module($_) for (@ARGV); |
99 |
- emerge_up_module($_) for (@ARGV); |
100 |
+ emerge_module($_); |
101 |
} |
102 |
else { |
103 |
my @GLIST = get_gcpans(); |
104 |
upgrade_module($_) for (@GLIST); |
105 |
- emerge_up_module(@GLIST); |
106 |
+ emerge_module(@GLIST); |
107 |
} |
108 |
} |
109 |
|
110 |
if($install or $upgrade) { |
111 |
- clean_up(); |
112 |
+ clean_up() unless $noclean; |
113 |
} |
114 |
|
115 |
exit; |
116 |
@@ -243,7 +249,7 @@ |
117 |
} |
118 |
|
119 |
sub ebuild_exists { |
120 |
- my ($dir) = lc $_[0]; |
121 |
+ my ($dir) = $_[0]; |
122 |
|
123 |
# need to try harder here - see &portage_dir comments. |
124 |
# should return an ebuild name from this, as case matters. |
125 |
@@ -264,8 +270,9 @@ |
126 |
next if not -d $sdir; |
127 |
opendir PDIR, $sdir or fatal(ERR_FOLDER_OPEN, $sdir, $!); |
128 |
while(my $file = readdir PDIR) { |
129 |
- if(lc $file eq $dir) { |
130 |
- $found = $dir; |
131 |
+ if(lc $file eq lc $dir) { |
132 |
+ my $cat = basename($sdir); |
133 |
+ $found = "$cat/$file"; |
134 |
print "$prog: Looking for ebuilds in $sdir, found $found so far.\n" if $verbose; |
135 |
close PDIR; |
136 |
last SOURCE_FOLDER; |
137 |
@@ -274,7 +281,7 @@ |
138 |
closedir PDIR; |
139 |
} |
140 |
|
141 |
- # check for ebuilds that have been created by g-cpan.pl |
142 |
+ # check for ebuilds that have been created by g-cpan.pl - in THIS session |
143 |
for my $ebuild (@ebuild_list) { |
144 |
if($ebuild eq $dir) { |
145 |
$found = $ebuild; |
146 |
@@ -290,13 +297,17 @@ |
147 |
foreach my $sdir ( grep { -d $_ } ( @PORTAGE_DEV_PERL, @OVERLAY_PERLS ) ) { |
148 |
# FIXME Sniper |
149 |
# Do we really need regexp here ? |
150 |
- if ( $sdir =~ m/perl-gcpan/ ) { |
151 |
+ # Yes - this is potentially a large list of dirs, and we only want the ones containing the tail perl-gcpan |
152 |
+ # - mcummings |
153 |
+ if ( basename($sdir) eq "perl-gcpan" ) { |
154 |
+ print "OVERLAY: $sdir\n" if $list; |
155 |
# FIXME Sniper |
156 |
# maybee replace fatal by "warn and next folder" ? |
157 |
opendir PDIR, $sdir or fatal(ERR_FOLDER_OPEN, $sdir, $!); |
158 |
while(my $file = readdir PDIR) { |
159 |
next if $file eq '.' |
160 |
or $file eq '..'; |
161 |
+ print "perl-gcpan/$file\n" if $list; |
162 |
push @g_list, $file; |
163 |
} |
164 |
closedir PDIR; |
165 |
@@ -464,9 +475,8 @@ |
166 |
|
167 |
# remove trailing .pm to fix emerge breakage. |
168 |
$dir =~ s/.pm$//; |
169 |
- print "Testing $dir\n"; |
170 |
- $dir = build_catdep($dir); |
171 |
- print "Adding $dir unless $first\n"; |
172 |
+ #$dir = build_catdep($dir); |
173 |
+ $dir = ebuild_exists($dir); |
174 |
print EBUILD "\n\t" unless $first; |
175 |
print EBUILD "$dir"; |
176 |
} |
177 |
@@ -504,9 +514,15 @@ |
178 |
return; |
179 |
} |
180 |
|
181 |
- if ( ebuild_exists($dir) ) { |
182 |
- printbig "Ebuild already exists for '$module_name': " |
183 |
- . &ebuild_exists($dir) . "\n"; |
184 |
+ if ( my $exists = ebuild_exists($dir) ) { |
185 |
+ # Instead of exiting, we should just add the ebuild to the list of ebuilds to install |
186 |
+ # That way, if they want to install something we already have an ebuild for from g-cpan, it doesn't |
187 |
+ # die as well. |
188 |
+ #printbig "Ebuild already exists for '$module_name': " |
189 |
+ # . &ebuild_exists($dir) . "\n"; |
190 |
+ |
191 |
+ # Just because an ebuild exists, doesn't mean we don't want to pass it on ;) |
192 |
+ push @ebuild_list, "$exists"; |
193 |
return; |
194 |
} |
195 |
elsif ( !defined $recursive && module_check($module_name) ) { |
196 |
@@ -558,7 +574,9 @@ |
197 |
|
198 |
# FIXME Sniper |
199 |
# OH MY GOD ! |
200 |
- system( '/bin/mv', '-f', $localfile, $PORTAGE_DISTDIR ); |
201 |
+ unless ( -f "$PORTAGE_DISTDIR/$localfile" ) { |
202 |
+ system( '/bin/mv', '-f', $localfile, $PORTAGE_DISTDIR ); |
203 |
+ } |
204 |
|
205 |
push @ebuild_list, "perl-gcpan/$dir"; |
206 |
} |
207 |
@@ -602,7 +620,9 @@ |
208 |
} |
209 |
|
210 |
printbig "Checking ebuild for '$module_name': $dir\n"; |
211 |
+ my $fullname = ebuild_exists($dir); |
212 |
|
213 |
+ if (dirname($fullname) eq "perl-gcpan") { |
214 |
# check depends ... with CPAN have to make the module |
215 |
# before it can tell us what the depends are, this stinks |
216 |
|
217 |
@@ -641,8 +661,10 @@ |
218 |
create_ebuild( $obj, $dir, $file, $build_dir, $prereq_pm, $md5string ); |
219 |
unless ( -f "$PORTAGE_DISTDIR/$localfile" ) { |
220 |
system( '/bin/mv', '-f', $localfile, $PORTAGE_DISTDIR ); |
221 |
+ } |
222 |
push @ebuild_list, "perl-gcpan/$dir"; |
223 |
- } |
224 |
+ } else { push @ebuild_list, "$fullname" } |
225 |
+ |
226 |
} |
227 |
|
228 |
# TODO Sniper |
229 |
@@ -659,37 +681,16 @@ |
230 |
} |
231 |
|
232 |
sub emerge_module { |
233 |
- foreach my $ebuild_name (@ebuild_list) { |
234 |
- $ebuild_name =~ m/.*\/(.*)-[^-]+\./; |
235 |
- print "$prog: emerging $ebuild_name\n"; |
236 |
+ my @flags; |
237 |
+ push @flags, "-p" if $pretend > 0; |
238 |
+ push @flags, "-u" if $upgrade > 0; |
239 |
+ push @flags, "--ask" if $ask > 0; |
240 |
+ print "Calling: emerge --oneshot --digest @ebuild_list\n" if ($verbose); |
241 |
# FIXME Sniper |
242 |
# check return values |
243 |
- system( "emerge", "--oneshot", "--digest", $ebuild_name ); |
244 |
- } |
245 |
+ system( "emerge",@flags, "--oneshot", "--digest", @ebuild_list ); |
246 |
} |
247 |
|
248 |
-sub emerge_up_module { |
249 |
- |
250 |
- #my @e_list = @_; |
251 |
- print "\n\n"; |
252 |
- foreach my $ebuild_name (@ebuild_list) { |
253 |
- $ebuild_name =~ m/.*\/(.*)-[^-]+\./; |
254 |
- print "* Upgrade available for $ebuild_name\n"; |
255 |
- } |
256 |
- print "\nContinue with upgrade? (Y|N) "; |
257 |
- my $answer = <STDIN>; |
258 |
- chomp($answer); |
259 |
- if ( $answer =~ m|y|i ) { |
260 |
- foreach my $ebuild_name (@ebuild_list) { |
261 |
- # FIXME Sniper |
262 |
- # check return values |
263 |
- system( "emerge", "--oneshot", "--digest", $ebuild_name ); |
264 |
- } |
265 |
- } |
266 |
- return; |
267 |
- |
268 |
-} |
269 |
- |
270 |
sub get_globals { |
271 |
|
272 |
# Setting default configs |
273 |
@@ -777,10 +778,10 @@ |
274 |
mkpath($cpan_cfg_dir, 1, 0755 ) or fatal(ERR_FOLDER_CREATE, $cpan_cfg_dir, $!); |
275 |
} |
276 |
|
277 |
- my $tmp_dir = -d $ENV{TMPDIR} ? $ENV{TMPDIR} : $ENV{HOME}; |
278 |
- my $ftp_proxy = $ENV{ftp_proxy} ? $ENV{ftp_proxy} : ''; |
279 |
- my $http_proxy = $ENV{http_proxy} ? $ENV{http_proxy} : ''; |
280 |
- my $user_shell = -x $ENV{SHELL} ? $ENV{SHELL} : DEF_BASH_PROG; |
281 |
+ my $tmp_dir = -d $ENV{TMPDIR} ? defined($ENV{TMPDIR}) : $ENV{HOME}; |
282 |
+ my $ftp_proxy = $ENV{ftp_proxy} ? defined($ENV{ftp_proxy}) : ''; |
283 |
+ my $http_proxy = $ENV{http_proxy} ? defined($ENV{http_proxy}) : ''; |
284 |
+ my $user_shell = -x $ENV{SHELL} ? defined($ENV{SHELL}) : DEF_BASH_PROG; |
285 |
my $ftp_prog = -x DEF_FTP_PROG ? DEF_FTP_PROG : ''; |
286 |
my $gpg_prog = -x DEF_GPG_PROG ? DEF_GPG_PROG : ''; |
287 |
my $gzip_prog = -x DEF_GZIP_PROG ? DEF_GZIP_PROG : ''; |
288 |
@@ -886,6 +887,8 @@ |
289 |
print <<"USAGE"; |
290 |
Usage : $prog <Switch(es)> Module Name(s) |
291 |
|
292 |
+--ask,-a Ask before installing |
293 |
+ |
294 |
--install,-i Try to generate ebuild for the given module name |
295 |
and, if successful, emerge it. Important : installation |
296 |
requires exact CPAN Module Name. |
297 |
@@ -893,6 +896,11 @@ |
298 |
--list,-l This command generates a list of the Perl modules and ebuilds |
299 |
handled by $prog. |
300 |
|
301 |
+--noclean,-n Don't clean up temporary areas after running install or upgrade. |
302 |
+ |
303 |
+--pretend,-u Pretend (show actions, but don't emerge). This still generates |
304 |
+ new ebuilds. |
305 |
+ |
306 |
--search,-s Search CPAN for the given expression (similar to |
307 |
the "m /EXPR/" from the CPAN Shell). Searches are |
308 |
case insensitive. |
309 |
|
310 |
|
311 |
-- |
312 |
gentoo-perl@g.o mailing list |