home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / xserver.py < prev   
Encoding:
Python Source  |  2000-03-08  |  7.0 KB  |  260 lines

  1. import os
  2. import string
  3. import kudzu
  4. import isys
  5. import sys
  6. import time
  7. from xf86config import *
  8. from kbd import Keyboard
  9.  
  10. def startX():
  11.     global serverPath
  12.     global mode
  13.     
  14.     os.environ['DISPLAY'] = ':1'
  15.     serverPath = None
  16.  
  17.     print "Probing for mouse type..."
  18.     mice = kudzu.probe (kudzu.CLASS_MOUSE,
  19.                         kudzu.BUS_UNSPEC,
  20.                         kudzu.PROBE_ONE);
  21.     if not mice:
  22.         raise RuntimeError, "Unable to find a mouse!"
  23.  
  24.     device = None
  25.     mouseProtocol = None
  26.     (mouseDev, driver, descr) = mice[0]
  27.     if mouseDev == 'psaux':
  28.         mouseProtocol = "PS/2"
  29.     mouseEmulate = 0
  30.         # kickstart some ps/2 mice.  Blame the kernel
  31.         try:
  32.             f = open ('/dev/psaux')
  33.             f.write ('1')
  34.             f.close
  35.         except:
  36.             pass
  37.     elif mouseDev == 'sunmouse':
  38.     mouseProtocol = "sun"
  39.     mouseEmulate = 0
  40.     else:
  41.         mouseProtocol = "Microsoft"
  42.     mouseEmulate = 1
  43.  
  44.     x = XF86Config ((mouseProtocol, mouseEmulate, mouseDev))
  45.     x.probe ()
  46.     if x.server and len (x.server) >= 3 and x.server[0:3] == 'Sun':
  47.     serverPath = '/usr/X11R6/bin/Xs' + x.server[1:]
  48.     elif x.server:
  49.         serverPath = '/usr/X11R6/bin/XF86_' + x.server
  50.     elif iutil.getArch() == "sparc":
  51.     raise RuntimeError, "Unknown card"
  52.     else:
  53.         print "Unknown card, falling back to VGA16"
  54.         serverPath = '/usr/X11R6/bin/XF86_VGA16'
  55.  
  56.     if not os.access (serverPath, os.X_OK):
  57.     if iutil.getArch() == "sparc":
  58.         raise RuntimeError, "Missing X server"
  59.         print serverPath, "missing.  Falling back to VGA16"
  60.         serverPath = '/usr/X11R6/bin/XF86_VGA16'
  61.         
  62.     keycodes = "xfree86"
  63.     symbols = "us(pc101)"
  64.     geometry = "pc"
  65.     rules = "xfree86"
  66.     model = "pc101"
  67.  
  68.     kbd = Keyboard()
  69.     if kbd.type == 'Sun':
  70.     rules = "sun"
  71.     model = kbd.model
  72.     keycodes = "sun(" + kbd.model + ")"
  73.     if model == 'type4':
  74.         geometry = "sun(type4)"
  75.         symbols = "sun/us(sun4)"
  76.     else:
  77.         if model == 'type5':
  78.         geometry = "sun"
  79.         elif model == 'type5_euro':
  80.         geometry = "sun(type5euro)"
  81.         else:
  82.         geometry = "sun(type5unix)"
  83.         symbols = "sun/us(sun5)"
  84.     if kbd.layout == 'en_US':
  85.         symbols = symbols + "+iso9995-3(basic)"
  86.     elif kbd.layout != 'us':
  87.         symbols = symbols + "+" + kbd.layout
  88.         
  89.     mouseEmulateStr="""
  90.     Emulate3Buttons
  91.     Emulate3Timeout    50
  92. """
  93.     if not mouseEmulate:
  94.     mouseEmulateStr=""
  95.     settings = { "mouseDev" : '/dev/' + mouseDev ,
  96.                  "mouseProto" : mouseProtocol,
  97.          "keycodes" : keycodes,
  98.          "symbols" : symbols,
  99.          "geometry" : geometry,
  100.          "rules" : rules,
  101.          "model" : model,
  102.          "emulate" : mouseEmulateStr }
  103.     f = open ('/tmp/XF86Config', 'w')
  104.     f.write ("""
  105. Section "Files"
  106.     RgbPath    "/usr/X11R6/lib/X11/rgb"
  107.     FontPath    "/usr/X11R6/lib/X11/fonts/misc/"
  108.     FontPath    "/usr/X11R6/lib/X11/fonts/Type1/"
  109.     FontPath    "/usr/X11R6/lib/X11/fonts/Speedo/"
  110.     FontPath    "/usr/X11R6/lib/X11/fonts/75dpi/"
  111.     FontPath    "/usr/X11R6/lib/X11/fonts/100dpi/"
  112.     FontPath    "/usr/X11R6/lib/X11/fonts/cyrillic/"
  113.     FontPath    "/usr/share/fonts/ISO8859-2/misc/"
  114.     FontPath    "/usr/share/fonts/ISO8859-2/75dpi/"
  115.     FontPath    "/usr/share/fonts/ISO8859-2/100dpi/"
  116.     FontPath    "/usr/share/fonts/ISO8859-9/misc/"
  117.     FontPath    "/usr/share/fonts/ISO8859-9/75dpi/"
  118.     FontPath    "/usr/share/fonts/ISO8859-9/100dpi/"
  119. EndSection
  120.  
  121. Section "ServerFlags"
  122. EndSection
  123.  
  124. Section "Keyboard"
  125.     Protocol    "Standard"
  126.     AutoRepeat  500 5
  127.     LeftAlt     Meta
  128.     RightAlt    Meta
  129.     ScrollLock  Compose
  130.     RightCtl    Control
  131.     XkbKeycodes     "%(keycodes)s"
  132.     XkbTypes        "default"
  133.     XkbCompat       "default"
  134.     XkbSymbols      "%(symbols)s"
  135.     XkbGeometry     "%(geometry)s"
  136.     XkbRules        "%(rules)s"
  137.     XkbModel        "%(model)s"
  138.     XkbLayout       "us"
  139. EndSection
  140.  
  141. Section "Pointer"
  142.     Protocol    "%(mouseProto)s"
  143.     Device      "%(mouseDev)s"
  144. %(emulate)s
  145. EndSection
  146. """ % settings)
  147.     f.write (x.monitorSection (1))
  148.     f.write (x.deviceSection ())
  149.     if x.monSect:
  150.     bpp = x.bpp
  151.     else:
  152.         x.modes["32"] = [ ]
  153.         x.modes["16"] = [ ]
  154.         x.modes["8"] = [ "640x480" ]
  155.     bpp = None
  156.     f.write (x.screenSection (1))
  157.     f.close ()
  158.  
  159.     server = os.fork()
  160.     if (not server):
  161.         print "starting", serverPath
  162.     args = [serverPath, ':1', 'vt7', '-s', '1440', '-terminate']
  163.     if serverPath[0:19] == '/usr/X11R6/bin/Xsun':
  164.         try:
  165.         os.unlink("/dev/mouse")
  166.         except:
  167.         pass
  168.         try:
  169.         f = open("/dev/tty5", "w")
  170.         f.write("\n")
  171.         f.close()
  172.         except:
  173.         pass
  174.         os.symlink(mouseDev, "/dev/mouse")
  175.         if x.device:
  176.         args.append ("-dev")
  177.         args.append ('/dev/' + x.device)
  178.         args.append("-fp")
  179.         args.append("/usr/X11R6/lib/X11/fonts/misc/,"
  180.             "/usr/X11R6/lib/X11/fonts/75dpi/,"
  181.             "/usr/X11R6/lib/X11/fonts/100dpi/,"
  182.             "/usr/X11R6/lib/X11/fonts/cyrillic/,"
  183.             "/usr/share/fonts/ISO8859-2/misc/,"
  184.             "/usr/share/fonts/ISO8859-2/75dpi/,"
  185.             "/usr/share/fonts/ISO8859-2/100dpi/")
  186.     else:
  187.         args.append("-xf86config")
  188.         args.append("/tmp/XF86Config")
  189.         if bpp:
  190.         args.append("-bpp")
  191.         args.append(bpp)
  192.     os.execv(serverPath, args)
  193.  
  194.     # give time for the server to fail (if it is going to fail...)
  195.     # FIXME: Should find out if X server is already running
  196.     # otherwise with NFS installs the X server may be still being
  197.     # fetched from the network while we already continue to run
  198.     time.sleep (4)
  199.     pid, status = os.waitpid (server, os.WNOHANG)
  200.     if status:
  201.         raise RuntimeError, "X server failed to start"
  202.         
  203.     child = os.fork()
  204.     if (child):
  205.         try:
  206.             pid, status = os.waitpid(child, 0)
  207.         except:
  208.             sys.exit (-1)
  209.     try:
  210.         sys.kill(server, 15)
  211.         pid, status = os.waitpid(server, 0)
  212.     except:
  213.         sys.exit(0)
  214.  
  215.         sys.exit((status >> 8) & 0xf)
  216.  
  217.     return ((mouseProtocol, mouseEmulate, mouseDev), x)
  218.  
  219.  
  220.  
  221. #
  222. # to start X server using existing XF86Config file (reconfig mode use only)
  223. #
  224. def start_existing_X():
  225.  
  226.     os.environ['DISPLAY'] = ':1'
  227.  
  228.     server = os.fork()
  229.     serverPath = "/etc/X11/X"
  230.  
  231.     # override fontpath because xfs is not running yet!
  232.     if (not server):
  233.         print "Starting X using existing XF86Config"
  234.     args = [serverPath, ':1', 'vt7', '-s', '1440', '-terminate']
  235.     args.append("-fp")
  236.     args.append("/usr/X11R6/lib/X11/fonts/misc/,"
  237.              "/usr/X11R6/lib/X11/fonts/75dpi/,"
  238.             "/usr/X11R6/lib/X11/fonts/100dpi/,"
  239.             "/usr/X11R6/lib/X11/fonts/cyrillic/,"
  240.             "/usr/share/fonts/ISO8859-2/misc/,"
  241.             "/usr/share/fonts/ISO8859-2/75dpi/,"
  242.             "/usr/share/fonts/ISO8859-2/100dpi/")
  243.  
  244.         print args
  245.     os.execv(serverPath, args)
  246.  
  247.     # give time for the server to fail (if it is going to fail...)
  248.     # FIXME: Should find out if X server is already running
  249.     # otherwise with NFS installs the X server may be still being
  250.     # fetched from the network while we already continue to run
  251.     time.sleep (4)
  252.     pid, status = os.waitpid (server, os.WNOHANG)
  253.     if status:
  254.         raise RuntimeError, "X server failed to start"
  255.  
  256.     # startX() function above does a double-fork here, do we need to in
  257.     # reconfig mode?
  258.     
  259.     return (None, None)
  260.