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)))
# 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
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)
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:
# 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)
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)
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,
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
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
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]".
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):
"""
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
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
# 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: