summaryrefslogtreecommitdiffstats
path: root/backend.py
blob: afa6811a975d9fbaec178d76eaff216464995dc5 (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
#
# backend.py: Interface for installation backends
#
# Paul Nasrat <pnasrat@redhat.com>
# Jeremy Katz <katzj@redhat.com>
#
# Copyright (c) 2005 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import iutil
import os, sys
import logging
from syslogd import syslog

from rhpl.translate import _

from flags import flags
log = logging.getLogger("anaconda")


class AnacondaBackend:
    def __init__(self, method, instPath):
        """Abstract backend class all backends should inherit from this
           @param method: Object of InstallMethod type
           @param instPath: root path for the installation to occur"""

        self.method = method
        self.instPath = instPath
        self.instLog = None
        self.modeText = ""

    def doPreSelection(self, intf, id, instPath):
        pass

    def doPostSelection(self, intf, id, instPath):
        pass

    def doPreInstall(self, intf, id, instPath, dir):
        pass

    def doPostInstall(self, intf, id, instPath):
        sys.stdout.flush()
        if flags.setupFilesystems:
            syslog.stop()

    def doInstall(self, intf, id, instPath):
        pass

    def initLog(self, id, instPath):
        upgrade = id.getUpgrade()

        if upgrade:
            logname = '/root/upgrade.log'
        else:
            logname = '/root/install.log'

        instLogName = instPath + logname
        try:
            iutil.rmrf (instLogName)
        except OSError:
            pass

        instLog = open(instLogName, "w+")
        if upgrade:
            logname = '/root/upgrade.log'
        else:
            logname = '/root/install.log'

        instLogName = instPath + logname
        try:
            iutil.rmrf (instLogName)
        except OSError:
            pass

        self.instLog = open(instLogName, "w+")

       # dont start syslogd if we arent creating filesystems
        if flags.setupFilesystems:
            syslogname = "%s%s.syslog" % (instPath, logname)
            try:
                iutil.rmrf (syslogname)
            except OSError:
                pass
            syslog.start (instPath, syslogname)
        else:
            syslogname = None

        if upgrade:
            self.modeText = _("Upgrading %s-%s-%s.%s.\n")
        else:
            self.modeText = _("Installing %s-%s-%s.%s.\n")

    def kernelVersionList(self):
        pass

    def doInitialSetup(self, id, instPath):
        pass

    def doRepoSetup(self, intf, instPath):
        log.warning("doRepoSetup not implemented for backend!")
        pass

    def groupExists(self, group):
        log.warning("groupExists not implemented for backend!")
        pass

    def selectGroup(self, group, *args):
        log.warning("selectGroup not implemented for backend!")
        pass

    def deselectGroup(self, group, *args):
        log.warning("deselectGroup not implemented for backend!")
        pass

    def packageExists(self, pkg):
        log.warning("packageExists not implemented for backend!")
        pass
    
    def selectPackage(self, pkg, *args):
        log.warning("selectPackage not implemented for backend!")
        pass

    def deselectPackage(self, pkg, *args):
        log.warning("deselectPackage not implemented for backend!")
        pass

    def getDefaultGroups(self):
        log.warning("getDefaultGroups not implemented for backend!")
        pass

    def writePackagesKS(self, f):
        log.warning("writePackagesKS not implemented for backend!")
        pass

    def writeConfiguration(self):
        log.warning("writeConfig not implemented for backend!")
        pass

def doRepoSetup(backend, intf, id, instPath):
    backend.doInitialSetup(id, instPath)
    backend.doRepoSetup(intf, instPath)

def doPostSelection(backend, intf, id, instPath):
    backend.doPostSelection(intf, id, instPath)

def doPreInstall(backend, intf, id, instPath, dir):
    backend.doPreInstall(intf, id, instPath, dir)

def doPostInstall(backend, intf, id, instPath):
    backend.doPostInstall(intf, id, instPath)

def doInstall(backend, intf, id, instPath):
    backend.doInstall(intf, id, instPath)

# does this need to be per-backend?  we'll just leave here until it does :)
def doBasePackageSelect(backend, instClass):
    instClass.setPackageSelection(backend)
    instClass.setGroupSelection(backend)

def writeConfiguration(backend, id, instPath):
    log.info("Writing main configuration")
    if not flags.test:
        backend.writeConfiguration()
        id.write(instPath)