Author: cab
Date: 2005-05-11 01:08:12 +0200 (Wed, 11 May 2005)
New Revision: 7
Added:
TODO
Modified:
Changes
code/g-cpan.pl
docs/svn-mini-howto.txt
Log:
Modifications, imported old changes, todo file
Modified: Changes
===================================================================
--- Changes 2005-05-10 22:15:06 UTC (rev 6)
+++ Changes 2005-05-10 23:08:12 UTC (rev 7)
@@ -1,10 +1,13 @@
-10/05/2005 - cab made again some changes to g-cpan.. :)
+10/05/2005 - cab strikes g-cpan again.. :)
- added comments here and there..
- modified the cpan-config-needed if() test
- modified switches interpretations
- added -l,--list switch (nothing behind for now)
- added a new sub : clean_the_mess, that should take care of system's sanity
+- changed my $arches
+- subbed the MD5 sum calculation
+- updated exit_usage()
07/05/2005 - cab first strike !
@@ -17,7 +20,7 @@
instead of 3 times qx() : performance boost guaranteed. Sets up default before
overwriting them if needed and can replace variables like ${PORTDIR} if ever
they are used in make.conf : quality improvement guaranteed. :p
- thx to Sniper for the s// regexp !
+ thx to Sniper (sniper@...) for the s// regexp !
- Added a bit more explicative Usage message.. in fact a whole sub.
Available with -h or --help switch but will also appear if user
Added: TODO
===================================================================
--- TODO 2005-05-10 22:15:06 UTC (rev 6)
+++ TODO 2005-05-10 23:08:12 UTC (rev 7)
@@ -0,0 +1,7 @@
+- Heavy testing !
+- Some work on the overlays - possibility to use ~/.cpan
+- clean_the_mess / clean_up to improve/merge
+- big portions of upgrade_module and install_module are the same code
+- check for multiple emerge
+- Add verbosity messages
+- Clean the code.. which prog doesn't need this ? :p
Modified: code/g-cpan.pl
===================================================================
--- code/g-cpan.pl 2005-05-10 22:15:06 UTC (rev 6)
+++ code/g-cpan.pl 2005-05-10 23:08:12 UTC (rev 7)
@@ -19,15 +19,18 @@
my $needs_cpan_stub = $@ ? 1 : 0;
# Test Replacement - ((A&B)or(C&B)) should be the same as ((A or C) and B)
-if (( ($needs_cpan_stub) || ( $> > 0 ) ) && ( !-f "$ENV{HOME}/.cpan/CPAN/MyConfig.pm" ) ) {
- # In case match comes from the UID test
+if ( ( ($needs_cpan_stub) || ( $> > 0 ) )
+ && ( !-f "$ENV{HOME}/.cpan/CPAN/MyConfig.pm" ) )
+{
+
+ # In case match comes from the UID test
$needs_cpan_stub = 1;
-
- # Generate a fake config for CPAN
+
+ # Generate a fake config for CPAN
cpan_stub();
}
else {
- $needs_cpan_stub = 0;
+ $needs_cpan_stub = 0;
}
use CPAN;
@@ -49,7 +52,7 @@
###############################
# Init all options
-my ( $verbose, $search, $install, $upgrade, $list ) = (0,0,0,0,0);
+my ( $verbose, $search, $install, $upgrade, $list ) = ( 0, 0, 0, 0, 0 );
#Get & Parse them
GetOptions(
@@ -57,24 +60,24 @@
'search|s' => \$search,
'install|i' => \$install,
'upgrade|u' => \$upgrade,
- 'list|l' => \$list,
+ 'list|l' => \$list,
'help|h' => sub { exit_usage(); }
)
or exit_usage();
# Output error if more than one switch is activated
-if ($search + $list + $install + $upgrade > 1) {
- print "You can't combine search, list, install or upgrade with each other. Pick up one !\n\n";
- exit_usage();
+if ( $search + $list + $install + $upgrade > 1 ) {
+ print
+"You can't combine search, list, install or upgrade with each other. Pick up one !\n\n";
+ exit_usage();
}
# Output error if no arguments
-if ( !( defined( $ARGV[0] ) ) and (!($upgrade) or !($list)) ) {
+if ( !( defined( $ARGV[0] ) ) and ( !($upgrade) or !($list) ) ) {
print "Not even one module name or expression given !\n\n";
exit_usage();
}
-
##########
# main() #
##########
@@ -83,21 +86,22 @@
# CPAN Shell to do the job, thus making it impossible to have a clean output..
if ($search) {
foreach my $expr (@ARGV) {
-
+
# Assume they gave us module-name instead of module::name
- if ( $expr !~ m|::| ) {
+ # which is bad, because CPAN can't convert it ;p
+ if ( $expr !~ m|::| ) {
$expr =~ s/-/::/g;
- }
+ }
print "Searching for $expr on CPAN\n\n";
CPAN::Shell->m("/$expr/");
}
-
- clean_the_mess();
+
+ clean_the_mess();
exit;
}
# Take care of List requests. This should return all the ebuilds managed by g-cpan
-if ( $list ) {
+if ($list) {
print "List function not implemented yet.\n";
exit_usage();
}
@@ -110,7 +114,7 @@
if ( $ENV{TMPDIR} ) { $tmp_overlay_dir = "$ENV{TMPDIR}/perl-modules_$$" }
else { $tmp_overlay_dir = "/tmp/perl-modules_$$" }
-my @ebuild_list;
+my @ebuild_list; #this array needs to be seriously observed.
# Set up global paths
# my $TMP_DEV_PERL_DIR = '/var/db/pkg/dev-perl';
@@ -141,11 +145,18 @@
}
}
-my $arches =
- join( ' ', map { chomp; $_ } `cat $PORTAGE_DIR/profiles/arch.list` );
+# Grab the whole available arches list, to include them later in ebuilds
+my $arches = do {
+ if ($verbose) {
+ print "Grabbing arch list\n";
+ }
+ open my $tmp, "$PORTAGE_DIR/profiles/arch.list"
+ or die "Unable to open '$PORTAGE_DIR/profiles/arch.list' : $!";
+ join " ", map { chomp; $_ } <$tmp>;
+ }
-#this should never find the dir, but just to be safe
-unless ( -d $tmp_overlay_dir ) {
+ #this should never find the dir, but just to be safe
+ unless ( -d $tmp_overlay_dir ) {
mkpath( [$tmp_overlay_dir], 1, 0755 )
or die "Couldn't create '$tmp_overlay_dir': $|";
}
@@ -170,6 +181,7 @@
install_module($_) for (@ARGV);
emerge_module($_) for (@ARGV);
}
+
if ($upgrade) {
if (@ARGV) {
upgrade_module($_) for (@ARGV);
@@ -182,7 +194,9 @@
}
}
+
if ( $install or $upgrade ) { clean_up() }
+
exit;
##########
@@ -467,14 +481,8 @@
my $localfile = $pack->{localfile};
( my $base = $file ) =~ s/.*\/(.*)/$1/;
- my $md5digest;
- open( DIGIFILE, $localfile ) or die "Can't open '$file': $!";
- binmode(DIGIFILE);
- $md5digest = Digest::MD5->new->addfile(*DIGIFILE)->hexdigest;
- close(DIGIFILE);
+ my $md5string = sprintf "MD5 %s %s %d", file_md5sum($localfile), $base, -s $localfile;
- my $md5string = sprintf "MD5 %s %s %d", $md5digest, $base, -s $localfile;
-
# make ebuilds for all the prereqs
my $prereq_pm = $pack->prereq_pm;
if ($add_mb) { $prereq_pm->{'Module::Build'} = "0" }
@@ -554,13 +562,8 @@
my $localfile = $pack->{localfile};
( my $base = $file ) =~ s/.*\/(.*)/$1/;
- my $md5digest;
- open( DIGIFILE, $localfile ) or die "Can't open '$file': $!";
- binmode(DIGIFILE);
- $md5digest = Digest::MD5->new->addfile(*DIGIFILE)->hexdigest;
- close(DIGIFILE);
- my $md5string = sprintf "MD5 %s %s %d", $md5digest, $base, -s $localfile;
+ my $md5string = sprintf "MD5 %s %s %d", file_md5sum($localfile), $base, -s $localfile;
# make ebuilds for all the prereqs
my $prereq_pm = $pack->prereq_pm;
@@ -793,30 +796,54 @@
}
+# Simple useful sub. returns md5 hexdigest of the given argument
+# awaits a file name.
+sub file_md5sum {
+
+ my $file = $_[0];
+
+ if ($verbose) {
+ print "Computing MD5 Sum of $file\n";
+ }
+
+ open(DIGIFILE, $file ) or die "Can't open '$file': $!";
+ my $md5digest = Digest::MD5->new->addfile(*DIGIFILE)->hexdigest;
+ close(DIGIFILE);
+
+ return $md5digest;
+}
+
# Takes care of system's sanity
# should try to see if it can be merged with clean_up()
sub clean_the_mess {
- if ($verbose) {
- print "Now cleaning up the system of all the junk we put in !\n";
- }
- if ($needs_cpan_stub) {
- unlink "$ENV{HOME}/.cpan/CPAN/MyConfig.pm";
- #add something here to take care of the .cpan dir, if not empty
- }
+ if ($verbose) {
+ print "Now cleaning up the system of all the junk we put in !\n";
+ }
+ if ($needs_cpan_stub) {
+ unlink "$ENV{HOME}/.cpan/CPAN/MyConfig.pm";
+
+ #add something here to take care of the .cpan dir, if not empty
+ }
}
sub exit_usage {
print <<"USAGE";
-Usage : $0 [-i|--install] [-s|--search] [-v|--verbose] Module Name(s)
+Usage : $0 <Switch(es)> Module Name(s)
--install,-i Try to generate ebuild for the given module name
and, if successful, emerge it. Important : installation
requires exact CPAN Module Name.
+
+--list,-l This command generates a list of the Perl modules and ebuilds
+ handled by $0.
--search,-s Search CPAN for the given expression (similar to
the "m /EXPR/" from the CPAN Shell). Searches are
case insensitive.
+--upgrade,-u Try to list and upgrade all Perl modules managed by $0.
+ It generate up-to-date ebuilds, then emerge then.
+
--verbose,-v Enable (some) verbose output.
USAGE
Modified: docs/svn-mini-howto.txt
===================================================================
--- docs/svn-mini-howto.txt 2005-05-10 22:15:06 UTC (rev 6)
+++ docs/svn-mini-howto.txt 2005-05-10 23:08:12 UTC (rev 7)
@@ -9,6 +9,7 @@
don't forget to use svn update often, at least each time you want to work on the code ;p
+and of course SVN is web browsable : http://gredin.net/svn/gcpan/
+
--
cab
-
--
gentoo-perl@g.o mailing list
|