[firstboot 02/13] Rewritten frontend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 firstboot/frontend.py  |  146 ++++++++++++++++++++++++++++++++++++++++++++++++
 firstboot/xfrontend.py |  146 ------------------------------------------------
 2 files changed, 146 insertions(+), 146 deletions(-)
 create mode 100644 firstboot/frontend.py
 delete mode 100644 firstboot/xfrontend.py

diff --git a/firstboot/frontend.py b/firstboot/frontend.py
new file mode 100644
index 0000000..1d6d93d
--- /dev/null
+++ b/firstboot/frontend.py
@@ -0,0 +1,146 @@
+#
+# frontend.py
+#
+# Copyright (C) 2011  Red Hat, Inc.
+#
+# 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/>.
+#
+# Red Hat Author(s):  Martin Gracik <mgracik@xxxxxxxxxx>
+#
+
+import logging
+import os
+import shlex
+import signal
+import subprocess
+
+from .constants import *
+
+from system_config_keyboard import keyboard
+
+
+# set up logging
+logging.basicConfig(level=logging.DEBUG)
+log = logging.getLogger('firstboot.frontend')
+
+
+class Frontend:
+
+    def __init__(self):
+        self.x = None
+        self.wm_pid = None
+
+    def set_lang(self):
+        i18n = shlex.split(open(I18N).read())
+        i18n = dict(item.split('=') for item in i18n)
+        if 'LANG' in i18n:
+            log.info('setting LANG to %s', i18n['LANG'])
+            os.environ['LANG'] = i18n['LANG']
+
+    def startx(self):
+        def sigusr1_handler(num, frame):
+            pass
+
+        def sigchld_handler(num, frame):
+            raise OSError
+
+        def preexec_fn():
+            signal.signal(signal.SIGUSR1, signal.SIG_IGN)
+
+        old_sigusr1 = signal.signal(signal.SIGUSR1, sigusr1_handler)
+        old_sigchld = signal.signal(signal.SIGCHLD, sigchld_handler)
+
+        os.environ['DISPLAY'] = DISPLAY
+        cmd = ['Xorg', os.environ['DISPLAY'],
+               '-ac', '-nolisten', 'tcp', VT]
+
+        devnull = os.open('/dev/null', os.O_RDWR)
+
+        try:
+            log.info('starting the Xorg server')
+            self.x = subprocess.Popen(cmd, stdout=devnull, stderr=devnull,
+                                      preexec_fn=preexec_fn)
+
+        except OSError as e:
+            err = 'Xorg server failed to start: %s' % e
+            log.critical(err)
+            raise RuntimeError(err)
+
+        signal.pause()
+        signal.signal(signal.SIGUSR1, old_sigusr1)
+        signal.signal(signal.SIGCHLD, old_sigchld)
+
+        log.info('Xorg server started successfully')
+
+        # XXX no need to close devnull?
+
+    def init_gtk(self):
+        rd, wr = os.pipe()
+        pid = os.fork()
+        if not pid:
+            import gtk
+            os.write(wr, '#')
+
+            kbd = keyboard.Keyboard()
+            kbd.read()
+            kbd.activate()
+
+            gtk.main()
+            os._exit(0)
+
+        os.read(rd, 1)
+        os.close(rd)
+        os.close(wr)
+
+    def start_wm(self):
+        path = os.environ['PATH'].split(':')
+        wms = [os.path.join(p, wm) for wm in WMS for p in path]
+        available = [wm for wm in wms if os.access(wm, os.X_OK)]
+        if not available:
+            err = 'no window manager available'
+            log.critical(err)
+            raise RuntimeError(err)
+
+        wm = available[0]
+        cmd = [wm, '--display', os.environ['DISPLAY']]
+
+        self.wm_pid = os.fork()
+        if not self.wm_pid:
+            log.info('starting the window manager')
+            os.execvp(wm, cmd)
+
+        try:
+            pid, status = os.waitpid(self.wm_pid, os.WNOHANG)
+        except OSError as e:
+            err = 'window manager failed to start: %s' % e
+            log.critical(err)
+            raise RuntimeError(err)
+
+        log.info('window manager started successfully')
+
+    def merge_xres(self):
+        if os.access(XRES, os.R_OK):
+            log.info('merging the Xresources')
+            p = subprocess.Popen(['xrdb', '--merge', XRES])
+            p.wait()
+
+    def kill(self):
+        if self.wm_pid:
+            log.info('killing the window manager')
+            os.kill(self.wm_pid, 15)
+
+        if self.x:
+            log.info('killing the Xorg server')
+            os.kill(self.x.pid, 15)
+            self.x.wait()
diff --git a/firstboot/xfrontend.py b/firstboot/xfrontend.py
deleted file mode 100644
index d796fbc..0000000
--- a/firstboot/xfrontend.py
+++ /dev/null
@@ -1,146 +0,0 @@
-#
-# Chris Lumens <clumens@xxxxxxxxxx>
-#
-# Copyright 2007, 2008 Red Hat, Inc.
-#
-# This copyrighted material is made available to anyone wishing to use, modify,
-# copy, or redistribute it subject to the terms and conditions of the GNU
-# General Public License v.2.  This program is distributed in the hope that it
-# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
-# implied warranties 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, write to the Free Software Foundation, Inc., 51
-# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
-# trademarks that are incorporated in the source code or documentation are not
-# subject to the GNU General Public License and may only be used or replicated
-# with the express permission of Red Hat, Inc. 
-#
-import logging
-import os, string, subprocess, sys, signal, shlex
-
-##
-## I18N
-##
-import gettext
-_ = lambda x: gettext.ldgettext("firstboot", x)
-
-class XFrontEnd:
-    def __init__(self):
-        self._wm_pid = None
-        self.x = None
-
-    def _mergeXresources(self):
-        path = "/etc/X11/Xresources"
-        if os.access(path, os.R_OK):
-            os.system("xrdb -merge %s" % path)
-
-    # Attempt to start up the window manager.  Check the value of self.wm_pid
-    # afterwards to see if this succeeded.
-    def _startWindowManager(self):
-        self._wm_pid = os.fork()
-
-        if not self._wm_pid:
-            paths = ["/usr/bin/metacity", "/usr/bin/kwin", "/usr/bin/xfwm4",
-                     "/usr/bin/openbox"]
-            for path in paths:
-                if os.access(path, os.X_OK):
-                    break
-
-            args = [path, "--display", os.environ["DISPLAY"]]
-            os.execvp(path, args)
-
-        status = 0
-        try:
-            (pid, status) = os.waitpid (self._wm_pid, os.WNOHANG)
-        except OSError, (errno, msg):
-            logging.error ("starting window manager failed: %s" % msg)
-
-        if status:
-            raise RuntimeError, "Window manager failed to start."
-
-    # Initializes the UI for firstboot by starting up an X server and
-    # window manager, but returns control to the caller to proceed.
-    def start(self):
-        os.environ["DISPLAY"] = ":9"
-
-        # set up the lang variable according to what's set in i18n
-        with open("/etc/sysconfig/i18n", "r") as f:
-            data = f.read()
-        for line in shlex.split(data):
-            key, value = line.split("=")
-            if key == "LANG":
-                os.environ[key] = value
-                break
-
-        try:
-            args = [":9", "-ac", "-nolisten", "tcp", "vt1"]
-            noOutput = os.open("/dev/null", os.O_RDWR)
-
-            def sigchld_handler(num, frame):
-                raise OSError
-
-            def sigusr1_handler(num, frame):
-                pass
-
-            def preexec_fn():
-                signal.signal(signal.SIGUSR1, signal.SIG_IGN)
-
-            old_sigusr1 = signal.signal(signal.SIGUSR1, sigusr1_handler)
-            old_sigchld = signal.signal(signal.SIGCHLD, sigchld_handler)
-            self.x = subprocess.Popen(["/usr/bin/Xorg"] + args,
-                                      stdout=noOutput, stderr=noOutput,
-                                      preexec_fn=preexec_fn)
-            signal.pause()
-            signal.signal(signal.SIGUSR1, old_sigusr1)
-            signal.signal(signal.SIGCHLD, old_sigchld)
-
-        except OSError:
-            logging.error("X server failed to start")
-            raise RuntimeError, "X server failed to start"
-        except:
-            import traceback
-            (ty, value, tb) = sys.exc_info()
-            lst = traceback.format_exception (ty, value, tb)
-            text = string.joinfields (lst, "")
-            print text
-
-            logging.error("X server failed to start")
-            raise RuntimeError, "X server failed to start"
-
-        logging.info("X server started successfully.")
-
-        # Init GTK to connect to the X server, then write a token on a pipe to
-        # tell our parent process that we're ready to start metacity.
-        (rd, wr) = os.pipe()
-        pid = os.fork()
-        if not pid:
-            import gtk
-            os.write(wr, "#")
-
-            # Set up the keyboard.
-            import system_config_keyboard.keyboard as keyboard
-            kbd = keyboard.Keyboard()
-            kbd.read()
-            kbd.activate()
-
-            # Block until the X server is killed.
-            gtk.main()
-            os._exit(0)
-
-        # Block on read of token
-        os.read(rd, 1)
-        os.close(rd)
-        os.close(wr)
-
-        self._wm_pid = self._startWindowManager()
-        self._mergeXresources()
-
-    def stop(self):
-        if self._wm_pid:
-            os.kill(self._wm_pid, 15)
-
-        if self.x:
-            os.kill(self.x.pid, 15)
-            self.x.wait()
-- 
1.7.3.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux