# We need an interface before running kickstart execute methods for
# storage.
- from snack import *
+ from snack import SnackScreen
screen = SnackScreen()
anaconda.intf = rescue.RescueInterface(screen)
@@ -881,7 +881,7 @@ if __name__ == "__main__":
users.createLuserConf(anaconda.rootPath)
if opts.rescue:
- runRescueMode(anaconda)
+ runRescueMode(anaconda, opts)
# comment out the next line to make exceptions non-fatal
from pyanaconda.exception import initExceptionHandling
diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index 3b58028..99419cf 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -233,7 +233,7 @@ class Anaconda(object):
try:
from gui import InstallInterface
- except Exception, e:
+ except Exception as e:
from flags import flags
stdoutLog.error("Exception starting GUI installer: %s" %(e,))
# if we're not going to really go into GUI mode, we need to get
diff --git a/pyanaconda/backend.py b/pyanaconda/backend.py
index 65a1de0..b5a7323 100644
--- a/pyanaconda/backend.py
+++ b/pyanaconda/backend.py
@@ -74,7 +74,7 @@ class AnacondaBackend:
for f in glob.glob(DD_FIRMWARE+"/*"):
try:
shutil.copyfile(f, "%s/lib/firmware/" % anaconda.rootPath)
- except IOError, e:
+ except IOError as e:
log.error("Could not copy firmware file %s: %s" % (f, e.strerror))
def doPostInstall(self, anaconda):
@@ -93,7 +93,7 @@ class AnacondaBackend:
if os.path.exists(DD_ALL):
try:
shutil.copytree(DD_ALL, anaconda.rootPath + "/root/DD")
- except IOError, e:
+ except IOError as e:
pass
storage.writeEscrowPackets(anaconda)
diff --git a/pyanaconda/booty/bootloaderInfo.py b/pyanaconda/booty/bootloaderInfo.py
index 7eee4ec..c297557 100644
--- a/pyanaconda/booty/bootloaderInfo.py
+++ b/pyanaconda/booty/bootloaderInfo.py
@@ -268,21 +268,22 @@ class BootImages:
if part.partType not in (parted.PARTITION_NORMAL, parted.PARTITION_LOGICAL) or not part.format:
continue
- type = part.format.type
-
- if type in dosFilesystems and not foundDos and doesDualBoot() and
+ if part.format.type in dosFilesystems and
+ not foundDos and doesDualBoot() and
not part.getFlag(parted.PARTITION_DIAG):
try:
bootable = checkForBootBlock(part.path)
- retval.append((part, type))
- foundDos = True
- except:
+ except (OSError, struct.error):
pass
- elif type == "appleboot" and iutil.getPPCMachine() == "PMac" and part.bootable:
+ else:
+ retval.append((part, part.format.type))
+ foundDos = True
+ elif part.format.type == "appleboot" and
+ iutil.getPPCMachine() == "PMac" and part.bootable:
foundAppleBootstrap = True
- elif type in ["hfs", "hfs+"] and foundAppleBootstrap:
+ elif part.format.type in ["hfs", "hfs+"] and foundAppleBootstrap:
# questionable for same reason as above, but on mac this time
- retval.append((part, type))
+ retval.append((part, part.format.type))
if addRoot:
rootDevice = storage.rootDevice
@@ -392,7 +393,7 @@ class bootloaderInfo(object):
- for file in files:
- what = path + '/' + file
+ for f in files:
+ what = path + '/' + f
log.debug("Checking %s" % (what))
if not isys.isIsoImage(what):
continue
+ log.debug("mounting %s on /mnt/cdimage", what)
try:
- log.debug("mounting %s on /mnt/cdimage", what)
- isys.mount(what, "/mnt/cdimage", fstype = "iso9660", readOnly = True)
-
- if os.access("/mnt/cdimage/.discinfo", os.R_OK):
- log.debug("Reading .discinfo")
- f = open("/mnt/cdimage/.discinfo")
- try:
- f.readline() # skip timestamp
- f.readline() # skip release description
- discArch = string.strip(f.readline()) # read architecture
- except:
- discArch = None
-
- f.close()
-
- log.debug("discArch = %s" % discArch)
- if discArch != arch:
- isys.umount("/mnt/cdimage", removeDir=False)
- continue
-
- # If there's no repodata, there's no point in trying to
- # install from it.
- if not os.access("/mnt/cdimage/repodata", os.R_OK):
- log.warning("%s doesn't have repodata, skipping" %(what,))
- isys.umount("/mnt/cdimage", removeDir=False)
- continue
-
- # warn user if images appears to be wrong size
- if os.stat(what)[stat.ST_SIZE] % 2048:
- rc = messageWindow(_("Warning"),
- _("The ISO image %s has a size which is not "
- "a multiple of 2048 bytes. This may mean "
- "it was corrupted on transfer to this computer."
- "
"
- "It is recommended that you exit and abort your "
- "installation, but you can choose to continue if "
- "you think this is in error.") % (file,),
- type="custom", custom_icon="warning",
- custom_buttons= [_("_Exit installer"),
- _("_Continue")])
- if rc == 0:
- sys.exit(0)
-
- log.info("Found disc at %s" % file)
- isys.umount("/mnt/cdimage", removeDir=False)
- return file
+ isys.mount(what, "/mnt/cdimage", fstype="iso9660", readOnly=True)
except SystemError:
- pass
+ continue
+
+ if not os.access("/mnt/cdimage/.discinfo", os.R_OK):
+ isys.umount("/mnt/cdimage", removeDir=False)
+ continue
+
+ log.debug("Reading .discinfo")
+ f = open("/mnt/cdimage/.discinfo")
+ f.readline() # skip timestamp
+ f.readline() # skip release description
+ discArch = f.readline().strip() # read architecture
+ f.close()
+
+ log.debug("discArch = %s" % discArch)
+ if discArch != arch:
+ isys.umount("/mnt/cdimage", removeDir=False)
+ continue
+
+ # If there's no repodata, there's no point in trying to
+ # install from it.
+ if not os.access("/mnt/cdimage/repodata", os.R_OK):
+ log.warning("%s doesn't have repodata, skipping" %(what,))
+ isys.umount("/mnt/cdimage", removeDir=False)
+ continue
+
+ # warn user if images appears to be wrong size
+ if os.stat(what)[stat.ST_SIZE] % 2048:
+ rc = messageWindow(_("Warning"),
+ _("The ISO image %s has a size which is not "
+ "a multiple of 2048 bytes. This may mean "
+ "it was corrupted on transfer to this computer."
+ "
"
+ "It is recommended that you exit and abort your "
+ "installation, but you can choose to continue if "
+ "you think this is in error.") % (f,),
+ type="custom", custom_icon="warning",
+ custom_buttons= [_("_Exit installer"),
+ _("_Continue")])
+ if rc == 0:
+ sys.exit(0)
+
+ log.info("Found disc at %s" % f)
+ isys.umount("/mnt/cdimage", removeDir=False)
+ return f
return None
@@ -132,7 +131,7 @@ def mountDirectory(methodstr, messageWindow):
try:
isys.mount(device, "/mnt/isodir", fstype=fstype, options=options)
break
- except SystemError, msg:
+ except SystemError as msg:
log.error("couldn't mount ISO source directory: %s" % msg)
ans = messageWindow(_("Couldn't Mount ISO Source"),
_("An error occurred mounting the source "
@@ -160,7 +159,7 @@ def mountImage(isodir, tree, messageWindow):
isoImage = "%s/%s" % (isodir, image)
isys.mount(isoImage, tree, fstype = 'iso9660', readOnly = True)
break
- except:
+ except SystemError:
ans = messageWindow(_("Missing ISO 9660 Image"),
_("The installer has tried to mount the "
"installation image, but cannot find it on "
@@ -186,7 +185,7 @@ def scanForMedia(tree, storage):
storage.devicetree.updateDeviceFormat(dev)
try:
dev.format.mount(mountpoint=tree)
- except:
+ except Exception:
continue
if not verifyMedia(tree):
@@ -209,7 +208,7 @@ def unmountCD(dev, messageWindow):
try:
dev.format.unmount()
break
- except Exception, e:
+ except Exception as e:
log.error("exception in _unmountCD: %s" %(e,))
messageWindow(_("Error"),
_("An error occurred unmounting the disc. "
@@ -223,17 +222,8 @@ def verifyMedia(tree, timestamp=None):
f = open("%s/.discinfo" % tree)
def notify_kernel(path, action="change"):
- """ Signal the kernel that the specified device has changed. """
+ """ Signal the kernel that the specified device has changed.
+
+ Exceptions raised: ValueError, IOError
+ """
log.debug("notifying kernel of '%s' event on device %s" % (action, path))
path = os.path.join(path, "uevent")
if not path.startswith("/sys/") or not os.access(path, os.W_OK):
@@ -813,9 +816,8 @@ def numeric_type(num):
return num
try:
anaconda.backend.selectGroup(grp.name, (default, optional))
- except NoSuchGroup, e:
+ except NoSuchGroup as e:
if ksdata.packages.handleMissing == KS_MISSING_IGNORE or ignoreAll:
pass
else:
diff --git a/pyanaconda/livecd.py b/pyanaconda/livecd.py
index c1918a9..af05fda 100644
--- a/pyanaconda/livecd.py
+++ b/pyanaconda/livecd.py
@@ -61,7 +61,7 @@ def copytree(src, dst, symlinks=False, preserveOwner=False,
def trySetfilecon(src, dest):
try:
selinux.lsetfilecon(dest, selinux.lgetfilecon(src)[1])
- except:
+ except OSError:
log.error("Could not set selinux context on file %s" % dest)
# copy of shutil.copytree which doesn't require dst to not exist
@@ -90,11 +90,11 @@ def copytree(src, dst, symlinks=False, preserveOwner=False,
trySetfilecon(srcname, dstname)
shutil.copystat(srcname, dstname)
- except (IOError, os.error), why:
+ except (IOError, OSError) as why:
errors.append((srcname, dstname, str(why)))
# catch the Error from the recursive copytree so that we can
# continue with other files
- except Error, err:
+ except Error as err:
errors.extend(err.args[0])
try:
if preserveOwner:
@@ -130,7 +130,7 @@ class LiveCDCopyBackend(backend.AnacondaBackend):
try:
anaconda.storage.umountFilesystems(swapoff = False)
os.rmdir(anaconda.rootPath)
- except Exception, e:
+ except Exception as e:
log.error("Unable to unmount filesystems: %s" % e)
def doPreInstall(self, anaconda):
@@ -156,7 +156,7 @@ class LiveCDCopyBackend(backend.AnacondaBackend):
try:
buf = os.read(osfd, readamt)
written = os.write(rootfd, buf)
- except:
+ except (IOError, OSError):
rc = anaconda.intf.messageWindow(_("Error"),
_("There was an error installing the live image to "
"your hard drive. This could be due to bad media. "
diff --git a/pyanaconda/rescue.py b/pyanaconda/rescue.py
index e7077e9..bb21bf3 100644
--- a/pyanaconda/rescue.py
+++ b/pyanaconda/rescue.py
@@ -31,10 +31,12 @@ import sys
import os
import isys
from storage import mountExistingSystem
+from storage.errors import StorageError
from installinterfacebase import InstallInterfaceBase
import iutil
import shutil
import time
+import re
import network
import subprocess
from pykickstart.constants import *
@@ -77,14 +79,14 @@ class RescueInterface(InstallInterfaceBase):
elif type == "custom":
tmpbut = []
for but in custom_buttons:
- tmpbut.append(string.replace(but,"_",""))
+ tmpbut.append(but.replace("_",""))
idx = 0
for b in tmpbut:
- if string.lower(b) == rc:
+ if b.lower() == rc:
return idx
idx = idx + 1
return 0
@@ -149,7 +151,7 @@ def makeFStab(instPath = ""):
if buf:
f.write(buf)
f.close()
- except IOError, e:
+ except IOError as e:
log.info("failed to write /etc/fstab: %s" % e)
# make sure they have a resolv.conf in the chroot
@@ -190,9 +192,7 @@ def makeResolvConf(instPath):
#
def startNetworking(network, intf):
# do lo first
- try:
- os.system("/usr/sbin/ifconfig lo 127.0.0.1")
- except:
+ if os.system("/usr/sbin/ifconfig lo 127.0.0.1"):
log.error("Error trying to start lo in rescue.py::startNetworking()")
# see if they would like networking enabled
@@ -248,7 +248,7 @@ def runRescue(anaconda):
_("Do you want to start the network interfaces on "
"this system?"), [_("Yes"), _("No")])
- if rc != string.lower(_("No")):
+ if rc != _("No").lower():
anaconda.intf = RescueInterface(screen)
if not anaconda.intf.enableNetwork(anaconda):
@@ -303,14 +303,14 @@ def runRescue(anaconda):
"command shell.
# set a library path to use mounted fs
@@ -414,27 +414,18 @@ def runRescue(anaconda):
os.environ["LD_LIBRARY_PATH"] = ":".join(libdirs + mounted)
# find groff data dir
+ gversion = None
try:
glst = os.listdir("/mnt/sysimage/usr/share/groff")
-
+ except OSError:
+ pass
+ else:
# find a directory which is a numeral, its where
# data files are
- gversion = None
for gdir in glst:
- try:
- isone = 1
- for idx in range(0, len(gdir)):
- if string.find(string.digits + '.', gdir[idx]) == -1:
- isone = 0
- break
- if isone:
- gversion = gdir
- break
- except:
- gversion = None
- continue
- except:
- gversion = None
+ if re.match(r'd[.d]+d$', gdir):
+ gversion = gdir
+ break
if gversion is not None:
gpath = "/mnt/sysimage/usr/share/groff/"+gversion
@@ -445,18 +436,12 @@ def runRescue(anaconda):
try:
if os.access("/usr/bin/bash", os.R_OK):
os.symlink ("/usr/bin/bash", "/bin/bash")
- except:
+ except OSError:
pass
- except:
- # This looks horrible, but all it does is catch every exception,
- # and reraise those in the tuple check. This lets programming
- # errors raise exceptions, while any runtime error will
- # still result in a shell
- (exc, val) = sys.exc_info()[0:2]
- log.error(str(exc)+": "+str(val))
- if exc in (IndexError, ValueError, SyntaxError):
- raise exc, val, sys.exc_info()[2]
-
+ except (ValueError, LookupError, SyntaxError, NameError):
+ raise
+ except Exception as e:
+ log.error("runRescue caught exception: %s" % e)
if anaconda.ksdata:
log.error("An error occurred trying to mount some or all of your system")
else:
@@ -497,7 +482,7 @@ def runRescue(anaconda):
anaconda.storage.makeMtab(root=anaconda.rootPath)
try:
makeResolvConf(anaconda.rootPath)
- except Exception, e:
+ except (OSError, IOError) as e:
log.error("error making a resolv.conf: %s" %(e,))
msgStr = _("Your system is mounted under the %s directory.") % (anaconda.rootPath,)
ButtonChoiceWindow(screen, _("Rescue"), msgStr, [_("OK")] )
diff --git a/pyanaconda/security.py b/pyanaconda/security.py
index 6686251..5c71012 100644
--- a/pyanaconda/security.py
+++ b/pyanaconda/security.py
@@ -79,10 +79,8 @@ class Security:
iutil.execWithRedirect("/usr/sbin/lokkit", args,
root = instPath, stdout = "/dev/null",
stderr = "/dev/null")
- except RuntimeError, msg:
+ except (RuntimeError, OSError) as msg:
log.error ("lokkit run failed: %s" %(msg,))
- except OSError as e:
- log.error ("lokkit run failed: %s" % e.strerror)
# So that users can write iscsi() to get the singleton instance
@@ -130,7 +130,7 @@ class iscsi(object):
try:
found_nodes = libiscsi.discover_firmware()
- except:
+ except Exception:
# an exception here means there is no ibft firmware, just return
return
@@ -140,7 +140,7 @@ class iscsi(object):
log.info("iscsi._startIBFT logged in to %s %s %s" % (node.name, node.address, node.port))
self.nodes.append(node)
self.ibftNodes.append(node)
- except IOError, e:
+ except IOError as e:
log.error("Could not log into ibft iscsi target %s: %s" %
(node.name, str(e)))
pass
diff --git a/pyanaconda/storage/partitioning.py b/pyanaconda/storage/partitioning.py
index a0f529a..65902ff 100644
--- a/pyanaconda/storage/partitioning.py
+++ b/pyanaconda/storage/partitioning.py
@@ -626,7 +626,7 @@ def getBestFreeSpaceRegion(disk, part_type, req_size,
# parted.Geometry.overlapsWith can handle this
try:
free_geom = extended.geometry.intersect(_range)
- except ArithmeticError, e:
+ except ArithmeticError:
# this freespace region does not lie within the extended
# partition's geometry
free_geom = None
diff --git a/pyanaconda/storage/zfcp.py b/pyanaconda/storage/zfcp.py
index 001fc4c..9622c19 100644
--- a/pyanaconda/storage/zfcp.py
+++ b/pyanaconda/storage/zfcp.py
@@ -370,7 +370,7 @@ class ZFCP:
try:
self.addFCP(devnum, wwpn, fcplun)
- except ValueError, e:
+ except ValueError as e:
if self.intf:
self.intf.messageWindow(_("Error"), str(e))
else:
@@ -390,7 +390,7 @@ class ZFCP:
for d in self.fcpdevs:
try:
d.offlineDevice()
- except ValueError, e:
+ except ValueError as e:
log.warn(str(e))
def startup(self, intf=None):
@@ -409,7 +409,7 @@ class ZFCP:
for d in self.fcpdevs:
try:
d.onlineDevice()
- except ValueError, e:
+ except ValueError as e:
log.warn(str(e))
@@ -355,7 +353,7 @@ class AnacondaYum(yum.YumBase):
try:
self.configBaseURL()
break
- except SystemError, e:
+ except SystemError as e:
self.anaconda.intf.messageWindow(_("Error Setting Up Repository"),
_("The following error occurred while setting up the "
"installation repository:
%(e)s
Please provide the "
@@ -388,7 +386,7 @@ class AnacondaYum(yum.YumBase):
return
dev.format.unmount()
- except:
+ except Exception:
pass
else:
if verifyMedia(self.tree, None):
@@ -418,7 +416,7 @@ class AnacondaYum(yum.YumBase):
dev.format.unmount()
dev.eject()
- except:
+ except Exception:
self.anaconda.intf.messageWindow(_("Error"),
_("Unable to access the disc."))
@@ -653,7 +651,7 @@ class AnacondaYum(yum.YumBase):
valid addon repos and if so, return a list of (repo name, repo URL).
"""
retval = []
- c = ConfigParser()
+ c = ConfigParser.ConfigParser()
# If there's no .treeinfo for this repo, don't bother looking for addons.
treeinfo = self._getTreeinfo(baseurl, proxy_url)
@@ -663,9 +661,9 @@ class AnacondaYum(yum.YumBase):
# We need to know which variant is being installed so we know what addons
# are valid options.
try:
- ConfigParser.read(c, treeinfo)
+ ConfigParser.ConfigParser.read(c, treeinfo)
variant = c.get("general", "variant")
- except:
+ except ConfigParser.Error:
return retval
section = "variant-%s" % variant
@@ -722,16 +720,16 @@ class AnacondaYum(yum.YumBase):
read. Since there's no redhat-release package in /mnt/sysimage (and
won't be for quite a while), we need to do our own substutition.
"""
- c = ConfigParser()
+ c = ConfigParser.ConfigParser()
treeinfo = self._getTreeinfo(self._baseRepoURL, self.proxy_url)
if not treeinfo:
return productVersion
def _handleFailure(self, package):
@@ -993,7 +989,7 @@ class AnacondaYum(yum.YumBase):
self.populateTs(keepold=0)
self.dsCallback.pop()
self.dsCallback = None
- except RepoError, e:
+ except RepoError as e:
msg = _("There was an error running your transaction for "
"the following reason: %s
") % str(e)
@@ -1033,7 +1029,7 @@ class AnacondaYum(yum.YumBase):
try:
self.runTransaction(cb=cb)
- except YumBaseError, probs:
+ except YumBaseError as probs:
# FIXME: we need to actually look at these problems...
probTypes = { rpm.RPMPROB_NEW_FILE_CONFLICT : _('file conflicts'),
rpm.RPMPROB_FILE_CONFLICT : _('file conflicts'),
@@ -1310,7 +1306,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
fn(repo)
if callback:
callback.disconnect()
- except RepoError, e:
+ except RepoError:
if callback:
callback.disconnect()
buttons = [_("_Exit installer"), _("Edit"), _("_Retry")]
@@ -1515,7 +1511,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
return DISPATCH_BACK
break
- except RepoError, e:
+ except RepoError as e:
# FIXME: would be nice to be able to recover here
rc = anaconda.intf.messageWindow(_("Error"),
_("Unable to read package metadata. This may be "
@@ -1574,7 +1570,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
for i in dirList:
try:
os.mkdir(anaconda.rootPath + i)
- except os.error, (errno, msg):
+ except OSError:
pass
# log.error("Error making directory %s: %s" % (i, msg))
@@ -1777,7 +1773,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
mbrs = self.ayum.selectGroup(group, group_package_types=types)
if len(mbrs) == 0 and self.isGroupSelected(group):
return
- except yum.Errors.GroupsError, e:
+ except yum.Errors.GroupsError:
# try to find out if it's the name or translated name
gid = self.__getGroupId(group)
if gid is not None:
@@ -1791,7 +1787,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
def deselectGroup(self, group, *args):
try:
self.ayum.deselectGroup(group, force=True)
- except yum.Errors.GroupsError, e:
+ except yum.Errors.GroupsError:
# try to find out if it's the name or translated name
gid = self.__getGroupId(group)
if gid is not None:
diff --git a/utils/log_picker/sending/ftpsender.py b/utils/log_picker/sending/ftpsender.py
index 92f7184..9ecf095 100644
--- a/utils/log_picker/sending/ftpsender.py
+++ b/utils/log_picker/sending/ftpsender.py
@@ -42,6 +42,6 @@ class FtpSender(SenderBaseClass):
ftp.storbinary('STOR %s' % os.path.basename(filename),
file(filename))
ftp.quit()
- except ftplib.all_errors, e:
+ except ftplib.all_errors as e:
raise SenderError("FTP upload failed: %(error)s" % {'error':e})
--
1.7.3.5
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list