Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Script to update your PPM Repositories

by eibwen (Friar)
on Jun 26, 2005 at 02:48 UTC ( #469988=note: print w/ replies, xml ) Need Help??


in reply to Script to update your PPM Repositories

Now more efficient and no longer redundant.

Additionally, it should be noted that Net::Ping::new() defaults to TCP, therefore any "dead" repository merely failed to reply to a TCP ping. Some "dead" domains will reply to alternative protocol pings (eg SourceForge does not reply to TCP, but does reply to ICMP).

use strict; use warnings; use PPM::Repositories; use Net::Ping; foreach my $repository (split(/[\r\n]/, `ppm rep`)) { next unless $repository =~ s/^\[[\d\ ]+\]\ (.*)$/$1/; system("ppm rep delete $repository > NUL") unless $repository =~ / +activestate/i; } foreach my $repository (keys %Repositories) { my $domain = my $location = $Repositories{$repository}->{location} +; next unless $domain =~ s|^\s*http://([^/]+)/.*$|$1|; if (Net::Ping->new()->ping($domain)) { print "$repository is alive.\n"; system("ppm repository add $repository $location > NUL"); } else { print "$repository is dead.\n"; } } print $/, `ppm rep`;

Output:

dada is dead. smueller is alive. crazy58 is alive. crazy is alive. datetime is alive. soulcage58 is alive. bribes is alive. gtk is dead. rto is alive. spurkis is dead. theoryS is dead. jenda is dead. theory58S is dead. log4perl is dead. theory58 is dead. soulcage is alive. savage is dead. devhelp is alive. theory is dead. openi is dead. roth is alive. Repositories: [ 1] ActiveState Package Repository [ 2] ActiveState PPM2 Repository [ 3] smueller [ 4] crazy58 [ 5] crazy [ 6] datetime [ 7] soulcage58 [ 8] bribes [ 9] rto [10] soulcage [11] devhelp [12] roth


Comment on Re: Script to update your PPM Repositories
Select or Download Code
Re^2: Script to update your PPM Repositories
by QM (Vicar) on Sep 28, 2005 at 21:45 UTC
    I've taken this and made it more complicated :( I'm interested in suggestions for improvements!

    It will now keep "local" repositories in the list if they are alive, even if they aren't in the PPM::Repositories list or one of ActiveState's.

    It preserves the order of "local" repositories. (Those added from PPM::Repositories are still added in key order.)

    Since this script would generally be run only occasionally, it also gets the latest PPM::Repositories, in case that list has been updated. I could only mangle^Wmanage this automatically by first removing the old module, and then installing it again. If this somehow fails to reinstall, the script won't load. (I could fix this, but I've run out of time today. Besides, it winds up being something of a circular dependency.) This can be avoided by calling it with some arbitrary argument.

    adds and deletes now only happen if necessary (according to the IN_LOCAL_LIST key in the script-generated %repositories hash).

    I also found that exec in Windoze caused the prompt to wait for user input, such that it never appeared to finish. Switching to system with appropriate control logic fixed it.

    I'm sure someone will want option processing, etc., but I'm not inclined to add that today ;)

    Update: Thanks to randyk, used PPM::UI instead of ppm rep describe $name.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      I've been looking to incorporate the various changes and suggesions the monks have made into my top post, and maybe even taking out a PAUSE idea and adding this as my contribution to CPAN.

      Looking over what you did, however, I notice there's no PPM::UI when I searched cpan. Could you clarify?

        Sorry, I shouldn't have linked to it like that.

        PPM::UI is part of the ActiveState installation. On my machine, it lives in d:/Perl/site/lib/PPM/UI.pm.

        Here's the transcript to demonstrate:

        D:\>perl -demo Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(-e:1): mo DB<1> use PPM::UI DB<2> p $INC{'PPM/UI.pm'} d:/Perl/site/lib/PPM/UI.pm
        However, ppm3 doesn't seem to know about PPM::UI -- at least, you can't query PPM::UI, or search it, etc. In fact, I find the search and query functionality oddly designed, as I have to know the distribution name, or work at figuring out the wildcard/logical expression to match it. Maybe I just don't know how to use it.

        So other than installing ActiveState, I don't know where to get PPM::UI from. Which means if there's an update, it's either buried in PPM, or it's part of the ActiveState install package (and then you only get the update when you update Perl).

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://469988]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-07-29 16:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (220 votes), past polls