BmapCopy: rename _logger to _log
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Tue, 24 Sep 2013 10:00:12 +0000 (13:00 +0300)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Mon, 30 Sep 2013 07:10:04 +0000 (10:10 +0300)
This patch renames the _logger class attribute to "_log". The reason is to make
logging statements shorter. Besides, we use "log" in bmaptool, so this also
brings a bit more consistency.

Do the same change also in TransRead.

Change-Id: I72ce6070bb792b99349ea3bd9a229cb5f7b1ca49
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptool
bmaptools/BmapCopy.py
bmaptools/TransRead.py

index 3d30bc30b81e6aaf3e0ae566ca8db7350af5ce76..73c226e9f00aef1542a988b6d62ec1f67005c250 100755 (executable)
--- a/bmaptool
+++ b/bmaptool
@@ -138,7 +138,7 @@ def verify_detached_bmap_signature(args, bmap_obj, bmap_path, log):
 
     if args.bmap_sig:
         try:
-            sig_obj = TransRead.TransRead(args.bmap_sig, logger=log)
+            sig_obj = TransRead.TransRead(args.bmap_sig, log=log)
         except TransRead.Error as err:
             log.error("cannot open bmap signature file '%s': %s" %
                       (args.bmap_sig, str(err)))
@@ -148,11 +148,11 @@ def verify_detached_bmap_signature(args, bmap_obj, bmap_path, log):
         # Check if there is a stand-alone signature file
         try:
             sig_path = bmap_path + ".asc"
-            sig_obj = TransRead.TransRead(sig_path, logger=log)
+            sig_obj = TransRead.TransRead(sig_path, log=log)
         except TransRead.Error:
             try:
                 sig_path = bmap_path + ".sig"
-                sig_obj = TransRead.TransRead(sig_path, logger=log)
+                sig_obj = TransRead.TransRead(sig_path, log=log)
             except TransRead.Error:
                 # No signatures found
                 return None
@@ -310,7 +310,7 @@ def find_and_open_bmap(args, log):
 
     if args.bmap:
         try:
-            bmap_obj = TransRead.TransRead(args.bmap, logger=log)
+            bmap_obj = TransRead.TransRead(args.bmap, log=log)
         except TransRead.Error as err:
             log.error("cannot open bmap file '%s': %s" % (args.bmap, str(err)))
             raise SystemExit(1)
@@ -321,7 +321,7 @@ def find_and_open_bmap(args, log):
         while True:
             bmap_path = image_path + ".bmap"
             try:
-                bmap_obj = TransRead.TransRead(bmap_path, logger=log)
+                bmap_obj = TransRead.TransRead(bmap_path, log=log)
                 log.info("discovered bmap file '%s'" % bmap_path)
                 break
             except TransRead.Error:
@@ -363,7 +363,7 @@ def open_files(args, log):
     # Open the image file using the TransRead module, which will automatically
     # recognize whether it is compressed or whether file path is an URL, etc.
     try:
-        image_obj = TransRead.TransRead(args.image, logger=log)
+        image_obj = TransRead.TransRead(args.image, log=log)
     except TransRead.Error as err:
         log.error("cannot open image: %s" % str(err))
         raise SystemExit(1)
@@ -433,11 +433,11 @@ def copy_command(args, log):
             dest_str = "block device '%s'" % args.dest
             # For block devices, use the specialized class
             writer = BmapCopy.BmapBdevCopy(image_obj, dest_obj, bmap_obj,
-                                           image_size, logger=log)
+                                           image_size, log=log)
         else:
             dest_str = "file '%s'" % os.path.basename(args.dest)
             writer = BmapCopy.BmapCopy(image_obj, dest_obj, bmap_obj,
-                                       image_size, logger=log)
+                                       image_size, log=log)
     except BmapCopy.Error as err:
         log.error(str(err))
         raise SystemExit(1)
index 3899f38bedc74e98f8dc447127f3bc65ec44eca8..88bdeca34f9fc9de1519b2d83c081fca97ec3c97 100644 (file)
@@ -117,7 +117,7 @@ class BmapCopy:
     instance.
     """
 
-    def __init__(self, image, dest, bmap=None, image_size=None, logger=None):
+    def __init__(self, image, dest, bmap=None, image_size=None, log=None):
         """
         The class constructor. The parameters are:
             image      - file-like object of the image which should be copied,
@@ -127,12 +127,12 @@ class BmapCopy:
                          to.
             bmap       - file object of the bmap file to use for copying.
             image_size - size of the image in bytes.
-            logger     - the logger object to use for printing messages.
+            log     - the logger object to use for printing messages.
         """
 
-        self._logger = logger
-        if self._logger is None:
-            self._logger = logging.getLogger(__name__)
+        self._log = log
+        if self._log is None:
+            self._log = logging.getLogger(__name__)
 
         self._xml = None
 
@@ -619,14 +619,14 @@ class BmapBdevCopy(BmapCopy):
     scheduler.
     """
 
-    def __init__(self, image, dest, bmap=None, image_size=None, logger=None):
+    def __init__(self, image, dest, bmap=None, image_size=None, log=None):
         """
         The same as the constructor of the 'BmapCopy' base class, but adds
         useful guard-checks specific to block devices.
         """
 
         # Call the base class constructor first
-        BmapCopy.__init__(self, image, dest, bmap, image_size, logger=logger)
+        BmapCopy.__init__(self, image, dest, bmap, image_size, log=log)
 
         self._dest_fsync_watermark = (6 * 1024 * 1024) / self.block_size
 
@@ -683,9 +683,9 @@ class BmapBdevCopy(BmapCopy):
                 f_scheduler.seek(0)
                 f_scheduler.write("noop")
         except IOError as err:
-            self._logger.warning("failed to enable I/O optimization, expect "
-                                 "suboptimal speed (reason: cannot switch "
-                                 "to the 'noop' I/O scheduler: %s)" % err)
+            self._log.warning("failed to enable I/O optimization, expect "
+                              "suboptimal speed (reason: cannot switch "
+                              "to the 'noop' I/O scheduler: %s)" % err)
         else:
             # The file contains a list of schedulers with the current
             # scheduler in square brackets, e.g., "noop deadline [cfq]".
@@ -705,10 +705,9 @@ class BmapBdevCopy(BmapCopy):
                 f_ratio.seek(0)
                 f_ratio.write("1")
         except IOError as err:
-            self._logger.warning("failed to disable excessive buffering, "
-                                 "expect worse system responsiveness "
-                                 "(reason: cannot set max. I/O ratio to "
-                                 "1: %s)" % err)
+            self._log.warning("failed to disable excessive buffering, expect "
+                              "worse system responsiveness (reason: cannot set "
+                              "max. I/O ratio to 1: %s)" % err)
 
     def _restore_bdev_settings(self):
         """
index 469a351a11aeef24dca1b0a39ca92d57b8c15ebc..ff7f74d03fbdd6f1f71d04acb9750bbb8a5bab60 100644 (file)
@@ -219,16 +219,16 @@ class TransRead:
     this class are file-like objects which you can read and seek only forward.
     """
 
-    def __init__(self, filepath, logger=None):
+    def __init__(self, filepath, log=None):
         """
         Class constructor. The 'filepath' argument is the full path to the file
-        to read transparently. The "logger" argument is the logger object to
-        use for printing messages.
+        to read transparently. The "log" argument is the logger object to use
+        for printing messages.
         """
 
-        self._logger = logger
-        if self._logger is None:
-            self._logger = logging.getLogger(__name__)
+        self._log = log
+        if self._log is None:
+            self._log = logging.getLogger(__name__)
 
         self.name = filepath
         # Size of the file (in uncompressed form), may be 'None' if the size is
@@ -429,14 +429,14 @@ class TransRead:
         Open an URL 'url' and return the file-like object of the opened URL.
         """
 
-        def _print_warning(logger, timeout):
+        def _print_warning(log, timeout):
             """
             This is a small helper function for printing a warning if we cannot
             open the URL for some time.
             """
-            logger.warning("failed to open the URL with %d sec timeout, is the "
-                           "proxy configured correctly? Keep trying ..." %
-                           timeout)
+            log.warning("failed to open the URL with %d sec timeout, is the "
+                        "proxy configured correctly? Keep trying ..." %
+                        timeout)
 
         import urllib2
         import httplib
@@ -488,14 +488,14 @@ class TransRead:
             # Handling the timeout case in Python 2.7
             except socket.timeout, err:
                 if timeout is not None:
-                    _print_warning(self._logger, timeout)
+                    _print_warning(self._log, timeout)
                 else:
                     raise Error("cannot open URL '%s': %s" % (url, err))
             except urllib2.URLError as err:
                 # Handling the timeout case in Python 2.6
                 if timeout is not None and \
                    isinstance(err.reason, socket.timeout):
-                    _print_warning(self._logger, timeout)
+                    _print_warning(self._log, timeout)
                 else:
                     raise Error("cannot open URL '%s': %s" % (url, err))
             except (IOError, ValueError, httplib.InvalidURL) as err: