[PATCH 1/2] Make the firstboot --reconfig option work

Vratislav Podzimek vpodzime at redhat.com
Tue Jun 18 14:20:49 UTC 2013


Only the user creation should appear in the Initial Setup unless
'firstboot --reconfig' is used and only if no user had been created in the
installation.

Also use constants for the environment specifications instead of magic strings.

Resolves: rhbz#963935
Resolves: rhbz#963797
Related: rhbz#972362

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 pyanaconda/constants.py            |  2 ++
 pyanaconda/ui/common.py            | 36 +++++++++++++++++++++++++++++++++---
 pyanaconda/ui/gui/hubs/__init__.py |  5 +++--
 pyanaconda/ui/gui/spokes/user.py   | 20 ++++++++++++++++++++
 pyanaconda/ui/tui/spokes/user.py   | 19 +++++++++++++++++++
 5 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/pyanaconda/constants.py b/pyanaconda/constants.py
index df06dfe..ee9ffdb 100644
--- a/pyanaconda/constants.py
+++ b/pyanaconda/constants.py
@@ -142,3 +142,5 @@ GEOLOC_GEOCODER_NOMINATIM = "geocoder_nominatim"
 GEOLOC_DEFAULT_PROVIDER = GEOLOC_PROVIDER_FEDORA_GEOIP
 GEOLOC_DEFAULT_GEOCODER = GEOLOC_GEOCODER_NOMINATIM
 
+ANACONDA_ENVIRON = "anaconda"
+FIRSTBOOT_ENVIRON = "firstboot"
diff --git a/pyanaconda/ui/common.py b/pyanaconda/ui/common.py
index 5248694..38b18c6 100644
--- a/pyanaconda/ui/common.py
+++ b/pyanaconda/ui/common.py
@@ -27,6 +27,9 @@ import copy
 import sys
 import types
 
+from pyanaconda.constants import ANACONDA_ENVIRON, FIRSTBOOT_ENVIRON
+from pykickstart.constants import FIRSTBOOT_RECONFIG
+
 import logging
 log = logging.getLogger("anaconda")
 
@@ -134,7 +137,22 @@ class FirstbootSpokeMixIn(object):
            It might be called multiple times, with or without (None)
            the data argument.
         """
-        return environment in ("anaconda", "firstboot")
+
+        if environment == ANACONDA_ENVIRON:
+            return True
+        elif environment == FIRSTBOOT_ENVIRON and data is None:
+            # cannot decide, stay in the game and let another call with data
+            # available (will come) decide
+            return True
+        elif environment == FIRSTBOOT_ENVIRON and \
+                data and data.firstboot.firstboot == FIRSTBOOT_RECONFIG:
+            # generally run spokes in firstboot only if doing reconfig, spokes
+            # that should run even if not doing reconfig should override this
+            # method
+            return True
+        else:
+            return False
+
 
 class FirstbootOnlySpokeMixIn(object):
     """This MixIn class marks Spokes as usable for Firstboot."""
@@ -149,7 +167,19 @@ class FirstbootOnlySpokeMixIn(object):
            It might be called multiple times, with or without (None)
            the data argument.
         """
-        return environment in ("firstboot")
+
+        if environment == FIRSTBOOT_ENVIRON and data is None:
+            # cannot decide, stay in the game and let another call with data
+            # available (will come) decide
+            return True
+        elif environment == FIRSTBOOT_ENVIRON and \
+                data and data.firstboot.firstboot == FIRSTBOOT_RECONFIG:
+            # generally run spokes in firstboot only if doing reconfig, spokes
+            # that should run even if not doing reconfig should override this
+            # method
+            return True
+        else:
+            return False
 
 class Spoke(UIObject):
     """A Spoke is a single configuration screen.  There are several different
@@ -225,7 +255,7 @@ class Spoke(UIObject):
            It might be called multiple times, with or without (None)
            the data argument.
         """
-        return environment in ("anaconda")
+        return environment == ANACONDA_ENVIRON
 
     def apply(self):
         """Apply the selections made on this Spoke to the object's preset
diff --git a/pyanaconda/ui/gui/hubs/__init__.py b/pyanaconda/ui/gui/hubs/__init__.py
index 1908fd7..dcf1368 100644
--- a/pyanaconda/ui/gui/hubs/__init__.py
+++ b/pyanaconda/ui/gui/hubs/__init__.py
@@ -33,6 +33,7 @@ from pyanaconda.ui.gui import GUIObject
 from pyanaconda.ui.gui.categories import collect_categories
 from pyanaconda.ui.gui.spokes import StandaloneSpoke, collect_spokes
 from pyanaconda.ui.gui.utils import gtk_call_once
+from pyanaconda.constants import ANACONDA_ENVIRON
 
 import logging
 log = logging.getLogger("anaconda")
@@ -168,9 +169,9 @@ class Hub(GUIObject, common.Hub):
             selectors = []
             for spokeClass in sorted(cats_and_spokes[c], key=lambda s: s.title):
                 # Check if this spoke is to be shown in anaconda
-                if not spokeClass.should_run("anaconda", self.data):
+                if not spokeClass.should_run(ANACONDA_ENVIRON, self.data):
                     continue
-    
+
                 # Create the new spoke and populate its UI with whatever data.
                 # From here on, this Spoke will always exist.
                 spoke = spokeClass(self.data, self.storage, self.payload, self.instclass)
diff --git a/pyanaconda/ui/gui/spokes/user.py b/pyanaconda/ui/gui/spokes/user.py
index 8548268..cacae20 100644
--- a/pyanaconda/ui/gui/spokes/user.py
+++ b/pyanaconda/ui/gui/spokes/user.py
@@ -31,6 +31,9 @@ from pyanaconda.ui.gui.categories.user_settings import UserSettingsCategory
 from pyanaconda.ui.common import FirstbootSpokeMixIn
 from pyanaconda.ui.gui.utils import enlightbox
 
+from pykickstart.constants import FIRSTBOOT_RECONFIG
+from pyanaconda.constants import ANACONDA_ENVIRON, FIRSTBOOT_ENVIRON
+
 import pwquality
 
 __all__ = ["UserSpoke", "AdvancedUserDialog"]
@@ -144,6 +147,23 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke):
     icon = "avatar-default-symbolic"
     title = N_("_USER CREATION")
 
+    @classmethod
+    def should_run(cls, environment, data):
+        # the user spoke should run always in the anaconda and in firstboot only
+        # when doing reconfig or if no user has been created in the installation
+        if environment == ANACONDA_ENVIRON:
+            return True
+        elif environment == FIRSTBOOT_ENVIRON and data is None:
+            # cannot decide, stay in the game and let another call with data
+            # available (will come) decide
+            return True
+        elif environment == FIRSTBOOT_ENVIRON and data and \
+                (data.firstboot.firstboot == FIRSTBOOT_RECONFIG or \
+                     len(data.user.userList) == 0):
+            return True
+        else:
+            return False
+
     def __init__(self, *args):
         NormalSpoke.__init__(self, *args)
         self._oldweak = None
diff --git a/pyanaconda/ui/tui/spokes/user.py b/pyanaconda/ui/tui/spokes/user.py
index ce53e1b..255ef41 100644
--- a/pyanaconda/ui/tui/spokes/user.py
+++ b/pyanaconda/ui/tui/spokes/user.py
@@ -26,6 +26,8 @@ from pyanaconda.ui.tui.simpleline import TextWidget
 from pyanaconda.ui.tui import YesNoDialog
 from pyanaconda.users import guess_username
 from pyanaconda.i18n import _
+from pykickstart.constants import FIRSTBOOT_RECONFIG
+from pyanaconda.constants import ANACONDA_ENVIRON, FIRSTBOOT_ENVIRON
 
 import re
 
@@ -45,6 +47,23 @@ class UserSpoke(FirstbootSpokeMixIn, EditTUISpoke):
         Entry("Groups", "_groups", re.compile("^([a-z0-9_]+)?(, ?([a-z0-9_]+))*$"), lambda self,args: args._create)
         ]
 
+    @classmethod
+    def should_run(cls, environment, data):
+        # the user spoke should run always in the anaconda and in firstboot only
+        # when doing reconfig or if no user has been created in the installation
+        if environment == ANACONDA_ENVIRON:
+            return True
+        elif environment == FIRSTBOOT_ENVIRON and data is None:
+            # cannot decide, stay in the game and let another call with data
+            # available (will come) decide
+            return True
+        elif environment == FIRSTBOOT_ENVIRON and data and \
+                (data.firstboot.firstboot == FIRSTBOOT_RECONFIG or \
+                     len(data.user.userList) == 0):
+            return True
+        else:
+            return False
+
     def __init__(self, app, data, storage, payload, instclass):
         FirstbootSpokeMixIn.__init__(self)
         EditTUISpoke.__init__(self, app, data, storage, payload, instclass)
-- 
1.7.11.7



More information about the anaconda-patches mailing list