/[gli]/branches/overhaul/src/GLIClientController.py
Gentoo

Contents of /branches/overhaul/src/GLIClientController.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1633 - (show annotations) (download) (as text)
Mon Jan 22 01:43:13 2007 UTC (7 years, 10 months ago) by agaffney
File MIME type: text/x-python
File size: 8283 byte(s)
pass instantiated IP object to CC's __init__()
1 """
2 # Copyright 1999-2005 Gentoo Foundation
3 # This source code is distributed under the terms of version 2 of the GNU
4 # General Public License as published by the Free Software Foundation, a copy
5 # of which can be found in the main directory of this project.
6 Gentoo Linux Installer
7
8 $Id: GLIClientController.py,v 1.84 2006/07/17 18:18:27 agaffney Exp $
9 Copyright 2004 Gentoo Technologies Inc.
10
11 Steps (based on the ClientConfiguration):
12 1. Load any modules? (this may have to be done manually, using a shell - not implemented)
13 2. Set the root password (may need to generate one. GLIUtility.generate_random_password())
14 3. Add users? (not implemented yet)
15 4. Start ssh
16 5. Network setup
17 6. Start the ArchTemplate doing it's thing. - maybe.. this might get called from elsewhere
18
19 """
20
21 import os, sys, Queue, traceback, platform
22 from threading import Thread, Event
23 #import GLIInstallProfile
24 #import GLIUtility
25 import GLILogger
26 #import GLIArchitectureTemplate
27 import GLINotification
28 from GLIException import *
29
30 # Global constants for notifications
31 NEXT_STEP_READY = 1
32 INSTALL_DONE = 2
33
34 TEMPLATE_DIR = 'templates'
35 LOGFILE = '/var/log/installer.log'
36
37 ##
38 # This class provides an interface between the backend and frontend
39 class GLIClientController(Thread):
40
41 ##
42 # Initialization function for the GLIClientController class
43 # @param install_profile=None GLIInstallProfile object
44 # @param pretend=False Pretend mode. If pretending, no steps will actually be performed
45 def __init__(self,install_profile=None,pretend=False,verbose=True):
46 Thread.__init__(self)
47
48 self.set_install_profile(install_profile)
49 self._install_event = Event()
50 self._notification_queue = Queue.Queue(50)
51 self._install_mode = None
52 self._install_step = -1
53 self._install_steps = None
54 self._verbose = verbose
55 self._pretend = pretend
56 self._thread_pid = 0
57 self.setDaemon(True)
58 self._logger = GLILogger.Logger(LOGFILE)
59 self._arch_template = None
60
61 subarches = { 'i386': 'x86', 'i486': 'x86', 'i586': 'x86', 'i686': 'x86', 'x86_64': 'amd64', 'parisc': 'hppa' }
62 self.arch = platform.machine()
63 if self.arch in subarches:
64 self.arch = subarches[self.arch]
65
66 self.start()
67
68 ##
69 # Sets the GLIInstallProfile object
70 # @param install_profile GLIInstallProfile object
71 def set_install_profile(self, install_profile):
72 self._install_profile = install_profile
73
74 ##
75 # Returns the GLIInstallProfile object
76 def get_install_profile(self):
77 return self._install_profile
78
79 ##
80 # Returns the architecture we're running on
81 def get_arch(self):
82 return self.arch
83
84 ##
85 # This function runs as a second thread to do the actual installation (only used internally)
86 def run(self):
87 self._thread_pid = os.getpid()
88 if self._verbose: self._logger.log("DEBUG: secondary thread PID is " + str(self._thread_pid))
89
90 # Log installer version
91 version_file = os.path.abspath(os.path.dirname(__file__)) + "/version-stamp"
92 installer_version = open(version_file, "r").readline().strip()
93 self._logger.log("Gentoo Linux Installer version " + installer_version)
94
95 # self._install_event.wait()
96 # self._install_event.clear()
97
98 templates = {
99 'x86': 'x86ArchitectureTemplate',
100 'sparc': 'sparcArchitectureTemplate',
101 'amd64': 'amd64ArchitectureTemplate',
102 'mips': 'mipsArchitectureTemplate',
103 'hppa': 'hppaArchitectureTemplate',
104 'alpha': 'alphaArchitectureTemplate',
105 'ppc': 'ppcArchitectureTemplate',
106 'ppc64': 'ppc64ArchitectureTemplate'
107 }
108 if self._verbose: self._logger.log("DEBUG: arch is %s" % self.arch)
109 if self.arch not in templates:
110 self.addNotification("exception", GLIException("UnsupportedArchitectureError", "fatal", "run", self.arch + ' is not supported by the Gentoo Linux Installer!'))
111
112 try:
113 template = __import__(TEMPLATE_DIR + '/' + templates[self.arch])
114 self._arch_template = getattr(template, templates[self.arch])(self._install_profile, self)
115 except ImportError:
116 self.addNotification("exception", GLIException("UnsupportedArchitectureError", 'fatal', 'run', 'The Gentoo Linux Installer could not import the install template for this architecture!'))
117 except AttributeError:
118 self.addNotification("exception", GLIException("UnsupportedArchitectureError", 'fatal', 'run', 'This architecture template was not defined properly!'))
119
120 tmp_install_steps = self._arch_template.get_install_steps()
121 self._install_steps = [step for step in tmp_install_steps]
122
123 if self._verbose: self._logger.log("DEBUG: install_steps: " + str(self._install_steps))
124
125 # self.addNotification("int", NEXT_STEP_READY)
126
127 # Write install profile to disk for debugging purposes
128 configuration = open("/tmp/installprofile.xml", "w")
129 configuration.write(self._install_profile.serialize())
130 configuration.close()
131
132 while 1:
133 if self._install_step >= len(self._install_steps): break
134 if self._verbose: self._logger.log("DEBUG: waiting at top of 'while' loop in CC in secondary thread...waiting to start step " + str(self._install_step+1) + ", " + self._install_steps[(self._install_step+1)]['name'])
135 self._install_event.wait()
136 if self._verbose: self._logger.log("DEBUG: Event() cleared at top of 'while' loop in CC in secondary thread...starting step " + str(self._install_step) + ", " + self._install_steps[(self._install_step)]['name'])
137 # if self._install_step <= (len(self._install_steps) - 1):
138 try:
139 if not self._pretend:
140 func = getattr(self._arch_template, self._install_steps[self._install_step]['function'])
141 func()
142 self._install_event.clear()
143 if self.has_more_steps():
144 self.addNotification("int", NEXT_STEP_READY)
145 else:
146 self.addNotification("int", INSTALL_DONE)
147 except GLIException, error:
148 etype, value, tb = sys.exc_info()
149 s = traceback.format_exception(etype, value, tb)
150 self._logger.log("Exception received during '" + self._install_steps[self._install_step]['name'] + "': " + str(error))
151 for line in s:
152 line = line.strip()
153 self._logger.log(line)
154 self.addNotification("exception", error)
155 self._install_event.clear()
156 except Exception, error:
157 # Something very bad happened
158 etype, value, tb = sys.exc_info()
159 s = traceback.format_exception(etype, value, tb)
160 self._logger.log("This is a bad thing. An exception occured outside of the normal install errors. The error was: '" + str(error) + "'")
161 for line in s:
162 line = line.strip()
163 self._logger.log(line)
164 self.addNotification("exception", error)
165 self._install_event.clear()
166 # else:
167 # break
168
169 # This keeps the thread running until the FE exits
170 self._install_event.clear()
171 self._install_event.wait()
172
173 ##
174 # Returns the number of steps in the install process
175 def get_num_steps(self):
176 return len(self._install_steps)
177
178 ##
179 # Returns information about the next install step
180 def get_next_step_info(self):
181 return self._install_steps[(self._install_step + 1)]['name']
182
183 ##
184 # Returns information about the next install step
185 def get_next_step(self):
186 return self._install_steps[(self._install_step + 1)]
187
188 ##
189 # Performs the next install step
190 def next_step(self):
191 self._install_step = self._install_step + 1
192 if self._verbose: self._logger.log("DEBUG: next_step(): setting Event() flag...starting step " + str(self._install_step) + ", " + self._install_steps[(self._install_step)]['name'])
193 self._install_event.set()
194
195 ##
196 # Retries the current install step
197 def retry_step(self):
198 self._install_event.set()
199
200 ##
201 # Returns True if there are more install steps remaining
202 def has_more_steps(self):
203 return (self._install_step < (len(self._install_steps) - 1))
204
205 ##
206 # Cleans up after a failed install
207 def start_failure_cleanup(self):
208 self._arch_template.install_failed_cleanup()
209
210 ##
211 # Returns a notification object from the queue
212 def getNotification(self):
213 notification = None
214 try:
215 notification = self._notification_queue.get_nowait()
216 except:
217 pass
218 return notification
219
220 ##
221 # Adds a notification object to the queue
222 # @param type Notification type
223 # @param data Notification contents
224 def addNotification(self, type, data):
225 notification = GLINotification.GLINotification(type, data)
226 try:
227 self._notification_queue.put_nowait(notification)
228 except:
229 # This should only ever happen if the frontend is not checking for notifications
230 pass

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20