summaryrefslogtreecommitdiffstats
path: root/ipapython/errors.py
diff options
context:
space:
mode:
authorTomas Krizek <tkrizek@redhat.com>2016-10-26 14:00:29 +0200
committerMartin Basti <mbasti@redhat.com>2016-11-07 11:34:03 +0100
commite8aa2627c7a3dcb0b0745e656ea58ccbbccd38fb (patch)
treec1f0b38ead6bcee84dbe89dedc6f946d1e4a74fc /ipapython/errors.py
parent8934d03b3b5bbf02e9e20a1644ef31d27fa0f483 (diff)
upgradeinstance: ldap conn management
connect/disconnect api.Backend.ldap2 connection when directory server is started/stopped https://fedorahosted.org/freeipa/ticket/6461 Reviewed-By: Martin Basti <mbasti@redhat.com> Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipapython/errors.py')
0 files changed, 0 insertions, 0 deletions
75' href='#n175'>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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
#
# text.py - text mode frontend to anaconda
#
# Erik Troan <ewt@redhat.com>
# Matt Wilson <msw@redhat.com>
#
# Copyright 1999-2004 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

from snack import *
import sys
import os
import isys
import iutil
import time
import signal
import parted
import string
import kudzu
from language import expandLangs
from flags import flags
from constants_text import *
from constants import *

from rhpl.log import log
from rhpl.translate import _, cat, N_

stepToClasses = {
    "language" : ("language_text", "LanguageWindow"),
    "keyboard" : ("keyboard_text", "KeyboardWindow"),
    "mouse" : ("mouse_text", ("MouseWindow", "MouseDeviceWindow")),
    "welcome" : ("welcome_text", "WelcomeWindow"),
    "installtype" : ("installpath_text", "InstallPathWindow"),
    "autopartition" : ("partition_text", "AutoPartitionWindow"),
    "custom-upgrade" : ("upgrade_text", "UpgradeExamineWindow"),
    "addswap" : ("upgrade_text", "UpgradeSwapWindow"),
    "upgrademigratefs" : ("upgrade_text", "UpgradeMigrateFSWindow"),
    "fdisk" : ("fdisk_text", "fdiskPartitionWindow"),
    "partitionmethod" : ("partmethod_text", ("PartitionMethod")),
    "partition": ("partition_text", ("PartitionWindow")),
    "zfcpconfig": ("zfcp_text", ("ZFCPWindow")),
    "findinstall" : ("upgrade_text", ("UpgradeExamineWindow")),
# replace with below if you want customize screen
#    "findinstall" : ("upgrade_text", ("UpgradeExamineWindow",
#                                      "CustomizeUpgradeWindow")),
    "addswap" : ("upgrade_text", "UpgradeSwapWindow"),
    "upgbootloader": ("upgrade_bootloader_text", "UpgradeBootloaderWindow"),
    "bootloader" : ("bootloader_text", ("BootloaderChoiceWindow",
                                        "BootloaderAppendWindow",
                                        "BootloaderPasswordWindow")),
    "bootloaderadvanced" : ("bootloader_text", ("BootloaderImagesWindow",
                                                "BootloaderLocationWindow")),
    "network" : ("network_text", ("NetworkDeviceWindow", "NetworkGlobalWindow",
                                  "HostnameWindow")),
    "firewall" : ("firewall_text", ("FirewallWindow",
                                    "SELinuxWindow")),
    "languagesupport" : ("language_text", ("LanguageSupportWindow",
                                           "LanguageDefaultWindow")),
    "timezone" : ("timezone_text", "TimezoneWindow"),
    "accounts" : ("userauth_text", "RootPasswordWindow"),
    "authentication" : ("userauth_text", ("AuthConfigWindow")),
    "desktopchoice": ("desktop_choice_text", "DesktopChoiceWindow"),
    "package-selection"  : ("packages_text", "PackageGroupWindow"),
    "indivpackage" : ("packages_text", ("IndividualPackageWindow")),
    "dependencies" : ("packages_text", "PackageDepWindow"),
    "videocard" : ("xconfig_text", "XConfigWindowCard"),
    "monitor" : ("xconfig_text", "MonitorWindow"),
    "xcustom" : ("xconfig_text", "XCustomWindow"),
    "confirminstall" : ("confirm_text", "BeginInstallWindow"),
    "confirmupgrade" : ("confirm_text", "BeginUpgradeWindow"),
    "install" : ("progress_text", "setupForInstall"),
    "bootdisk" : ("bootdisk_text", ("BootDiskWindow")),
    "complete" : ("complete_text", "FinishedWindow"),
}

if iutil.getArch() == 'sparc':
    stepToClasses["bootloader"] = ("silo_text", ("SiloAppendWindow",
                                                 "SiloWindow"
                                                 "SiloImagesWindow"))
if iutil.getArch() == 's390':
    stepToClasses["bootloader"] = ("zipl_text", ( "ZiplWindow"))

class InstallWindow:
    def __call__ (self, screen):
        raise RuntimeError, "Unimplemented screen"

class WaitWindow:
    def pop(self):
	self.screen.popWindow()
	self.screen.refresh()

    def __init__(self, screen, title, text):
	self.screen = screen
	width = 40
	if (len(text) < width): width = len(text)

	t = TextboxReflowed(width, text)

	g = GridForm(self.screen, title, 1, 1)
	g.add(t, 0, 0)
	g.draw()
	self.screen.refresh()

class OkCancelWindow:
    def getrc(self):
	return self.rc

    def __init__(self, screen, title, text):
	rc = ButtonChoiceWindow(screen, title, text,
			        buttons=[TEXT_OK_BUTTON, _("Cancel")])
	if rc == string.lower(_("Cancel")):
	    self.rc = 1
	else:
	    self.rc = 0

class ProgressWindow:
    def pop(self):
	self.screen.popWindow()
	self.screen.refresh()
        del self.scale
        self.scale = None

    def set(self, amount):
        self.scale.set(amount)
	self.screen.refresh()

    def __init__(self, screen, title, text, total):
	self.screen = screen
	width = 55
	if (len(text) > width): width = len(text)

	t = TextboxReflowed(width, text)

	g = GridForm(self.screen, title, 1, 2)
	g.add(t, 0, 0, (0, 0, 0, 1), anchorLeft=1)

        self.scale = Scale(width, total)
        g.add(self.scale, 0, 1)
                
	g.draw()
	self.screen.refresh()

class InstallInterface:
    def helpWindow(self, screen, key):
        lang = self.instLanguage.getCurrent()
        lang = self.instLanguage.getLangNick(lang)
        self.langSearchPath = expandLangs(lang) + ['C']

        if key == "helponhelp":
            if self.showingHelpOnHelp:
                return None
            else:
                self.showingHelpOnHelp = 1
	try:
            f = None

            if self.configFileData.has_key("helptag"):
                helpTag = "-%s" % (self.configFileData["helptag"],)
            else:
                helpTag = ""
            arch = "-%s" % (iutil.getArch(),)
            tags = [ "%s%s" % (helpTag, arch), "%s" % (helpTag,),
                     "%s" % (arch,), "" ]

	    # XXX
	    #
	    # HelpWindow can't get to the langauge

            found = 0
            for path in ("./text-", "/mnt/source/RHupdates/",
                         "/usr/share/anaconda/"):
                if found:
                    break
                for lang in self.langSearchPath:
                    for tag in tags:
                        fn = "%shelp/%s/s1-help-screens-%s%s.txt" \
                             % (path, lang, key, tag)

                        try:
                            f = open(fn)
                        except IOError, msg:
                            continue
                        found = 1
                        break

            if not f:
                ButtonChoiceWindow(screen, _("Help not available"), 
                                   _("No help is available for this "
                                     "step of the install."),
                                   buttons=[TEXT_OK_BUTTON])
                return None

	    lines = f.readlines()
            for l in lines:
                l = l.replace("@RHL@", productName)
                l = l.replace("@RHLVER@", productVersion)
	    while not string.strip(l[0]):
		l = l[1:]
	    title = string.strip(l[0])
	    l = l[1:]
	    while not string.strip(l[0]):
		l = l[1:]
	    f.close()

	    height = 10
	    scroll = 1
	    if len(l) < height: 
		height = len(l)
		scroll = 0

	    width = len(title) + 6
	    stream = ""
	    for line in l:
		line = string.strip(line)
		stream = stream + line + "\n"
		if len(line) > width:
		    width = len(line)

	    bb = ButtonBar(screen, [TEXT_OK_BUTTON])
	    t = Textbox(width, height, stream, scroll=scroll)

	    g = GridFormHelp(screen, title, "helponhelp", 1, 2)
	    g.add(t, 0, 0, padding=(0, 0, 0, 1))
	    g.add(bb, 0, 1, growx=1)

	    g.runOnce()
            self.showingHelpOnHelp = 0
	except:
	    import traceback
	    (type, value, tb) = sys.exc_info()
	    from string import joinfields
	    list = traceback.format_exception(type, value, tb)
	    text = joinfields(list, "")
	    rc = self.exceptionWindow(_("Exception Occurred"), text)
	    if rc:
		import pdb
		pdb.post_mortem(tb)
	    os._exit(1)

    def progressWindow(self, title, text, total):
        return ProgressWindow(self.screen, title, text, total)

    def messageWindow(self, title, text, type="ok", default = None,
		      custom_icon=None, custom_buttons=[]):
	if type == "ok":
	    ButtonChoiceWindow(self.screen, title, text,
			       buttons=[TEXT_OK_BUTTON])
        elif type == "yesno":
            if default and default == "no":
                btnlist = [TEXT_NO_BUTTON, TEXT_YES_BUTTON]
            else:
                btnlist = [TEXT_YES_BUTTON, TEXT_NO_BUTTON]
	    rc = ButtonChoiceWindow(self.screen, title, text,
			       buttons=btnlist)
            if rc == "yes":
                return 1
            else:
                return 0
	elif type == "custom":
	    tmpbut = []
	    for but in custom_buttons:
		tmpbut.append(string.replace(but,"_",""))

	    rc = ButtonChoiceWindow(self.screen, title, text, width=60,
				    buttons=tmpbut)

	    idx = 0
	    for b in tmpbut:
		if string.lower(b) == rc:
		    return idx != 0
		idx = idx + 1
	    return 0
	else:
	    return OkCancelWindow(self.screen, title, text)

    def kickstartErrorWindow(self, text):
        s = _("The following error was found while parsing your "
              "kickstart configuration:\n\n%s") %(text,)
        self.messageWindow(_("Error Parsing Kickstart Config"),
                           s,
                           type = "custom",
                           custom_buttons = [("_Reboot")],
                           custom_icon="error")
                           
    

    def dumpWindow(self):
	rc = ButtonChoiceWindow(self.screen, _("Save Crash Dump"),
	    _("Please insert a floppy now. All contents of the disk "
	      "will be erased, so please choose your diskette carefully."),
	    [TEXT_OK_BUTTON, _("Cancel")])

        if rc == string.lower(_("Cancel")):
	    return 1

	return 0
    
    def exceptionWindow(self, title, text):
        try:
            floppyDevices = 0
            for dev in kudzu.probe(kudzu.CLASS_FLOPPY, kudzu.BUS_UNSPEC,
                                   kudzu.PROBE_ALL):
                if not dev.detached:
                    floppyDevices = floppyDevices + 1
        except:
            floppyDevices = 0
        if floppyDevices > 0 or DEBUG:
            ugh = "%s\n\n" % (exceptionText,)
            buttons=[TEXT_OK_BUTTON, _("Save"), _("Debug")]
        else:
            ugh = "%s\n\n" % (exceptionTextNoFloppy,)
            buttons=[TEXT_OK_BUTTON, _("Debug")]

	rc = ButtonChoiceWindow(self.screen, title, ugh + text, buttons)
        if rc == string.lower(_("Debug")):
            return 1
	elif rc == string.lower(_("Save")):
            return 2
        return None

    def partedExceptionWindow(self, exc):
        # if our only option is to cancel, let us handle the exception
        # in our code and avoid popping up the exception window here.
        if exc.options == parted.EXCEPTION_CANCEL:
            return parted.EXCEPTION_UNHANDLED
        log("parted exception: %s: %s" %(exc.type_string,exc.message))
        buttons = []
        buttonToAction = {}
        flags = ((parted.EXCEPTION_FIX, N_("Fix")),
                 (parted.EXCEPTION_YES, N_("Yes")),
                 (parted.EXCEPTION_NO, N_("No")),
                 (parted.EXCEPTION_OK, N_("OK")),
                 (parted.EXCEPTION_RETRY, N_("Retry")),
                 (parted.EXCEPTION_IGNORE, N_("Ignore")),
                 (parted.EXCEPTION_CANCEL, N_("Cancel")))
        for flag, errorstring in flags:
            if exc.options & flag:
                buttons.append(_(errorstring))
                buttonToAction[string.lower(_(errorstring))] = flag

        rc = None
        while not buttonToAction.has_key(rc):
            rc = ButtonChoiceWindow(self.screen, exc.type_string, exc.message,
                                    buttons=buttons)

        return buttonToAction[rc]
    

    def waitWindow(self, title, text):
	return WaitWindow(self.screen, title, text)

    def drawFrame(self):
        self.welcomeText = _("%s (C) 2004 Red Hat, Inc.") % (productName,)
        self.screen.drawRootText (0, 0, self.welcomeText)
	self.screen.drawRootText (len(_(self.welcomeText)), 0,
                                  (self.screen.width -
                                   len(_(self.welcomeText))) * " ")
        
	if (os.access("/usr/share/anaconda/help/C/s1-help-screens-lang.txt", os.R_OK)):
	    self.screen.pushHelpLine(_(" <F1> for help | <Tab> between elements | <Space> selects | <F12> next screen"))
	else:
	    self.screen.pushHelpLine(_("  <Tab>/<Alt-Tab> between elements   |  <Space> selects   |  <F12> next screen"))

    def setScreen(self, screen):
        self.screen = screen

    def shutdown(self):
	self.screen.finish()
	self.screen = None

    def __init__(self):
	signal.signal(signal.SIGINT, signal.SIG_IGN)
	signal.signal(signal.SIGTSTP, signal.SIG_IGN)
	self.screen = None
        self.showingHelpOnHelp = 0

    def __del__(self):
	if self.screen:
	    self.screen.finish()

    def run(self, id, dispatch, configFileData):
        # set up for CJK text mode if needed
        oldlang = None
        if (flags.setupFilesystems and
            (id.instLanguage.getFontFile(id.instLanguage.getCurrent()) == "bterm")
            and not flags.serial and not flags.virtpconsole
            and not isys.isPsudoTTY(0) and not isys.isVioConsole()):
            log("starting bterm")
            rc = 1
            try:
                rc = isys.startBterm()
                time.sleep(1)
            except Exception, e:
                log("got an exception starting bterm: %s" %(e,))

            if rc == 1:
                log("unable to start bterm, falling back to english")
                oldlang = id.instLanguage.getCurrent()
                log("old language was %s" %(oldlang,))
                id.instLanguage.setRuntimeLanguage("English")
                id.instLanguage.setRuntimeDefaults(oldlang)

        if id.instLanguage.getFontFile(id.instLanguage.getCurrent()) == "none":
            oldlang = id.instLanguage.getCurrent()
            id.instLanguage.setRuntimeLanguage("English")
            id.instLanguage.setRuntimeDefaults(oldlang)
        
        self.screen = SnackScreen()
        self.configFileData = configFileData
	self.screen.helpCallback(self.helpWindow)

# uncomment this line to make the installer quit on <Ctrl+Z>
# handy for quick debugging.
#	self.screen.suspendCallback(killSelf, self.screen)
# uncomment this line to drop into the python debugger on <Ctrl+Z>