Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 4bb4abb

Browse files
committed
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 <artem.bityutskiy@intel.com>
1 parent 091b905 commit 4bb4abb

3 files changed

Lines changed: 33 additions & 34 deletions

File tree

bmaptool

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def verify_detached_bmap_signature(args, bmap_obj, bmap_path, log):
138138

139139
if args.bmap_sig:
140140
try:
141-
sig_obj = TransRead.TransRead(args.bmap_sig, logger=log)
141+
sig_obj = TransRead.TransRead(args.bmap_sig, log=log)
142142
except TransRead.Error as err:
143143
log.error("cannot open bmap signature file '%s': %s" %
144144
(args.bmap_sig, str(err)))
@@ -148,11 +148,11 @@ def verify_detached_bmap_signature(args, bmap_obj, bmap_path, log):
148148
# Check if there is a stand-alone signature file
149149
try:
150150
sig_path = bmap_path + ".asc"
151-
sig_obj = TransRead.TransRead(sig_path, logger=log)
151+
sig_obj = TransRead.TransRead(sig_path, log=log)
152152
except TransRead.Error:
153153
try:
154154
sig_path = bmap_path + ".sig"
155-
sig_obj = TransRead.TransRead(sig_path, logger=log)
155+
sig_obj = TransRead.TransRead(sig_path, log=log)
156156
except TransRead.Error:
157157
# No signatures found
158158
return None
@@ -310,7 +310,7 @@ def find_and_open_bmap(args, log):
310310

311311
if args.bmap:
312312
try:
313-
bmap_obj = TransRead.TransRead(args.bmap, logger=log)
313+
bmap_obj = TransRead.TransRead(args.bmap, log=log)
314314
except TransRead.Error as err:
315315
log.error("cannot open bmap file '%s': %s" % (args.bmap, str(err)))
316316
raise SystemExit(1)
@@ -321,7 +321,7 @@ def find_and_open_bmap(args, log):
321321
while True:
322322
bmap_path = image_path + ".bmap"
323323
try:
324-
bmap_obj = TransRead.TransRead(bmap_path, logger=log)
324+
bmap_obj = TransRead.TransRead(bmap_path, log=log)
325325
log.info("discovered bmap file '%s'" % bmap_path)
326326
break
327327
except TransRead.Error:
@@ -363,7 +363,7 @@ def open_files(args, log):
363363
# Open the image file using the TransRead module, which will automatically
364364
# recognize whether it is compressed or whether file path is an URL, etc.
365365
try:
366-
image_obj = TransRead.TransRead(args.image, logger=log)
366+
image_obj = TransRead.TransRead(args.image, log=log)
367367
except TransRead.Error as err:
368368
log.error("cannot open image: %s" % str(err))
369369
raise SystemExit(1)
@@ -433,11 +433,11 @@ def copy_command(args, log):
433433
dest_str = "block device '%s'" % args.dest
434434
# For block devices, use the specialized class
435435
writer = BmapCopy.BmapBdevCopy(image_obj, dest_obj, bmap_obj,
436-
image_size, logger=log)
436+
image_size, log=log)
437437
else:
438438
dest_str = "file '%s'" % os.path.basename(args.dest)
439439
writer = BmapCopy.BmapCopy(image_obj, dest_obj, bmap_obj,
440-
image_size, logger=log)
440+
image_size, log=log)
441441
except BmapCopy.Error as err:
442442
log.error(str(err))
443443
raise SystemExit(1)

bmaptools/BmapCopy.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class BmapCopy:
117117
instance.
118118
"""
119119

120-
def __init__(self, image, dest, bmap=None, image_size=None, logger=None):
120+
def __init__(self, image, dest, bmap=None, image_size=None, log=None):
121121
"""
122122
The class constructor. The parameters are:
123123
image - file-like object of the image which should be copied,
@@ -127,12 +127,12 @@ def __init__(self, image, dest, bmap=None, image_size=None, logger=None):
127127
to.
128128
bmap - file object of the bmap file to use for copying.
129129
image_size - size of the image in bytes.
130-
logger - the logger object to use for printing messages.
130+
log - the logger object to use for printing messages.
131131
"""
132132

133-
self._logger = logger
134-
if self._logger is None:
135-
self._logger = logging.getLogger(__name__)
133+
self._log = log
134+
if self._log is None:
135+
self._log = logging.getLogger(__name__)
136136

137137
self._xml = None
138138

@@ -619,14 +619,14 @@ class BmapBdevCopy(BmapCopy):
619619
scheduler.
620620
"""
621621

622-
def __init__(self, image, dest, bmap=None, image_size=None, logger=None):
622+
def __init__(self, image, dest, bmap=None, image_size=None, log=None):
623623
"""
624624
The same as the constructor of the 'BmapCopy' base class, but adds
625625
useful guard-checks specific to block devices.
626626
"""
627627

628628
# Call the base class constructor first
629-
BmapCopy.__init__(self, image, dest, bmap, image_size, logger=logger)
629+
BmapCopy.__init__(self, image, dest, bmap, image_size, log=log)
630630

631631
self._dest_fsync_watermark = (6 * 1024 * 1024) / self.block_size
632632

@@ -683,9 +683,9 @@ def _tune_block_device(self):
683683
f_scheduler.seek(0)
684684
f_scheduler.write("noop")
685685
except IOError as err:
686-
self._logger.warning("failed to enable I/O optimization, expect "
687-
"suboptimal speed (reason: cannot switch "
688-
"to the 'noop' I/O scheduler: %s)" % err)
686+
self._log.warning("failed to enable I/O optimization, expect "
687+
"suboptimal speed (reason: cannot switch "
688+
"to the 'noop' I/O scheduler: %s)" % err)
689689
else:
690690
# The file contains a list of schedulers with the current
691691
# scheduler in square brackets, e.g., "noop deadline [cfq]".
@@ -705,10 +705,9 @@ def _tune_block_device(self):
705705
f_ratio.seek(0)
706706
f_ratio.write("1")
707707
except IOError as err:
708-
self._logger.warning("failed to disable excessive buffering, "
709-
"expect worse system responsiveness "
710-
"(reason: cannot set max. I/O ratio to "
711-
"1: %s)" % err)
708+
self._log.warning("failed to disable excessive buffering, expect "
709+
"worse system responsiveness (reason: cannot set "
710+
"max. I/O ratio to 1: %s)" % err)
712711

713712
def _restore_bdev_settings(self):
714713
"""

bmaptools/TransRead.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,16 @@ class TransRead:
219219
this class are file-like objects which you can read and seek only forward.
220220
"""
221221

222-
def __init__(self, filepath, logger=None):
222+
def __init__(self, filepath, log=None):
223223
"""
224224
Class constructor. The 'filepath' argument is the full path to the file
225-
to read transparently. The "logger" argument is the logger object to
226-
use for printing messages.
225+
to read transparently. The "log" argument is the logger object to use
226+
for printing messages.
227227
"""
228228

229-
self._logger = logger
230-
if self._logger is None:
231-
self._logger = logging.getLogger(__name__)
229+
self._log = log
230+
if self._log is None:
231+
self._log = logging.getLogger(__name__)
232232

233233
self.name = filepath
234234
# Size of the file (in uncompressed form), may be 'None' if the size is
@@ -429,14 +429,14 @@ def _open_url(self, url):
429429
Open an URL 'url' and return the file-like object of the opened URL.
430430
"""
431431

432-
def _print_warning(logger, timeout):
432+
def _print_warning(log, timeout):
433433
"""
434434
This is a small helper function for printing a warning if we cannot
435435
open the URL for some time.
436436
"""
437-
logger.warning("failed to open the URL with %d sec timeout, is the "
438-
"proxy configured correctly? Keep trying ..." %
439-
timeout)
437+
log.warning("failed to open the URL with %d sec timeout, is the "
438+
"proxy configured correctly? Keep trying ..." %
439+
timeout)
440440

441441
import urllib2
442442
import httplib
@@ -488,14 +488,14 @@ def _print_warning(logger, timeout):
488488
# Handling the timeout case in Python 2.7
489489
except socket.timeout, err:
490490
if timeout is not None:
491-
_print_warning(self._logger, timeout)
491+
_print_warning(self._log, timeout)
492492
else:
493493
raise Error("cannot open URL '%s': %s" % (url, err))
494494
except urllib2.URLError as err:
495495
# Handling the timeout case in Python 2.6
496496
if timeout is not None and \
497497
isinstance(err.reason, socket.timeout):
498-
_print_warning(self._logger, timeout)
498+
_print_warning(self._log, timeout)
499499
else:
500500
raise Error("cannot open URL '%s': %s" % (url, err))
501501
except (IOError, ValueError, httplib.InvalidURL) as err:

0 commit comments

Comments
 (0)