Update of /cvsroot/fink/fink/perlmod/Fink
In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv12055/perlmod/Fink

Modified Files:
      Tag: selfupdate_classes
        ChangeLog SelfUpdate.pm 
Log Message:
Offload all CVS-method stuff into its own class. Yay complete modularity!


Index: SelfUpdate.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/SelfUpdate.pm,v
retrieving revision 1.117.2.7
retrieving revision 1.117.2.8
diff -u -d -r1.117.2.7 -r1.117.2.8
--- SelfUpdate.pm       8 Mar 2007 08:02:04 -0000       1.117.2.7
+++ SelfUpdate.pm       8 Mar 2007 17:21:57 -0000       1.117.2.8
@@ -25,13 +25,10 @@
 
 use Fink::Services qw(&execute);
 use Fink::Bootstrap qw(&additional_packages);
-use Fink::CLI qw(&print_breaking &prompt &prompt_boolean &prompt_selection);
-use Fink::Config qw($config $basepath $distribution);
+use Fink::CLI qw(&print_breaking &prompt_boolean &prompt_selection);
+use Fink::Config qw($config $basepath);
 use Fink::Engine;  # &aptget_update &cmd_install, but they aren't EXPORT_OK
 use Fink::Package;
-use Fink::Command qw(cat chowname mkdir_p mv rm_f rm_rf touch);
-
-use File::Find;
 
 use strict;
 use warnings;
@@ -64,7 +61,6 @@
 
   Fink::SelfUpdate::check($method);
 
-
 This is the main entry point for the 'fink selfupdate*' commands. The
 local collection of package descriptions is updated according to one
 of the following methods:
@@ -199,276 +195,12 @@
                $subclass->clear_metadata();
        }
 
-       if ($subclass_use eq 'Fink::SelfUpdate::CVS') {
-               # TODO: make a single CVS method that is self-deterministic
-               # and migrate into the subclass
-               if (-d "$basepath/fink/dists/CVS") {
-                       # already have a cvs checkout
-                       &do_direct_cvs();
-               } else {
-                       &setup_direct_cvs();
-               }
-       } else {
-               $subclass_use->do_direct();
-       }
+       # Let's do this thang!
+       $subclass_use->do_direct();
        $subclass_use->stamp_set();
        &do_finish();
 }
 
-### set up direct cvs
-
-sub setup_direct_cvs {
-       my ($finkdir, $tempdir, $tempfinkdir);
-       my ($username, $cvsuser, @testlist);
-       my ($use_hardlinks, $cutoff, $cmd);
-       my ($cmdd);
-
-       Fink::SelfUpdate::CVS->system_check() || die;
-
-       $username = "root";
-       if (exists $ENV{SUDO_USER}) {
-               $username = $ENV{SUDO_USER};
-       }
-
-       print "\n";
-       $username =
-               &prompt("Fink has the capability to run the CVS commands as a ".
-                               "normal user. That has some advantages - it 
uses that ".
-                               "user's CVS settings files and allows the 
package ".
-                               "descriptions to be edited and updated without 
becoming ".
-                               "root. Please specify the user login name that 
should be ".
-                               "used:",
-                               default => $username);
-
-       # sanity check
-       @testlist = getpwnam($username);
-       if (scalar(@testlist) <= 0) {
-               die "The user \"$username\" does not exist on the system.\n";
-       }
-
-       print "\n";
-       $cvsuser =
-               &prompt("For Fink developers only: ".
-                               "Enter your SourceForge login name to set up 
full CVS access. ".
-                               "Other users, just press return to set up 
anonymous ".
-                               "read-only access.",
-                               default => "anonymous");
-       print "\n";
-
-       # start by creating a temporary directory with the right permissions
-       $finkdir = "$basepath/fink";
-       $tempdir = "$finkdir.tmp";
-       $tempfinkdir = "$tempdir/fink";
-
-       if (-d $tempdir) {
-               rm_rf $tempdir or
-                       die "Can't remove left-over temporary directory 
'$tempdir'\n";
-       }
-       mkdir_p $tempdir or
-               die "Can't create temporary directory '$tempdir'\n";
-       if ($username ne "root") {
-               chowname $username, $tempdir or
-                       die "Can't set ownership of temporary directory 
'$tempdir'\n";
-       }
-
-       # check if hardlinks from the old directory work
-       &print_breaking("Checking to see if we can use hard links to merge ".
-                                       "the existing tree. Please ignore 
errors on the next ".
-                                       "few lines.");
-       unless (touch "$finkdir/README" and link "$finkdir/README", 
"$tempdir/README") {
-               $use_hardlinks = 0;
-       } else {
-               $use_hardlinks = 1;
-       }
-       unlink "$tempdir/README";
-
-       # start the CVS fun
-       chdir $tempdir or die "Can't cd to $tempdir: $!\n";
-
-       # add cvs quiet flag if verbosity level permits
-       my $verbosity = "-q";
-       if ($config->verbosity_level() > 1) {
-               $verbosity = "";
-       }
-       my $cvsrepository = "fink.cvs.sourceforge.net:/cvsroot/fink";
-       if (-f "$basepath/lib/fink/URL/cvs-repository") {
-               $cvsrepository = cat "$basepath/lib/fink/URL/cvs-repository";
-               chomp($cvsrepository);
-               $cvsrepository .= ':/cvsroot/fink';
-       }
-       if ($cvsuser eq "anonymous") {
-               if (-f "$basepath/lib/fink/URL/anonymous-cvs") {
-                       $cvsrepository = cat 
"$basepath/lib/fink/URL/anonymous-cvs";
-                       chomp($cvsrepository);
-               }
-               &print_breaking("Now logging into the CVS server. When CVS asks 
you ".
-                                               "for a password, just press 
return (i.e. the password ".
-                                               "is empty).");
-               $cmd = "cvs -d:pserver:[EMAIL PROTECTED] login";
-               if ($username ne "root") {
-                       $cmd = "/usr/bin/su $username -c '$cmd'";
-               }
-               if (&execute($cmd)) {
-                       die "Logging into the CVS server for anonymous 
read-only access failed.\n";
-               }
-
-               $cmd = "cvs ${verbosity} -z3 -d:pserver:[EMAIL PROTECTED]";
-       } else {
-               if (-f "$basepath/lib/fink/URL/developer-cvs") {
-                       $cvsrepository = cat 
"$basepath/lib/fink/URL/developer-cvs";
-                       chomp($cvsrepository);
-               }
-               $cmd = "cvs ${verbosity} -z3 -d:ext:[EMAIL PROTECTED]";
-               $ENV{CVS_RSH} = "ssh";
-       }
-       $cmdd = "$cmd checkout -l -d fink dists";
-       if ($username ne "root") {
-               $cmdd = "/usr/bin/su $username -c '$cmdd'";
-       }
-       &print_breaking("Setting up base Fink directory...");
-       if (&execute($cmdd)) {
-               die "Downloading package descriptions from CVS failed.\n";
-       }
-
-       my @trees = split(/\s+/, $config->param_default("SelfUpdateCVSTrees", 
$distribution));
-       chdir "fink" or die "Can't cd to fink\n";
-
-       for my $tree (@trees) {
-               &print_breaking("Checking out $tree tree...");
-
-               my $cvsdir = "dists/$tree";
-               $cvsdir = "packages/dists" if ($tree eq "10.1");
-               $cmdd = "$cmd checkout -d $tree $cvsdir";
-
-               if ($username ne "root") {
-                       $cmdd = "/usr/bin/su $username -c '$cmdd'";
-               }
-               if (&execute($cmdd)) {
-                       die "Downloading package descriptions from CVS 
failed.\n";
-               }
-       }
-       chdir $tempdir or die "Can't cd to $tempdir: $!\n";
-
-       if (not -d $tempfinkdir) {
-               die "The CVS didn't report an error, but the directory 
'$tempfinkdir' ".
-                       "doesn't exist as expected. Strange.\n";
-       }
-
-       # merge the old tree
-       $cutoff = length($finkdir)+1;
-       find(sub {
-                                if ($_ eq "CVS") {
-                                        $File::Find::prune = 1;
-                                        return;
-                                }
-                                return if (length($File::Find::name) <= 
$cutoff);
-                                my $rel = substr($File::Find::name, $cutoff);
-                                if (-l and not -e "$tempfinkdir/$rel") {
-                                        my $linkto;
-                                        $linkto = readlink($_)
-                                                or die "Can't read target of 
symlink $File::Find::name: $!\n";
-                                        symlink $linkto, "$tempfinkdir/$rel" or
-                                                die "Can't create symlink 
\"$tempfinkdir/$rel\"\n";
-                                } elsif (-d and not -d "$tempfinkdir/$rel") {
-                                        mkdir_p "$tempfinkdir/$rel" or
-                                                die "Can't create directory 
\"$tempfinkdir/$rel\"\n";
-                                } elsif (-f and not -f "$tempfinkdir/$rel") {
-                                        my $cmd;
-                                        if ($use_hardlinks) {
-                                                $cmd = "ln";
-                                        } else {
-                                                $cmd = "cp -p"
-                                        }
-                                        $cmd .= " '$_' '$tempfinkdir/$rel'";
-                                        if (&execute($cmd)) {
-                                                die "Can't copy file 
\"$tempfinkdir/$rel\"\n";
-                                        }
-                                }
-                        }, $finkdir);
-
-       # switch $tempfinkdir to $finkdir
-       chdir $basepath or die "Can't cd to $basepath: $!\n";
-       mv $finkdir, "$finkdir.old" or
-               die "Can't move \"$finkdir\" out of the way\n";
-       mv $tempfinkdir, $finkdir or
-               die "Can't move new tree \"$tempfinkdir\" into place at 
\"$finkdir\". ".
-                       "Warning: Your Fink installation is in an inconsistent 
state now.\n";
-       rm_rf $tempdir;
-
-       print "\n";
-       &print_breaking("Your Fink installation was successfully set up for ".
-                                       "direct CVS updating. The directory 
\"$finkdir.old\" ".
-                                       "contains your old package description 
tree. Its ".
-                                       "contents were merged into the new one, 
but the old ".
-                                       "tree was left intact for safety 
reasons. If you no ".
-                                       "longer need it, remove it manually.");
-       print "\n";
-}
-
-### call cvs update
-
-sub do_direct_cvs {
-       my ($descdir, @sb, $cmd, $cmd_recursive, $username, $msg);
-
-       Fink::SelfUpdate::CVS->system_check() || die;
-
-       # add cvs quiet flag if verbosity level permits
-       my $verbosity = "-q";
-       if ($config->verbosity_level() > 1) {
-               $verbosity = "";
-       }
-
-       $descdir = "$basepath/fink";
-       chdir $descdir or die "Can't cd to $descdir: $!\n";
-
-       @sb = stat("$descdir/CVS");
-
-       $cmd = "cvs ${verbosity} -z3 update -d -P -l";
-
-       $msg = "I will now run the cvs command to retrieve the latest package 
descriptions. ";
-
-       if ($sb[4] != 0 and $> != $sb[4]) {
-               ($username) = getpwuid($sb[4]);
-               $msg .= "The 'su' command will be used to run the cvs command 
as the ".
-                               "user '$username'. ";
-       }
-
-       $msg .= "After that, the core packages will be updated right away; ".
-                       "you should then update the other packages using 
commands like ".
-                       "'fink update-all'.";
-
-       print "\n";
-       &print_breaking($msg);
-       print "\n";
-
-       $ENV{CVS_RSH} = "ssh";
-
-       # first, update the top-level stuff
-
-       my $errors = 0;
-
-       $cmd = "/usr/bin/su $username -c '$cmd'" if ($username);
-       if (&execute($cmd)) {
-               $errors++;
-       }
-
-       # then, update the trees
-
-       my @trees = split(/\s+/, $config->param_default("SelfUpdateCVSTrees", 
$distribution));
-       for my $tree (@trees) {
-               $cmd = "cvs ${verbosity} -z3 update -d -P ${tree}";
-               $cmd = "/usr/bin/su $username -c '$cmd'" if ($username);
-               if (&execute($cmd)) {
-                       $errors++;
-               }
-       }
-
-       Fink::SelfUpdate::CVS->stamp_set();
-       Fink::SelfUpdate::rsync->stamp_clear();
-       die "Updating using CVS failed. Check the error messages above.\n" if 
($errors);
-
-}
-
 =item do_finish
 
   Fink::SelfUpdate::do_finish;

Index: ChangeLog
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v
retrieving revision 1.1439.2.8
retrieving revision 1.1439.2.9
diff -u -d -r1.1439.2.8 -r1.1439.2.9
--- ChangeLog   8 Mar 2007 08:02:04 -0000       1.1439.2.8
+++ ChangeLog   8 Mar 2007 17:21:57 -0000       1.1439.2.9
@@ -1,5 +1,10 @@
 2007-03-08  Daniel Macks  <[EMAIL PROTECTED]>
 
+       * SelfUpdate.pm, SelfUpdate/CVS.pm: Offload cvs stuff into its own
+       class
+
+2007-03-08  Daniel Macks  <[EMAIL PROTECTED]>
+
        * SelfUpdate/Base.pm: add system_check to public API
        * SelfUpdate.pm, SelfUpdate/*: let each method handle its own
        system sanity-checking; nuke &SU::need_devtools


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Fink-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fink-commits

Reply via email to