[PATCH] The Desktop class doesn't need to inherit from SimpleConfigFile.
David Shea
dshea at redhat.com
Thu Sep 12 17:43:53 UTC 2013
On 09/12/2013 12:54 PM, Chris Lumens wrote:
> We barely use the superclass anyway.
> ---
> pyanaconda/desktop.py | 43 ++++++++++++++++++-------------------------
> pyanaconda/kickstart.py | 4 ++--
> 2 files changed, 20 insertions(+), 27 deletions(-)
>
> diff --git a/pyanaconda/desktop.py b/pyanaconda/desktop.py
> index 3d73d32..3976485 100644
> --- a/pyanaconda/desktop.py
> +++ b/pyanaconda/desktop.py
> @@ -17,47 +17,40 @@
> # along with this program. If not, see <http://www.gnu.org/licenses/>.
> #
> # Author(s): Matt Wilson <msw at redhat.com>
> +# Chris Lumens <clumens at redhat.com>
> #
>
> import os
> -from simpleconfig import SimpleConfigFile
> from pyanaconda.constants import ROOT_PATH, RUNLEVELS
>
> import logging
> log = logging.getLogger("anaconda")
>
> -class Desktop(SimpleConfigFile):
> -#
> -# This class represents the default desktop to run and the default runlevel
> -# to start in
> -#
> - def setDefaultRunLevel(self, runlevel):
> - if int(runlevel) not in RUNLEVELS:
> - raise RuntimeError("Desktop::setDefaultRunLevel() - Must specify runlevel as 3 or 5!")
> - self.runlevel = runlevel
> -
> - def getDefaultRunLevel(self):
> - return self.runlevel
> +class Desktop(object):
> + def __init__(self):
> + self._runlevel = 3
> + self.desktop = None
>
> - def setDefaultDesktop(self, desktop):
> - self.info["DESKTOP"] = desktop
> + @property
> + def runlevel(self):
> + return self._runlevel
>
> - def getDefaultDesktop(self):
> - return self.get("DESKTOP")
> + @runlevel.setter
> + def runlevel(self, runlevel):
> + if int(runlevel) not in RUNLEVELS:
> + raise RuntimeError("Desktop::setDefaultRunLevel() - Must specify runlevel as one of %s" % RUNLEVELS.keys())
>
> - def __init__(self):
> - super(Desktop, self).__init__()
> - self.runlevel = 3
> + self._runlevel = runlevel
>
> - def write(self, filename=None, use_tmp=True):
> - if self.getDefaultDesktop():
> - f = open(ROOT_PATH + "/etc/sysconfig/desktop", "w")
> - f.write(str(self))
> - f.close()
> + def write(self):
> + if self.desktop:
> + with open(ROOT_PATH + "/etc/sysconfig/desktop", "w") as f:
> + f.write("DESKTOP=%s\n" % self.desktop)
>
> if not os.path.isdir(ROOT_PATH + '/etc/systemd/system'):
> log.warning("there is no /etc/systemd/system directory, cannot update default.target!")
> return
> +
> default_target = ROOT_PATH + '/etc/systemd/system/default.target'
> if os.path.islink(default_target):
> os.unlink(default_target)
> diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
> index 3963889..f61d2c3 100644
> --- a/pyanaconda/kickstart.py
> +++ b/pyanaconda/kickstart.py
> @@ -1400,10 +1400,10 @@ class XConfig(commands.xconfig.F14_XConfig):
> def execute(self, *args):
> desktop = Desktop()
> if self.startX:
> - desktop.setDefaultRunLevel(5)
> + desktop.runlevel = 5
>
> if self.defaultdesktop:
> - desktop.setDefaultDesktop(self.defaultdesktop)
> + desktop.desktop = self.defaultdesktop
>
> # now write it out
> desktop.write()
Ack to both
More information about the anaconda-patches
mailing list