[master 4/9] Use python 3's OSError subclasses instead of checking errno

dashea installerbot-noreply at redhat.com
Thu Jun 18 21:03:50 UTC 2015


From: David Shea <dshea at redhat.com>

---
 anaconda            | 20 +++++++-------------
 pyanaconda/iutil.py | 11 ++++-------
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/anaconda b/anaconda
index efc9c1c..a7ea57e 100755
--- a/anaconda
+++ b/anaconda
@@ -44,7 +44,7 @@ if ("debug=1" in proc_cmdline) or ("debug" in proc_cmdline):
     cov.start()
 
 
-import atexit, sys, os, time, signal, stat, errno
+import atexit, sys, os, time, signal, stat
 
 def exitHandler(rebootData, storage):
     # Clear the list of watched PIDs.
@@ -928,13 +928,12 @@ if __name__ == "__main__":
     try:
         with open(pidfile_path, 'r') as pidfile:
             pid = int(pidfile.read())
-    except IOError as e:
+    except FileNotFoundError:
         # Ignore errors due to the file not existing. Other errors mean (most
         # likely) that we're not running as root, there's a filesystem error,
         # or someone filled our PID file with garbage, so just let those be
         # raised.
-        if e.errno != errno.ENOENT:
-            raise
+        pass
     else:
         # Is the PID still running?
         if not os.path.isdir("/proc/%s" % pid):
@@ -951,14 +950,14 @@ if __name__ == "__main__":
                         os.unlink(pidfile_path)
                     # If it is anaconda, let the pidfile creation below fail
                     # and print an error
-            except IOError as e:
+            except (FileNotFoundError, ProcessLookupError):
                 # Ignore failures due to the file not existing in case the
                 # process ended while we were trying to read about it. Assume
                 # in this case that the process was another anaconda instance,
                 # and the PID file was cleaned up.
                 # If the process ended between open and read, we'll get ESRCH
-                if e.errno not in (errno.ENOENT, errno.ESRCH):
-                    raise
+                # (ProcessLookupError)
+                pass
 
     # Attempt to create the pidfile
     try:
@@ -969,12 +968,7 @@ if __name__ == "__main__":
         pid_string = "%s\n" % os.getpid()
         iutil.eintr_retry_call(os.write, pidfile, pid_string.encode("utf-8"))
         os.close(pidfile)
-    except OSError as e:
-        # If the failure was anything other than EEXIST during the open call,
-        # just re-raise the exception
-        if e.errno != errno.EEXIST:
-            raise
-
+    except FileExistsError:
         log.error("%s already exists, exiting", pidfile_path)
 
         # If we had a $DISPLAY at start and zenity is available, we may be
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index f06d19e..1aa85d0 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -509,9 +509,8 @@ def _sigchld_handler(num=None, frame=None):
     for child_pid in _forever_pids:
         try:
             pid_result, status = eintr_retry_call(os.waitpid, child_pid, os.WNOHANG)
-        except OSError as e:
-            if e.errno == errno.ECHILD:
-                continue
+        except ChildProcessError:
+            continue
 
         if pid_result:
             proc_name = _forever_pids[child_pid][0]
@@ -1300,10 +1299,8 @@ def eintr_retry_call(func, *args, **kwargs):
     while True:
         try:
             return func(*args, **kwargs)
-        except (OSError, IOError) as e:
-            if e.errno == errno.EINTR:
-                continue
-            raise
+        except InterruptedError:
+            continue
 
 def parent_dir(directory):
     """Return the parent's path"""


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/b4b7c758d64379eb8fa61f2a20a1520fbe67be63


More information about the anaconda-patches mailing list