[PATCH 2/6] Link to the correct default target

Jesse Keating jkeating at redhat.com
Tue Nov 13 05:50:56 UTC 2012


This uses the new constant to link to the right target by name.  It also
removes any fiddling with /etc/inittab as we don't want/need to touch
that any more.
---
 pyanaconda/desktop.py | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/pyanaconda/desktop.py b/pyanaconda/desktop.py
index 263c543..b6207a6 100644
--- a/pyanaconda/desktop.py
+++ b/pyanaconda/desktop.py
@@ -21,7 +21,7 @@
 
 import string, os
 from simpleconfig import SimpleConfigFile
-from pyanaconda.constants import ROOT_PATH
+from pyanaconda.constants import ROOT_PATH, RUNLEVELS
 
 import logging
 log = logging.getLogger("anaconda")
@@ -32,7 +32,7 @@ class Desktop (SimpleConfigFile):
 # to start in
 #
     def setDefaultRunLevel(self, runlevel):
-        if str(runlevel) != "3" and str(runlevel) != "5":
+        if int(runlevel) not in RUNLEVELS.keys():
             raise RuntimeError, "Desktop::setDefaultRunLevel() - Must specify runlevel as 3 or 5!"
         self.runlevel = runlevel
 
@@ -55,26 +55,11 @@ class Desktop (SimpleConfigFile):
             f.write(str (self))
             f.close()
 
-        try:
-            inittab = open (ROOT_PATH + '/etc/inittab', 'r')
-        except IOError:
-            log.warning ("there is no inittab, bad things will happen!")
-            return
-        lines = inittab.readlines ()
-        inittab.close ()
-        inittab = open (ROOT_PATH + '/etc/inittab', 'w')        
-        for line in lines:
-            if len (line) > 3 and line[:3] == "id:":
-                fields = string.split (line, ':')
-                fields[1] = str (self.runlevel)
-                line = string.join (fields, ':')
-            inittab.write (line)
-        inittab.close ()
-
         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/runlevel' + str(self.runlevel) + '.target', default_target)
+        os.symlink('/lib/systemd/system/%s' % RUNLEVELS[self.runlevel],
+                   default_target)
-- 
1.7.11.4



More information about the anaconda-patches mailing list