summaryrefslogtreecommitdiffstats
path: root/pyanaconda/__init__.py
blob: fd1e676f4120e402a8b5e8fb04a90cb8ef3780e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/python
#
# anaconda: The Red Hat Linux Installation program
#
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
# Red Hat, Inc.  All rights reserved.
#
# 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/>.
#
# Author(s): Brent Fox <bfox@redhat.com>
#            Mike Fulbright <msf@redhat.com>
#            Jakub Jelinek <jakub@redhat.com>
#            Jeremy Katz <katzj@redhat.com>
#            Chris Lumens <clumens@redhat.com>
#            Paul Nasrat <pnasrat@redhat.com>
#            Erik Troan <ewt@rpath.com>
#            Matt Wilson <msw@rpath.com>
#

import os, time, string
import iutil
import isys
from constants import ROOT_PATH
from tempfile import mkstemp

import logging
log = logging.getLogger("anaconda")
stdoutLog = logging.getLogger("anaconda.stdout")

import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)

class Anaconda(object):
    def __init__(self):
        import desktop, dispatch, firewall, security
        import system_config_keyboard.keyboard as keyboard
        from flags import flags

        self._backend = None
        self._bootloader = None
        self.canReIPL = False
        self.desktop = desktop.Desktop()
        self.dir = None
        self.dispatch = dispatch.Dispatcher(self)
        self.displayMode = None
        self.extraModules = []
        self.firewall = firewall.Firewall()
        self.id = None
        self._instClass = None
        self._instLanguage = None
        self._intf = None
        self.isHeadless = False
        self.keyboard = keyboard.Keyboard()
        self.ksdata = None
        self.mediaDevice = None
        self.methodstr = None
        self._network = None
        self.opts = None
        self._payload = None
        self._platform = None
        self.proxy = None
        self.proxyUsername = None
        self.proxyPassword = None
        self.reIPLMessage = None
        self.rescue = False
        self.rescue_mount = True
        self.rootParts = None
        self.security = security.Security()
        self.simpleFilter = not iutil.isS390()
        self.stage2 = None
        self._storage = None
        self._timezone = None
        self.updateSrc = None
        self.upgrade = flags.cmdline.has_key("preupgrade")
        self.upgradeRoot = None
        self._users = None
        self.mehConfig = None
        self.clearPartTypeSelection = None      # User's GUI selection
        self.clearPartTypeSystem = None         # System's selection

        # *sigh* we still need to be able to write this out
        self.xdriver = None

    @property
    def backend(self):
        if not self._backend:
            b = self.instClass.getBackend()
            self._backend = apply(b, (self, ))

        return self._backend

    @property
    def bootloader(self):
        if not self._bootloader:
            self._bootloader = self.platform.bootloaderClass(self.platform)

        return self._bootloader

    @property
    def firstboot(self):
        from pykickstart.constants import FIRSTBOOT_DEFAULT

        if self.ksdata:
            return self.ksdata.firstboot.firstboot
        else:
            return FIRSTBOOT_DEFAULT

    @property
    def instClass(self):
        if not self._instClass:
            from installclass import DefaultInstall
            self._instClass = DefaultInstall()

        return self._instClass

    @property
    def instLanguage(self):
        if not self._instLanguage:
            import language
            self._instLanguage = language.Language(self.displayMode)

        return self._instLanguage

    def _getInterface(self):
        return self._intf

    def _setInterface(self, v):
        # "lambda cannot contain assignment"
        self._intf = v

    def _delInterface(self):
        del self._intf

    intf = property(_getInterface, _setInterface, _delInterface)

    @property
    def network(self):
        if not self._network:
            import network
            self._network = network.Network()

        return self._network

    @property
    def payload(self):
        # Try to find the packaging payload class.  First try the install
        # class.  If it doesn't give us one, fall back to the default.
        if not self._payload:
            klass = self.instClass.getBackend()

            if not klass:
                from flags import flags

                if flags.livecdInstall:
                    from pyanaconda.packaging.livepayload import LiveImagePayload
                    klass = LiveImagePayload
                else:
                    from pyanaconda.packaging.yumpayload import YumPayload
                    klass = YumPayload

            self._payload = klass(self.ksdata)

        return self._payload

    @property
    def platform(self):
        if not self._platform:
            from pyanaconda import platform
            self._platform = platform.getPlatform()

        return self._platform

    @property
    def protected(self):
        import stat

        if os.path.exists("/dev/live") and \
           stat.S_ISBLK(os.stat("/dev/live")[stat.ST_MODE]):
            return [os.readlink("/dev/live")]
        elif self.methodstr and self.methodstr.startswith("hd:"):
            method = self.methodstr[3:]
            return [method.split(":", 3)[0]]
        else:
            return []

    @property
    def users(self):
        if not self._users:
            import users
            self._users = users.Users(self)

        return self._users

    @property
    def storage(self):
        if not self._storage:
            import storage
            self._storage = storage.Storage(data=self.ksdata, platform=self.platform)

        return self._storage

    @property
    def timezone(self):
        if not self._timezone:
            import timezone
            self._timezone = timezone.Timezone()
            self._timezone.setTimezoneInfo(self.instLanguage.getDefaultTimeZone())

        return self._timezone

    def dumpState(self):
        from meh.dump import ReverseExceptionDump
        from inspect import stack as _stack

        # Skip the frames for dumpState and the signal handler.
        stack = _stack()[2:]
        stack.reverse()
        exn = ReverseExceptionDump((None, None, stack), self.mehConfig)

        # dump to a unique file
        (fd, filename) = mkstemp("", "anaconda-tb-", "/tmp")
        fo = os.fdopen(fd, "w")
        exn.write(self, fo)
        fo.close()

        #append to a given file
        with open(filename, "r") as f:
            content = f.readlines()
        with open("/tmp/anaconda-tb-all.log", "a+") as f:
            f.write("--- traceback: %s ---\n" % filename)
            f.writelines(content)

    def initInterface(self):
        if self._intf:
            raise RuntimeError, "Second attempt to initialize the InstallInterface"

        if self.displayMode != 'g':
            raise RuntimeError("Due to UI rewrite in progress, only graphical installs are supported")

        from pyanaconda.ui.gui import GraphicalUserInterface
        self._intf = GraphicalUserInterface(self.storage, self.payload, self.instClass)

    def writeXdriver(self, root = None):
        # this should go away at some point, but until it does, we
        # need to keep it around.
        if self.xdriver is None:
            return
        if root is None:
            root = ROOT_PATH
        if not os.path.isdir("%s/etc/X11" %(root,)):
            os.makedirs("%s/etc/X11" %(root,), mode=0755)
        f = open("%s/etc/X11/xorg.conf" %(root,), 'w')
        f.write('Section "Device"\n\tIdentifier "Videocard0"\n\tDriver "%s"\nEndSection\n' % self.xdriver)
        f.close()

    def setMethodstr(self, methodstr):
        if methodstr.startswith("cdrom://"):
            (device, tree) = string.split(methodstr[8:], ":", 1)

            if not tree.startswith("/"):
                tree = "/%s" %(tree,)

            if device.startswith("/dev/"):
                device = device[5:]

            self.mediaDevice = device
            self.methodstr = "cdrom://%s" % tree
        else:
            self.methodstr = methodstr

    def write(self):
        self.writeXdriver()
        self.instLanguage.write()

        self.timezone.write()
        if not self.ksdata:
            self.instClass.setNetworkOnbootDefault(self.network)
        self.network.write()
        self.network.copyConfigToPath()
        self.network.disableNMForStorageDevices(self)
        self.desktop.write()
        self.users.write()
        self.security.write()
        self.firewall.write()