Package pyanaconda :: Module desktop
[hide private]
[frames] | no frames]

Source Code for Module pyanaconda.desktop

 1  # 
 2  # desktop.py - install data for default desktop and run level 
 3  # 
 4  # Copyright (C) 2001, 2002  Red Hat, Inc.  All rights reserved. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU General Public License as published by 
 8  # the Free Software Foundation; either version 2 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
18  # 
19  # Author(s): Matt Wilson <msw@redhat.com> 
20  # 
21   
22  import string, os 
23  from simpleconfig import SimpleConfigFile 
24  from pyanaconda.constants import ROOT_PATH 
25   
26  import logging 
27  log = logging.getLogger("anaconda") 
28   
29 -class Desktop (SimpleConfigFile):
30 # 31 # This class represents the default desktop to run and the default runlevel 32 # to start in 33 #
34 - def setDefaultRunLevel(self, runlevel):
35 if str(runlevel) != "3" and str(runlevel) != "5": 36 raise RuntimeError, "Desktop::setDefaultRunLevel() - Must specify runlevel as 3 or 5!" 37 self.runlevel = runlevel
38
39 - def getDefaultRunLevel(self):
40 return self.runlevel
41
42 - def setDefaultDesktop(self, desktop):
43 self.info["DESKTOP"] = desktop
44
45 - def getDefaultDesktop(self):
46 return self.get("DESKTOP")
47
48 - def __init__ (self):
49 SimpleConfigFile.__init__ (self) 50 self.runlevel = 3
51
52 - def write(self):
53 if self.getDefaultDesktop(): 54 f = open(ROOT_PATH + "/etc/sysconfig/desktop", "w") 55 f.write(str (self)) 56 f.close() 57 58 try: 59 inittab = open (ROOT_PATH + '/etc/inittab', 'r') 60 except IOError: 61 log.warning ("there is no inittab, bad things will happen!") 62 return 63 lines = inittab.readlines () 64 inittab.close () 65 inittab = open (ROOT_PATH + '/etc/inittab', 'w') 66 for line in lines: 67 if len (line) > 3 and line[:3] == "id:": 68 fields = string.split (line, ':') 69 fields[1] = str (self.runlevel) 70 line = string.join (fields, ':') 71 inittab.write (line) 72 inittab.close () 73 74 if not os.path.isdir(ROOT_PATH + '/etc/systemd/system'): 75 log.warning("there is no /etc/systemd/system directory, cannot update default.target!") 76 return 77 default_target = ROOT_PATH + '/etc/systemd/system/default.target' 78 if os.path.islink(default_target): 79 os.unlink(default_target) 80 os.symlink('/lib/systemd/system/runlevel' + str(self.runlevel) + '.target', default_target)
81