11
sys.path.insert(0, '/usr/lib/ubiquity')
13
import ubiquity.frontend
15
background = '/usr/share/backgrounds/warty-final-ubuntu.png'
17
class XStartupError(EnvironmentError):
21
def __init__(self, vt, display):
23
self.display = display
24
self.server_started = False
26
# Look for a frontend module; we won't actually use it (yet), but
27
# this lets us find out which window manager etc. to launch. Be
28
# careful that importing this here will cause the underlying library
29
# to try to talk to the X server, which won't go well.
30
frontend_names = ['gtk_ui', 'kde_ui']
32
for f in frontend_names:
34
imp.find_module(f, ubiquity.frontend.__path__)
40
raise AttributeError, ('No frontend available; tried %s' %
41
', '.join(frontend_names))
43
def sigusr1_handler(self, signum, frame):
44
self.server_started = True
46
def server_preexec(self):
47
signal.signal(signal.SIGUSR1, signal.SIG_IGN)
49
def run(self, *program):
50
null = open('/dev/null', 'w')
51
if not os.path.exists('/var/log/installer'):
52
os.makedirs('/var/log/installer')
53
logfile = open('/var/log/installer/dm', 'w')
55
signal.signal(signal.SIGUSR1, self.sigusr1_handler)
56
signal.signal(signal.SIGTTIN, signal.SIG_IGN)
57
signal.signal(signal.SIGTTOU, signal.SIG_IGN)
58
server = subprocess.Popen(['X', '-br', '-ac', '-noreset', self.vt, self.display], stdin=null, stdout=logfile, stderr=logfile, preexec_fn=self.server_preexec)
60
os.environ['DISPLAY'] = self.display
62
# Really we should select on a pipe or something, but it's not worth
65
while not self.server_started:
67
raise XStartupError, "X server failed to start after 60 seconds"
71
if self.frontend == 'gtk_ui':
72
if os.access(background, os.R_OK):
74
pixbuf = gtk.gdk.pixbuf_new_from_file(background)
75
root = gtk.gdk.get_default_root_window()
76
(root_width, root_height) = root.get_size()
77
scaled = pixbuf.scale_simple(root_width, root_height, gtk.gdk.INTERP_BILINEAR)
78
(pixmap, mask) = scaled.render_pixmap_and_mask(0)
79
root.set_back_pixmap(pixmap, False)
83
if self.frontend == 'gtk_ui':
84
wm = subprocess.Popen(['/usr/bin/metacity', '--sm-disable'], stdin=null, stdout=logfile, stderr=logfile)
85
elif self.frontend == 'kde_ui':
86
wm = subprocess.Popen('/usr/bin/kwin', stdin=null, stdout=logfile, stderr=logfile)
88
greeter = subprocess.Popen(program, stdin=null, stdout=logfile, stderr=logfile)
91
def sigalrm_handler(signum, frame):
92
os.kill(wm.pid, signal.SIGKILL)
94
os.kill(wm.pid, signal.SIGTERM)
95
signal.signal(signal.SIGALRM, sigalrm_handler)
96
signal.alarm(1) # low patience with WMs failing to exit on demand
101
if e.errno == errno.EINTR:
106
os.kill(server.pid, signal.SIGTERM)
109
if ret is not None and ret >= 0:
114
if len(sys.argv) < 3:
115
sys.stderr.write('Usage: ubiquity-dm <vt[1-N]> <:[0-N]> <program> [<arguments>]\n')
118
vt, display = sys.argv[1:3]
120
sys.exit(dm.run(*sys.argv[3:]))