[PATCH] When catching an OSError, handle it as an object instead of a tuple (#497374).

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 firewall.py         |    4 ++--
 iutil.py            |   30 +++++++++++++++---------------
 livecd.py           |    6 +++---
 packages.py         |    4 ++--
 security.py         |    6 ++----
 storage/__init__.py |    8 ++++----
 syslogd.py          |    8 ++++----
 timezone.py         |    4 ++--
 users.py            |    4 ++--
 yuminstall.py       |    4 ++--
 10 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/firewall.py b/firewall.py
index ef543e6..bc45cb5 100644
--- a/firewall.py
+++ b/firewall.py
@@ -81,8 +81,8 @@ class Firewall:
                 log.error("would have run %s", args)
         except RuntimeError, msg:
             log.error ("lokkit run failed: %s", msg)
-        except OSError, (errno, msg):
-            log.error ("lokkit run failed: %s", msg)
+        except OSError as e:
+            log.error ("lokkit run failed: %s", e.strerror)
         else:
             f = open(instPath +
                      '/etc/sysconfig/system-config-securitylevel', 'w')
diff --git a/iutil.py b/iutil.py
index 0d7faed..5b93b1b 100644
--- a/iutil.py
+++ b/iutil.py
@@ -103,8 +103,8 @@ def execWithRedirect(command, argv, stdin = None, stdout = None,
             if proc.returncode is not None:
                 ret = proc.returncode
                 break
-    except OSError, (errno, msg):
-        errstr = "Error running %s: %s" % (command, msg)
+    except OSError as e:
+        errstr = "Error running %s: %s" % (command, e.strerror)
         log.error(errstr)
         runningLog.write(errstr)
         runningLog.close()
@@ -168,9 +168,9 @@ def execWithCapture(command, argv, stdin = None, stderr = None, root='/'):
 
             if proc.returncode is not None:
                 break
-    except OSError, (errno, msg):
-        log.error ("Error running " + command + ": " + msg)
-        raise RuntimeError, "Error running " + command + ": " + msg
+    except OSError as e:
+        log.error ("Error running " + command + ": " + e.strerror)
+        raise RuntimeError, "Error running " + command + ": " + e.strerror
 
     return rc
 
@@ -226,10 +226,10 @@ def execWithPulseProgress(command, argv, stdin = None, stdout = None,
     while 1:
         try:
             s = os.read(p[0], 1)
-        except OSError, args:
-            (num, _str) = args
+        except OSError as e:
+            (num, _str) = e.args
             if (num != 4):
-                raise IOError, args
+                raise IOError, e.args
 
         os.write(stdout, s)
         runningLog.write(s)
@@ -240,8 +240,8 @@ def execWithPulseProgress(command, argv, stdin = None, stdout = None,
 
     try:
         (pid, status) = os.waitpid(childpid, 0)
-    except OSError, (num, msg):
-        log.critical("exception from waitpid: %s %s" %(num, msg))
+    except OSError as e:
+        log.critical("exception from waitpid: %s %s" %(e.errno, e.strerror))
 
     progress and progress.pop()
 
@@ -259,8 +259,8 @@ def execConsole():
     try:
         proc = subprocess.Popen(["/bin/sh"])
         proc.wait()
-    except OSError, (errno, msg):
-        raise RuntimeError, "Error running /bin/sh: " + msg
+    except OSError as e:
+        raise RuntimeError, "Error running /bin/sh: " + e.strerror
 
 ## Get the size of a directory and all its subdirectories.
 # @param dir The name of the directory to find the size of.
@@ -338,14 +338,14 @@ def swapSuggestion(quiet=0):
 def mkdirChain(dir):
     try:
         os.makedirs(dir, 0755)
-    except OSError, (errno, msg):
+    except OSError as e:
         try:
-            if errno == EEXIST and stat.S_ISDIR(os.stat(dir).st_mode):
+            if e.errno == EEXIST and stat.S_ISDIR(os.stat(dir).st_mode):
                 return
         except:
             pass
 
-        log.error("could not create directory %s: %s" % (dir, msg))
+        log.error("could not create directory %s: %s" % (dir, e.strerror))
 
 ## Get the total amount of swap memory.
 # @return The total amount of swap memory in kilobytes, or 0 if unknown.
diff --git a/livecd.py b/livecd.py
index 915c0c1..280434b 100644
--- a/livecd.py
+++ b/livecd.py
@@ -90,8 +90,8 @@ def copytree(src, dst, symlinks=False, preserveOwner=False,
         if preserveSelinux:
             selinux.lsetfilecon(dst, selinux.lgetfilecon(src)[1])
         shutil.copystat(src, dst)
-    except OSError, why:
-        errors.extend((src, dst, str(why)))
+    except OSError as e:
+        errors.extend((src, dst, e.strerror))
     if errors:
         raise Error, errors
 
@@ -299,7 +299,7 @@ class LiveCDCopyBackend(backend.AnacondaBackend):
                 try:
                     os.rmdir("%s/mnt/%s" %(anaconda.rootPath,
                                            e.format.mountpoint))
-                except OSError, e:
+                except OSError as e:
                     log.debug("error removing %s" %(tocopy,))
             for e in [entry] + fsdict[tocopy]:                
                 e.format.setup(chroot=anaconda.rootPath)
diff --git a/packages.py b/packages.py
index 0457326..a7f5e32 100644
--- a/packages.py
+++ b/packages.py
@@ -225,8 +225,8 @@ def setupTimezone(anaconda):
     else:
         try:
             shutil.copyfile(tzfile, "/etc/localtime")
-        except OSError, (errno, msg):
-            log.error("Error copying timezone (from %s): %s" %(tzfile, msg))
+        except OSError as e:
+            log.error("Error copying timezone (from %s): %s" %(tzfile, e.strerror))
 
     if iutil.isS390():
         return
diff --git a/security.py b/security.py
index c784287..bd5c9da 100644
--- a/security.py
+++ b/security.py
@@ -72,7 +72,5 @@ class Security:
                 log.info("would have run %s" %(args,))
         except RuntimeError, msg:
             log.error ("lokkit run failed: %s" %(msg,))
-        except OSError, (errno, msg):
-            log.error ("lokkit run failed: %s" %(msg,))
-        
-        
+        except OSError as e:
+            log.error ("lokkit run failed: %s" % e.strerror)
diff --git a/storage/__init__.py b/storage/__init__.py
index 6c69fb2..e47fe68 100644
--- a/storage/__init__.py
+++ b/storage/__init__.py
@@ -1518,9 +1518,9 @@ class FSSet(object):
             try:
                 device.format.setup(options=options,
                                     chroot=anaconda.rootPath)
-            except OSError as (num, msg):
+            except OSError as e:
                 if intf:
-                    if num == errno.EEXIST:
+                    if e.errno == errno.EEXIST:
                         intf.messageWindow(_("Invalid mount point"),
                                            _("An error occurred when trying "
                                              "to create %s.  Some element of "
@@ -1538,8 +1538,8 @@ class FSSet(object):
                                              "cannot continue.\n\n"
                                              "Press <Enter> to exit the "
                                              "installer.")
-                                            % (device.format.mountpoint, msg))
-                log.error("OSError: (%d) %s" % (num, msg) )
+                                            % (device.format.mountpoint, e.strerror))
+                log.error("OSError: (%d) %s" % (e.errno, e.strerror))
                 sys.exit(0)
             except SystemError as (num, msg):
                 if raiseErrors:
diff --git a/syslogd.py b/syslogd.py
index 9b95e59..267b7fd 100644
--- a/syslogd.py
+++ b/syslogd.py
@@ -91,13 +91,13 @@ class InstSyslog:
             return
         try:
             os.kill (self.pid, 15)
-        except OSError, (num, msg):
-            log.error("killing syslogd failed: %s %s" %(num, msg))
+        except OSError as e:
+            log.error("killing syslogd failed: %s %s" %(e.errno, e.strerror))
 	
         try:
 	    os.waitpid (self.pid, 0)
-        except OSError, (num, msg):
-            log.error("exception from waitpid in syslogd::stop: %s %s" % (num, msg))
+        except OSError as e:
+            log.error("exception from waitpid in syslogd::stop: %s %s" % (e.errno, e.strerror))
 
         self.pid = -1
 
diff --git a/timezone.py b/timezone.py
index f29e9a7..4b2dfbe 100644
--- a/timezone.py
+++ b/timezone.py
@@ -44,8 +44,8 @@ class Timezone:
         else:
             try:
                 shutil.copyfile(fromFile, instPath + "/etc/localtime")
-            except OSError, (errno, msg):
-                log.error("Error copying timezone (from %s): %s" % (fromFile, msg))
+            except OSError as e:
+                log.error("Error copying timezone (from %s): %s" % (fromFile, e.strerror))
 
         f = open(instPath + "/etc/sysconfig/clock", "w")
 
diff --git a/users.py b/users.py
index a146aa2..ec9aa05 100644
--- a/users.py
+++ b/users.py
@@ -145,8 +145,8 @@ class Users:
 
         try:
             (pid, status) = os.waitpid(childpid, 0)
-        except OSError, (num, msg):
-            log.critical("exception from waitpid while creating a user: %s %s" % (num, msg))
+        except OSError as e:
+            log.critical("exception from waitpid while creating a user: %s %s" % (e.errno, e.strerror))
             return False
 
         if os.WIFEXITED(status) and (os.WEXITSTATUS(status) == 0):
diff --git a/yuminstall.py b/yuminstall.py
index 753e099..d097eaa 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -201,8 +201,8 @@ class AnacondaCallback:
             if os.path.dirname(fn).startswith("%s/var/cache/yum/" % self.rootPath):
                 try:
                     os.unlink(fn)
-                except OSError, e:
-                    log.debug("unable to remove file %s" %(e,))
+                except OSError as e:
+                    log.debug("unable to remove file %s" %(e.strerror,))
 
             self.donepkgs += 1
             self.doneSize += self.inProgressPo.returnSimple("installedsize") / 1024.0
-- 
1.6.1.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux