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

Modified Files:
      Tag: selfupdate_classes
        ChangeLog SelfUpdate.pm 
Log Message:
Massively overhaul SU::check...headed towards plugin-able format


Index: SelfUpdate.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/SelfUpdate.pm,v
retrieving revision 1.117.2.5
retrieving revision 1.117.2.6
diff -u -d -r1.117.2.5 -r1.117.2.6
--- SelfUpdate.pm       8 Mar 2007 03:12:30 -0000       1.117.2.5
+++ SelfUpdate.pm       8 Mar 2007 07:28:54 -0000       1.117.2.6
@@ -112,124 +112,118 @@
 
 =cut
 
+# TODO: auto-detect all available classes and their descs
+our @known_method_classes = qw( rsync CVS point );
+our %known_method_descs = (
+       'rsync' => 'rsync',
+       'CVS'   => 'cvs',
+       'point' => 'Stick to point releases',
+);
+
 sub check {
-       my $method = shift;
+       my $method = shift;  # requested selfupdate method to use
+
+       $method = '' if ! defined $method;
 
        {
+               # compatibility for old calling parameters
                my %methods = (
-                       0       => undef,
-                       1       => 'cvs',
-                       2       => 'rsync',
-                       'cvs'   => 'cvs',
-                       'rsync' => 'rsync',
+                       0 => '',
+                       1 => 'cvs',
+                       2 => 'rsync',
                );
-               $method = 0 if ! defined $method;
-               if (! exists $methods{lc $method}) {
-                       die "Invalid method '$method' passed to 
Selfupdate::check\n";
+               if (length $method and exists $methods{$method}) {
+                       $method = $methods{$method};
                }
-               $method = $methods{lc $method};
        }
 
-       if (defined $method) {
+       # canonical form is all-lower-case
+       $method = lc($method);
+       my $prev_method = lc($config->param_default("SelfUpdateMethod", ''));
+
+       if ($method eq '') {
+               # no explicit method requested
+
+               if ($prev_method ne '') {
+                       # use existing default
+                       $method = $prev_method;
+               } else {
+                       # no existing default so ask user
+
+                       $method = &prompt_selection(
+                               'Choose an update method',
+                               intro   => 'fink needs you to choose a 
SelfUpdateMethod.',
+                               default => [ 'value' => 'rsync' ],  # TODO: 
make sure this exists
+                               choices => [ map { $known_method_descs{$_} => 
lc($_) } @known_method_classes ]
+                       );
+               }
+       } else {
+               # explicit method requested
                &print_breaking("\n Please note: the command 'fink selfupdate' "
-                               . "should be used for routine updating; you 
only need to use " 
-                               . "'fink selfupdate-cvs' or 'fink 
selfupdate-rsync' if you are "
-                               . "changing your update method. \n\n");
-       }
-       if (! defined $config->param("SelfUpdateMethod") and defined $method) {
-               my $answer = $method;
-               $answer = 'point' if !defined $answer;
-               &need_devtools($answer);
-               &print_breaking("fink is setting your default update method to 
$answer \n");
-               $config->set_param("SelfUpdateMethod", $answer);
-               $config->save();
+                                               . "should be used for routine 
updating; you only "
+                                               . "need to use a command like 
'fink selfupdate-cvs' "
+                                               . "or 'fink selfupdate-rsync' 
if you are changing "
+                                               . "your update method. \n\n");
+
+               if ($method ne $prev_method) {
+                       # requested a method different from previously-saved 
default
+                       # better double-check that user really wants to do this
+                       my $answer =
+                               &prompt_boolean("The current selfupdate method 
is $prev_method. "
+                                                               . "Do you wish 
to change this default method "
+                                                               . "to $method?",
+                                                               default => 1
+                               );
+                       return if !$answer;
+               }
        }
 
-       # The user has not chosen a selfupdatemethod yet, always ask
-       # if the fink.conf setting is not there.
-       if (! defined $config->param("SelfUpdateMethod") and ! defined $method) 
{
-               my $answer = &prompt_selection("Choose an update method",
-                                               intro   => "fink needs you to 
choose a SelfUpdateMethod.",
-                                               default => [ value => "rsync" ],
-                                               choices => [
-                                                 "rsync" => "rsync",
-                                                 "cvs" => "cvs",
-                                                 "Stick to point releases" => 
"point"
-                                               ] );
-               &need_devtools($answer);
-               $config->set_param("SelfUpdateMethod", $answer);
-               $config->save();        
+       # We temporarily disable rsync updating for 10.5, until we've decided 
how to handle it
+       if ($method eq 'rsync' and $distribution eq '10.5') {
+               die "Sorry, fink doesn't support rsync updating in the 10.5 
distribution at present.\n";
        }
 
-       # We temporarily disable rsync updating for 10.5, until we've decided
-       # how to handle it
+       my ($subclass_use)  = grep { $method eq lc($_) } @known_method_classes;
+       die "SelfUpdateMethod '$method' is not implemented\n" unless( defined 
$subclass_use && length $subclass_use );
 
-       if (($config->param("SelfUpdateMethod") eq "rsync") and ($distribution 
eq "10.5")) {
-               die "Sorry, fink doesn't support rsync updating in the 10.5 
distribution at present.\n\n";
+       $subclass_use = "Fink::SelfUpdate::$subclass_use";
+       eval { require $subclass_use };
+       die "SelfUpdateMethod '$method' could not be loaded: [EMAIL PROTECTED]" 
if $@;
+
+       &need_devtools($method);        # TODO: query the subclass to have it
+                                                               # determine if 
its needed support
+                                                               # programs 
(including devtools for
+                                                               # 
build-from-source methods) are
+                                                               # available
+
+       if ($method ne $prev_method) {
+               # save new selection (explicit change or being set for first 
time)
+               &print_breaking("fink is setting your default update method to 
$method \n");
+               $config->set_param("SelfUpdateMethod", $method);
+               $config->save();
        }
 
-       # By now the config param SelfUpdateMethod should be set.
-       if ($config->param("SelfUpdateMethod") eq 'cvs' and $method ne 'rsync') 
{
-               &need_devtools('cvs');
-               Fink::SelfUpdate::rsync->stamp_clear();
+       # clear remnants of any methods other than one to be used
+       foreach my $subclass (map { "Fink::SelfUpdate::$_" } 
@known_method_classes) {
+               next if $subclass eq $subclass_use;
+               $subclass->stamp_clear();
+               $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();
                }
-               &do_finish();
-               return;
-       }
-       elsif ($config->param("SelfUpdateMethod") eq 'rsync' and $method ne 
'cvs'){
-               &need_devtools('rsync');
-               Fink::SelfUpdate::rsync->do_direct();
-               &do_finish();
-               return;
-       }
-       # Hm, we were called with a different option than the default :(
-       my $selfupdatemethod = $config->param("SelfUpdateMethod");
-       if ($selfupdatemethod ne 'rsync' and $method eq 'rsync') {
-
-       # We temporarily disable rsync updating for 10.5, until we've decided
-       # how to handle it
-
-               if ($distribution eq "10.5") {
-                       die "Sorry, fink doesn't support rsync updating in the 
10.5 distribution at present.\n\n";
-               }
-
-               my $answer =
-                       &prompt_boolean("The current selfupdate method is 
$selfupdatemethod. " 
-                                       . "Do you wish to change the default 
selfupdate method ".
-                               "to rsync?", default => 1);
-               if (! $answer) {
-                       return;
-               }
-               &need_devtools('rsync');
-               $config->set_param("SelfUpdateMethod", "rsync");
-               $config->save();        
-               Fink::SelfUpdate::rsync->do_direct();
-               &do_finish();
-               return;         
-       }
-       if ($selfupdatemethod ne 'cvs' and $method eq 'cvs') {
-               my $answer =
-                       &prompt_boolean("The current selfupdate method is 
$selfupdatemethod. " 
-                                       . "Do you wish to change the default 
selfupdate method ".
-                               "to cvs?", default => 1);
-               if (! $answer) {
-                       return;
-               }
-               &need_devtools('cvs');
-               $config->set_param("SelfUpdateMethod", "cvs");
-               $config->save();        
-               &setup_direct_cvs();
-               &do_finish();
-               return;
-       }
-       if (($config->param("SelfUpdateMethod") eq "point")) {
-               Fink::SelfUpdate::point->do_direct();
-               &do_finish();
+       } else {
+               $subclass_use->do_direct();
        }
+       $subclass_use->stamp_set();
+       &do_finish();
 }
 
 =item need_devtools

Index: ChangeLog
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v
retrieving revision 1.1439.2.6
retrieving revision 1.1439.2.7
diff -u -d -r1.1439.2.6 -r1.1439.2.7
--- ChangeLog   8 Mar 2007 03:12:29 -0000       1.1439.2.6
+++ ChangeLog   8 Mar 2007 07:28:53 -0000       1.1439.2.7
@@ -1,3 +1,9 @@
+2007-03-08  Daniel Macks  <[EMAIL PROTECTED]>
+
+       * SelfUpdate.pm: completely redo check(), removing most
+       special-case method tests
+       * SelfUpdate.pm, SelfUpdate/*: remove all cross-method interactions
+
 2007-03-07  Daniel Macks  <[EMAIL PROTECTED]>
 
        * SelfUpdate.pm, SelfUpdate/*: clean up imports from other pkgs


-------------------------------------------------------------------------
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
Fink-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fink-commits

Reply via email to