[master] Tidy warnings.showwarning into anaconda_log.py.

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

 



Also remove unused 'warnings' imports.
---
 anaconda                    |    6 ------
 pyanaconda/anaconda_log.py  |   18 +++++++++++++++---
 pyanaconda/isys/__init__.py |    1 -
 pyanaconda/kickstart.py     |    3 +--
 pyanaconda/yuminstall.py    |    1 -
 5 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/anaconda b/anaconda
index 6ca3391..676b033 100755
--- a/anaconda
+++ b/anaconda
@@ -37,10 +37,6 @@ from tempfile import mkstemp
 # keep up with process ID of the window manager if we start it
 wm_pid = None
 
-# Make sure messages sent through python's warnings module get logged.
-def AnacondaShowWarning(message, category, filename, lineno, file=sys.stderr, line=None):
-    log.warning("%s" % warnings.formatwarning(message, category, filename, lineno, line))
-
 def startMetacityWM():
     childpid = os.fork()
     if not childpid:
@@ -575,7 +571,6 @@ if __name__ == "__main__":
     isys.initLog()
 
     import signal, string, time
-    import warnings
 
     from pyanaconda import iutil
     from pyanaconda import vnc
@@ -586,7 +581,6 @@ if __name__ == "__main__":
 
     from pyanaconda import Anaconda
     anaconda = Anaconda()
-    warnings.showwarning = AnacondaShowWarning
     iutil.setup_translations(gettext)
 
     # reset python's default SIGINT handler
diff --git a/pyanaconda/anaconda_log.py b/pyanaconda/anaconda_log.py
index 04dea8d..235fc54 100644
--- a/pyanaconda/anaconda_log.py
+++ b/pyanaconda/anaconda_log.py
@@ -29,6 +29,7 @@ import os
 import signal
 import sys
 import types
+import warnings
 
 import iutil
 from flags import flags
@@ -120,9 +121,10 @@ class AnacondaLog:
         logging.addLevelName(logging.CRITICAL, "CRIT")
 
         # Create the base of the logger hierarchy.
-        anaconda_logger = logging.getLogger("anaconda")
-        self.addFileHandler(MAIN_LOG_FILE, anaconda_logger,
+        self.anaconda_logger = logging.getLogger("anaconda")
+        self.addFileHandler(MAIN_LOG_FILE, self.anaconda_logger,
                             minLevel=logging.DEBUG)
+        warnings.showwarning = self.showwarning
 
         # Create the storage logger.
         storage_logger = logging.getLogger("storage")
@@ -130,7 +132,7 @@ class AnacondaLog:
                             minLevel=logging.DEBUG)
 
         # Set the common parameters for anaconda and storage loggers.
-        for logger in [anaconda_logger, storage_logger]:
+        for logger in [self.anaconda_logger, storage_logger]:
             logger.setLevel(logging.DEBUG)
             self.forwardToSyslog(logger)
             # Logging of basic stuff and storage to tty3.
@@ -190,6 +192,16 @@ class AnacondaLog:
         syslogHandler.setLevel(logging.DEBUG)
         logger.addHandler(syslogHandler)
 
+    def showwarning(self, message, category, filename, lineno,
+                      file=sys.stderr, line=None):
+        """ Make sure messages sent through python's warnings module get logged.
+
+            The warnings mechanism is used by some libraries we use,
+            notably pykickstart.
+        """
+        self.anaconda_logger.warning("%s" % warnings.formatwarning(
+                message, category, filename, lineno, line))
+
     def updateRemote(self, remote_syslog):
         """Updates the location of remote rsyslogd to forward to.
 
diff --git a/pyanaconda/isys/__init__.py b/pyanaconda/isys/__init__.py
index 13026c7..fc766fc 100755
--- a/pyanaconda/isys/__init__.py
+++ b/pyanaconda/isys/__init__.py
@@ -37,7 +37,6 @@ import stat
 import posix
 import sys
 from pyanaconda import iutil
-import warnings
 import resource
 import re
 import struct
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 7ec12b1..c38606d 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -40,7 +40,6 @@ from constants import *
 import sys
 import string
 import urlgrabber
-import warnings
 import network
 import upgrade
 import pykickstart.commands as commands
@@ -1508,7 +1507,7 @@ def setSteps(anaconda):
 
         # Special check for this, since it doesn't make any sense.
         if packagesSeen:
-            warnings.warn("Ignoring contents of %packages section due to upgrade.")
+            log.warning("Ignoring contents of %packages section due to upgrade.")
     elif havePackages(ksdata.packages):
         dispatch.skip_steps("tasksel", "group-selection")
     else:
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index da10e97..69275ee 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -26,7 +26,6 @@ import os
 import os.path
 import shutil
 import time
-import warnings
 import types
 import locale
 import glob
-- 
1.7.6

_______________________________________________
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