From: Artem Bityutskiy Date: Tue, 24 Sep 2013 10:00:12 +0000 (+0300) Subject: BmapCopy: rename _logger to _log X-Git-Tag: v3.0~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4bb4abbab57ca451461ec6da8cf21605e316f050;p=tools%2Fbmap-tools.git BmapCopy: rename _logger to _log 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 --- diff --git a/bmaptool b/bmaptool index 3d30bc3..73c226e 100755 --- 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) diff --git a/bmaptools/BmapCopy.py b/bmaptools/BmapCopy.py index 3899f38..88bdeca 100644 --- a/bmaptools/BmapCopy.py +++ b/bmaptools/BmapCopy.py @@ -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): """ diff --git a/bmaptools/TransRead.py b/bmaptools/TransRead.py index 469a351..ff7f74d 100644 --- a/bmaptools/TransRead.py +++ b/bmaptools/TransRead.py @@ -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: