2011-01-18 09:24:57 +00:00
|
|
|
#
|
|
|
|
# desktop.py - install data for default desktop and run level
|
|
|
|
#
|
|
|
|
# Copyright (C) 2001, 2002 Red Hat, Inc. All rights reserved.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# Author(s): Matt Wilson <msw@redhat.com>
|
|
|
|
#
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
import os
|
2011-01-18 09:24:57 +00:00
|
|
|
from simpleconfig import SimpleConfigFile
|
2013-01-23 17:28:19 +00:00
|
|
|
from pyanaconda.constants import ROOT_PATH, RUNLEVELS
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger("anaconda")
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
class Desktop(SimpleConfigFile):
|
2011-01-18 09:24:57 +00:00
|
|
|
#
|
|
|
|
# This class represents the default desktop to run and the default runlevel
|
|
|
|
# to start in
|
|
|
|
#
|
|
|
|
def setDefaultRunLevel(self, runlevel):
|
2013-01-23 17:28:19 +00:00
|
|
|
if int(runlevel) not in RUNLEVELS:
|
2011-01-18 09:24:57 +00:00
|
|
|
raise RuntimeError, "Desktop::setDefaultRunLevel() - Must specify runlevel as 3 or 5!"
|
|
|
|
self.runlevel = runlevel
|
|
|
|
|
|
|
|
def getDefaultRunLevel(self):
|
|
|
|
return self.runlevel
|
|
|
|
|
|
|
|
def setDefaultDesktop(self, desktop):
|
|
|
|
self.info["DESKTOP"] = desktop
|
|
|
|
|
|
|
|
def getDefaultDesktop(self):
|
|
|
|
return self.get("DESKTOP")
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
def __init__(self):
|
|
|
|
super(Desktop, self).__init__()
|
2011-01-18 09:24:57 +00:00
|
|
|
self.runlevel = 3
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
def write(self):
|
2011-01-18 09:24:57 +00:00
|
|
|
if self.getDefaultDesktop():
|
2013-01-23 17:28:19 +00:00
|
|
|
f = open(ROOT_PATH + "/etc/sysconfig/desktop", "w")
|
|
|
|
f.write(str(self))
|
2011-01-18 09:24:57 +00:00
|
|
|
f.close()
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
os.symlink('/lib/systemd/system/%s' % RUNLEVELS[self.runlevel],
|
|
|
|
default_target)
|