# License: This file is licensed under the GPL v2.
###############################################################################
-import os, subprocess, sys, tempfile, time, traceback
+import fileinput, os, subprocess, sys, tempfile, time, traceback
from optparse import OptionParser
class Section(object):
for depth in [8, 15, 16, 24, 32]:
screen.subsect += "SubSection \"Display\"\n\tDepth %d\n\tModes \"%s\"\t\nEndSubSection\n" % (depth, options.mode)
- if len(args) == 1:
- window_manager = args[0]
- wm_path = which(window_manager)
- if not wm_path:
- print "E: Cannot find window manager %r, aborting." % window_manager
- return 2
- run_program(["sudo", "update-alternatives", "--set", "x-window-manager", wm_path])
-
- config_empty = True
- if monitor or device or len(screen.data) > 0 or screen.subsect != '':
- config_empty = False
+ xinitrc = '~/.xinitrc'
+ if 'XINITRC' in os.environ: xinitrc = os.environ['XINITRC']
+ xinitrc = os.path.expanduser(xinitrc)
+
+ window_manager = 'x-window-manager'
+ if len(args) == 1: window_manager = args[0]
+ window_manager_path = which(window_manager)
+ if not window_manager_path:
+ print "E: Cannot find window manager %r, aborting." % window_manager
+ return 2
+
+ wm_exec = "exec %s\n" % window_manager_path
+ if not os.path.exists(xinitrc):
+ f = open(xinitrc, 'w')
+ f.write("#!/bin/sh\n")
+ f.write(wm_exec)
+ f.close()
+ else:
+ f = open(xinitrc, 'r')
+ lines = f.readlines()
+ f.close()
+ f = open(xinitrc, 'w')
+ for line in lines:
+ if line.startswith('exec '): line = wm_exec
+ f.write(line)
+ os.fchmod(f.fileno(), 0750)
+ f.close()
# write new config
- if not config_empty:
+ if monitor or device or len(screen.data) > 0 or screen.subsect != '':
try:
f = tempfile.NamedTemporaryFile(delete=False)
f.write('# Automatically generated by grml-x.\n')
f.close()
if options.start_server:
- xinitrc = '~/.xinitrc'
- if 'XINITRC' in os.environ: xinitrc = os.environ['XINITRC']
- xinitrc = os.path.expanduser(xinitrc)
- startx = ['startx']
- if os.path.exists(xinitrc):
- startx.append(xinitrc)
- else:
- startx.append(which('x-window-manager'))
- startx.append('--')
+ startx = ['startx', xinitrc, '--']
if options.display: startx.append(':' + options.display)
print "Starting X: %r" % startx
run_program(startx)