Remove junk back-slashes
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 4 Jul 2013 07:40:27 +0000 (10:40 +0300)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 4 Jul 2013 08:00:26 +0000 (11:00 +0300)
In Python we don't need the line-continuation "\" inside (), [], {}.

Suggested by Simon McVittie <simon.mcvittie@collabora.co.uk>.

Change-Id: I2c258cd1099e5c07bd710cd66854f6291c04f623
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptool
bmaptools/BmapCopy.py
bmaptools/BmapCreate.py
bmaptools/Fiemap.py
bmaptools/TransRead.py
tests/test_api_base.py
tests/test_fiemap.py

index 5482f989ab9616b80cb1c01aeb667c411f967078..2b1bda0ffc3e2854b83d8437b824ed238e956283 100755 (executable)
--- a/bmaptool
+++ b/bmaptool
@@ -81,7 +81,7 @@ def copy_command_open_blkdev(path, log):
     try:
         descriptor = os.open(path, os.O_WRONLY | os.O_EXCL)
     except OSError as err:
-        log.error("cannot open block device '%s' in exclusive mode: %s" \
+        log.error("cannot open block device '%s' in exclusive mode: %s"
                   % (path, err))
         raise SystemExit(1)
 
@@ -169,7 +169,7 @@ def copy_command_open_all(args, log):
     try:
         dest_obj = open(args.dest, 'wb+')
     except IOError as err:
-        log.error("cannot open destination file '%s': %s" \
+        log.error("cannot open destination file '%s': %s"
                   % (args.dest, err))
         raise SystemExit(1)
 
@@ -214,11 +214,11 @@ def copy_command(args, log):
             raise SystemExit(1)
     else:
         log.info("block map format version %s" % writer.bmap_version)
-        log.info("%d blocks of size %d (%s), mapped %d blocks (%s or %.1f%%)" \
+        log.info("%d blocks of size %d (%s), mapped %d blocks (%s or %.1f%%)"
                  % (writer.blocks_cnt, writer.block_size,
                     writer.image_size_human, writer.mapped_cnt,
                     writer.mapped_size_human, writer.mapped_percent))
-        log.info("copying image '%s' to %s using bmap file '%s'" \
+        log.info("copying image '%s' to %s using bmap file '%s'"
                  % (os.path.basename(args.image), dest_str,
                     os.path.basename(bmap_path)))
 
@@ -242,8 +242,8 @@ def copy_command(args, log):
 
     copying_time = time.time() - start_time
     copying_speed = writer.mapped_size / copying_time
-    log.info("copying time: %s, copying speed %s/sec" \
-             % (BmapHelpers.human_time(copying_time), \
+    log.info("copying time: %s, copying speed %s/sec"
+             % (BmapHelpers.human_time(copying_time),
                 BmapHelpers.human_size(copying_speed)))
 
     dest_obj.close()
@@ -282,7 +282,7 @@ def create_command(args, log):
         try:
             output = open(args.output, "w+")
         except IOError as err:
-            log.error("cannot open the output file '%s': %s" \
+            log.error("cannot open the output file '%s': %s"
                       % (args.output, err))
             raise SystemExit(1)
     else:
@@ -305,9 +305,9 @@ def create_command(args, log):
         sys.stdout.write(output.read())
 
     if creator.mapped_cnt == creator.blocks_cnt:
-        log.warning("all %s are mapped, no holes in '%s'" \
+        log.warning("all %s are mapped, no holes in '%s'"
                     % (creator.image_size_human, args.image))
-        log.warning("was the image handled incorrectly and holes " \
+        log.warning("was the image handled incorrectly and holes "
                     "were expanded?")
 
 def parse_arguments():
@@ -318,7 +318,7 @@ def parse_arguments():
     parser = argparse.ArgumentParser(description = text, prog = 'bmaptool')
 
     # The --version option
-    parser.add_argument("--version", action = "version", \
+    parser.add_argument("--version", action = "version",
                         version = "%(prog)s " + "%s" % VERSION)
 
     # The --quiet option
index f6974cec707df8f31d6eb8a4bc56c91c320e66f6..a025cb5b973cc2f41f41b3d1dca01cb70e1b26d3 100644 (file)
@@ -142,7 +142,7 @@ class BmapCopy:
         """
 
         if self.image_size is not None and self.image_size != image_size:
-            raise Error("cannot set image size to %d bytes, it is known to " \
+            raise Error("cannot set image size to %d bytes, it is known to "
                         "be %d bytes (%s)" % (image_size, self.image_size,
                                               self.image_size_human))
 
@@ -180,9 +180,9 @@ class BmapCopy:
         mapped_bmap.close()
 
         if calculated_sha1 != correct_sha1:
-            raise Error("checksum mismatch for bmap file '%s': calculated " \
-                        "'%s', should be '%s'" % \
-                        (self._bmap_path, calculated_sha1, correct_sha1))
+            raise Error("checksum mismatch for bmap file '%s': calculated "
+                        "'%s', should be '%s'"
+                        (self._bmap_path, calculated_sha1, correct_sha1))
 
     def _parse_bmap(self):
         """
@@ -192,7 +192,7 @@ class BmapCopy:
         try:
             self._xml = ElementTree.parse(self._f_bmap)
         except  ElementTree.ParseError as err:
-            raise Error("cannot parse the bmap file '%s' which should be a " \
+            raise Error("cannot parse the bmap file '%s' which should be a "
                         "proper XML file: %s" % (self._bmap_path, err))
 
         xml = self._xml
@@ -202,8 +202,8 @@ class BmapCopy:
         self.bmap_version_major = int(self.bmap_version.split('.', 1)[0])
         self.bmap_version_minor = int(self.bmap_version.split('.', 1)[1])
         if self.bmap_version_major > SUPPORTED_BMAP_VERSION:
-            raise Error("only bmap format version up to %d is supported, " \
-                        "version %d is not supported" \
+            raise Error("only bmap format version up to %d is supported, "
+                        "version %d is not supported"
                         % (SUPPORTED_BMAP_VERSION, self.bmap_version_major))
 
         # Fetch interesting data from the bmap XML file
@@ -218,8 +218,8 @@ class BmapCopy:
 
         blocks_cnt = (self.image_size + self.block_size - 1) / self.block_size
         if self.blocks_cnt != blocks_cnt:
-            raise Error("Inconsistent bmap - image size does not match " \
-                        "blocks count (%d bytes != %d blocks * %d bytes)" \
+            raise Error("Inconsistent bmap - image size does not match "
+                        "blocks count (%d bytes != %d blocks * %d bytes)"
                         % (self.image_size, self.blocks_cnt, self.block_size))
 
         if self.bmap_version_major >= 1 and self.bmap_version_minor >= 3:
@@ -444,8 +444,8 @@ class BmapCopy:
                     try:
                         buf = self._f_image.read(length * self.block_size)
                     except IOError as err:
-                        raise Error("error while reading blocks %d-%d of the " \
-                                    "image file '%s': %s" \
+                        raise Error("error while reading blocks %d-%d of the "
+                                    "image file '%s': %s"
                                     % (start, end, self._image_path, err))
 
                     if not buf:
@@ -460,9 +460,9 @@ class BmapCopy:
                                            buf))
 
                 if verify and sha1 and hash_obj.hexdigest() != sha1:
-                    raise Error("checksum mismatch for blocks range %d-%d: " \
-                                "calculated %s, should be %s (image file %s)" \
-                                % (first, last, hash_obj.hexdigest(), \
+                    raise Error("checksum mismatch for blocks range %d-%d: "
+                                "calculated %s, should be %s (image file %s)"
+                                % (first, last, hash_obj.hexdigest(),
                                    sha1, self._image_path))
         # Silence pylint warning about catching too general exception
         # pylint: disable=W0703
@@ -524,7 +524,7 @@ class BmapCopy:
             try:
                 self._f_dest.write(buf)
             except IOError as err:
-                raise Error("error while writing blocks %d-%d of '%s': %s" \
+                raise Error("error while writing blocks %d-%d of '%s': %s"
                             % (start, end, self._dest_path, err))
 
             self._batch_queue.task_done()
@@ -540,10 +540,10 @@ class BmapCopy:
         # This is just a sanity check - we should have written exactly
         # 'mapped_cnt' blocks.
         if blocks_written != self.mapped_cnt:
-            raise Error("wrote %u blocks from image '%s' to '%s', but should " \
-                        "have %u - bmap file '%s' does not belong to this" \
-                        "image" \
-                        % (blocks_written, self._image_path, self._dest_path, \
+            raise Error("wrote %u blocks from image '%s' to '%s', but should "
+                        "have %u - bmap file '%s' does not belong to this"
+                        "image"
+                        % (blocks_written, self._image_path, self._dest_path,
                            self.mapped_cnt, self._bmap_path))
 
         if self._dest_is_regfile:
@@ -551,7 +551,7 @@ class BmapCopy:
             try:
                 os.ftruncate(self._f_dest.fileno(), self.image_size)
             except OSError as err:
-                raise Error("cannot truncate file '%s': %s" \
+                raise Error("cannot truncate file '%s': %s"
                             % (self._dest_path, err))
 
         try:
@@ -572,7 +572,7 @@ class BmapCopy:
             try:
                 os.fsync(self._f_dest.fileno()),
             except OSError as err:
-                raise Error("cannot synchronize '%s': %s " \
+                raise Error("cannot synchronize '%s': %s "
                             % (self._dest_path, err.strerror))
 
 
@@ -602,8 +602,8 @@ 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 "   \
+            self._logger.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
@@ -624,9 +624,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 "  \
+            self._logger.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):
@@ -640,7 +640,7 @@ class BmapBdevCopy(BmapCopy):
                 with open(self._sysfs_scheduler_path, "w") as f_scheduler:
                     f_scheduler.write(self._old_scheduler_value)
             except IOError as err:
-                raise Error("cannot restore the '%s' I/O scheduler: %s" \
+                raise Error("cannot restore the '%s' I/O scheduler: %s"
                             % (self._old_scheduler_value, err))
 
         if self._old_max_ratio_value is not None:
@@ -648,7 +648,7 @@ class BmapBdevCopy(BmapCopy):
                 with open(self._sysfs_max_ratio_path, "w") as f_ratio:
                     f_ratio.write(self._old_max_ratio_value)
             except IOError as err:
-                raise Error("cannot set the max. I/O ratio back to '%s': %s" \
+                raise Error("cannot set the max. I/O ratio back to '%s': %s"
                             % (self._old_max_ratio_value, err))
 
     def copy(self, sync=True, verify=True):
@@ -700,12 +700,12 @@ class BmapBdevCopy(BmapCopy):
                 bdev_size = os.lseek(self._f_dest.fileno(), 0, os.SEEK_END)
                 os.lseek(self._f_dest.fileno(), 0, os.SEEK_SET)
             except OSError as err:
-                raise Error("cannot seed block device '%s': %s " \
+                raise Error("cannot seed block device '%s': %s "
                             % (self._dest_path, err.strerror))
 
             if bdev_size < self.image_size:
-                raise Error("the image file '%s' has size %s and it will not " \
-                            "fit the block device '%s' which has %s capacity" \
+                raise Error("the image file '%s' has size %s and it will not "
+                            "fit the block device '%s' which has %s capacity"
                             % (self._image_path, self.image_size_human,
                                self._dest_path, human_size(bdev_size)))
 
index 3b7c2dadde65d3165f73e29bc6c88d6d2363a6fc..cb45bc8b5cc21442ddca9574265baa7e949b72b3 100644 (file)
@@ -111,7 +111,7 @@ class BmapCreate:
         try:
             self._f_image = open(self._image_path, 'rb')
         except IOError as err:
-            raise Error("cannot open image file '%s': %s" \
+            raise Error("cannot open image file '%s': %s"
                         % (self._image_path, err))
 
         self._f_image_needs_close = True
@@ -121,7 +121,7 @@ class BmapCreate:
         try:
             self._f_bmap = open(self._bmap_path, 'w+')
         except IOError as err:
-            raise Error("cannot open bmap file '%s': %s" \
+            raise Error("cannot open bmap file '%s': %s"
                         % (self._bmap_path, err))
 
         self._f_bmap_needs_close = True
@@ -170,7 +170,7 @@ class BmapCreate:
         self.image_size = self.fiemap.image_size
         self.image_size_human = human_size(self.image_size)
         if self.image_size == 0:
-            raise Error("cannot generate bmap for zero-sized image file '%s'" \
+            raise Error("cannot generate bmap for zero-sized image file '%s'"
                         % self._image_path)
 
         self.block_size = self.fiemap.block_size
@@ -235,8 +235,8 @@ class BmapCreate:
         self._f_bmap.write(xml)
 
         self._f_bmap.seek(self._mapped_count_pos1)
-        self._f_bmap.write("%s or %.1f%%" % \
-                           (self.mapped_size_human, self.mapped_percent))
+        self._f_bmap.write("%s or %.1f%%"
+                           (self.mapped_size_human, self.mapped_percent))
 
         self._f_bmap.seek(self._mapped_count_pos2)
         self._f_bmap.write("%u" % self.mapped_cnt)
@@ -294,10 +294,10 @@ class BmapCreate:
                 sha1 = ""
 
             if first != last:
-                self._f_bmap.write("        <Range%s> %s-%s </Range>\n" \
+                self._f_bmap.write("        <Range%s> %s-%s </Range>\n"
                                    % (sha1, first, last))
             else:
-                self._f_bmap.write("        <Range%s> %s </Range>\n" \
+                self._f_bmap.write("        <Range%s> %s </Range>\n"
                                    % (sha1, first))
 
         self.mapped_size = self.mapped_cnt * self.block_size
@@ -309,7 +309,7 @@ class BmapCreate:
         try:
             self._f_bmap.flush()
         except IOError as err:
-            raise Error("cannot flush the bmap file '%s': %s" \
+            raise Error("cannot flush the bmap file '%s': %s"
                         % (self._bmap_path, err))
 
         self._f_image.seek(image_pos)
index 0889df1e6a769bb5509b78da18d0204cdbe5deae..76857b835be90c3ad771b5d540de321539957f73 100644 (file)
@@ -64,7 +64,7 @@ class Fiemap:
         try:
             self._f_image = open(self._image_path, 'rb')
         except IOError as err:
-            raise Error("cannot open image file '%s': %s" \
+            raise Error("cannot open image file '%s': %s"
                         % (self._image_path, err))
 
         self._f_image_needs_close = True
@@ -91,7 +91,7 @@ class Fiemap:
 
         # Validate 'buf_size'
         if buf_size < MIN_BUFFER_SIZE:
-            raise Error("too small buffer (%d bytes), minimum is %d bytes" \
+            raise Error("too small buffer (%d bytes), minimum is %d bytes"
                     % (buf_size, MIN_BUFFER_SIZE))
 
         # How many 'struct fiemap_extent' elements fit the buffer
@@ -108,7 +108,7 @@ class Fiemap:
         try:
             self.block_size = BmapHelpers.get_block_size(self._f_image)
         except IOError as err:
-            raise Error("cannot get block size for '%s': %s" \
+            raise Error("cannot get block size for '%s': %s"
                         % (self._image_path, err))
 
         self.blocks_cnt = self.image_size + self.block_size - 1
@@ -118,12 +118,12 @@ class Fiemap:
         try:
             self._f_image.flush()
         except IOError as err:
-            raise Error("cannot flush image file '%s': %s" \
+            raise Error("cannot flush image file '%s': %s"
                         % (self._image_path, err))
         try:
             os.fsync(self._f_image.fileno()),
         except OSError as err:
-            raise Error("cannot synchronize image file '%s': %s " \
+            raise Error("cannot synchronize image file '%s': %s "
                         % (self._image_path, err.strerror))
 
         # Check if the FIEMAP ioctl is supported
@@ -145,7 +145,7 @@ class Fiemap:
         """
 
         if block < 0 or block >= self.blocks_cnt:
-            raise Error("bad block number %d, should be within [0, %d]" \
+            raise Error("bad block number %d, should be within [0, %d]"
                         % (block, self.blocks_cnt))
 
         # Initialize the 'struct fiemap' part of the buffer
index d2f31c325f135da539f7e22387de66f164259b0a..870b584c2e47af11819b79d8605b5b6b1d0bbae7 100644 (file)
@@ -43,13 +43,13 @@ def _fake_seek_forward(file_obj, cur_pos, offset, whence=os.SEEK_SET):
     elif whence == os.SEEK_CUR:
         new_pos = cur_pos + offset
     else:
-        raise Error("'seek()' method requires the 'whence' argument " \
-                    "to be %d or %d, but %d was passed" \
+        raise Error("'seek()' method requires the 'whence' argument "
+                    "to be %d or %d, but %d was passed"
                     % (os.SEEK_SET, os.SEEK_CUR, whence))
 
     if new_pos < cur_pos:
-        raise Error("''seek()' method supports only seeking forward, " \
-                    "seeking from %d to %d is not allowed" \
+        raise Error("''seek()' method supports only seeking forward, "
+                    "seeking from %d to %d is not allowed"
                     % (cur_pos, new_pos))
 
     length = new_pos - cur_pos
@@ -62,7 +62,7 @@ def _fake_seek_forward(file_obj, cur_pos, offset, whence=os.SEEK_SET):
         to_read -= len(buf)
 
     if to_read < 0:
-        raise Error("seeked too far: %d instead of %d" \
+        raise Error("seeked too far: %d instead of %d"
                     % (new_pos - to_read, new_pos))
 
     return new_pos - to_read
@@ -279,7 +279,7 @@ class TransRead:
                                     stdout=subprocess.PIPE).wait()
         except OSError as err:
             if err.errno == os.errno.ENOENT:
-                raise Error("\"sshpass\" program not found, but it is " \
+                raise Error("\"sshpass\" program not found, but it is "
                             "required for downloading over SSH")
 
         # Prepare the commands that we are going to run
@@ -300,7 +300,7 @@ class TransRead:
                                             stdout=subprocess.PIPE).wait()
             except OSError as err:
                 if err.errno == os.errno.ENOENT:
-                    raise Error("\"sshpass\" program not found, but it is " \
+                    raise Error("\"sshpass\" program not found, but it is "
                                 "required for password SSH authentication")
         else:
             popen_args = ["ssh",
@@ -316,8 +316,8 @@ class TransRead:
         retcode = child_process.returncode
         if retcode != 0:
             decoded = _decode_sshpass_exit_code(retcode)
-            raise Error("cannot connect to \"%s\": %s (error code %d)" % \
-                        (hostname, decoded, retcode))
+            raise Error("cannot connect to \"%s\": %s (error code %d)"
+                        (hostname, decoded, retcode))
 
         # Test if file exists by running "test -f path && test -r path" on the
         # host
@@ -326,8 +326,8 @@ class TransRead:
                                          stdout=subprocess.PIPE)
         child_process.wait()
         if child_process.returncode != 0:
-            raise Error("\"%s\" on \"%s\" cannot be read: make sure it " \
-                        "exists, is a regular file, and you have read "   \
+            raise Error("\"%s\" on \"%s\" cannot be read: make sure it "
+                        "exists, is a regular file, and you have read "
                         "permissions" % (path, hostname))
 
         # Read the entire file using 'cat'
@@ -386,7 +386,7 @@ class TransRead:
         except (IOError, ValueError, httplib.InvalidURL) as err:
             raise Error("cannot open URL '%s': %s" % (url, err))
         except httplib.BadStatusLine:
-            raise Error("cannot open URL '%s': server responds with an HTTP " \
+            raise Error("cannot open URL '%s': server responds with an HTTP "
                         "status code that we don't understand" % url)
 
     def _create_local_copy(self):
@@ -414,7 +414,7 @@ class TransRead:
         try:
             self._transfile_obj = open(tmp_file_obj.name, "rb")
         except IOError as err:
-            raise Error("cannot open own temporary file '%s': %s" \
+            raise Error("cannot open own temporary file '%s': %s"
                         % (tmp_file_obj.name, err))
 
     def __init__(self, filepath, local=False):
@@ -477,7 +477,7 @@ class TransRead:
     def seek(self, offset, whence=os.SEEK_SET):
         """The 'seek()' method, similar to the one file objects have."""
         if self._force_fake_seek or not hasattr(self._transfile_obj, "seek"):
-            self._pos = _fake_seek_forward(self._transfile_obj, self._pos, \
+            self._pos = _fake_seek_forward(self._transfile_obj, self._pos,
                                            offset, whence)
         else:
             self._transfile_obj.seek(offset, whence)
index 07e2e47c1784c10229489f6aa2d6811a4a2bdaaa..58f64b3ace15452ed237d42799c4c696492e2d91 100644 (file)
@@ -40,7 +40,7 @@ def _compare_holes(file1, file2):
     iterator = itertools.izip_longest(iterator1, iterator2)
     for range1, range2 in iterator:
         if range1 != range2:
-            raise Error("mismatch for hole %d-%d, it is %d-%d in file2" \
+            raise Error("mismatch for hole %d-%d, it is %d-%d in file2"
                         % (range1[0], range1[1], range2[0], range2[1]))
 
 def _generate_compressed_files(file_obj, delete=True):
index 609aeb30f016f69f9679e5aa2af9de4a194ba2c1..0c031d271cbfa743690a36f59adae38d41e976d3 100644 (file)
@@ -46,7 +46,7 @@ def _check_ranges(f_image, fiemap, first_block, blocks_cnt,
     # starting from block 'first_block'. Create an iterator which filters
     # those block ranges from the 'ranges' list, that are out of the
     # 'first_block'/'blocks_cnt' file region.
-    ranges_iterator = ( x for x in ranges if x[1] >= first_block and \
+    ranges_iterator = ( x for x in ranges if x[1] >= first_block and
                                              x[0] <= last_block )
     iterator = itertools.izip_longest(ranges_iterator, fiemap_iterator)
 
@@ -63,8 +63,8 @@ def _check_ranges(f_image, fiemap, first_block, blocks_cnt,
             correct = (correct[0], last_block)
 
         if check[0] > check[1] or check != correct:
-            raise Error("bad or unmatching %s range for file '%s': correct " \
-                        "is %d-%d, get_%s_ranges(%d, %d) returned %d-%d" \
+            raise Error("bad or unmatching %s range for file '%s': correct "
+                        "is %d-%d, get_%s_ranges(%d, %d) returned %d-%d"
                         % (ranges_type, f_image.name, correct[0], correct[1],
                            ranges_type, first_block, blocks_cnt,
                            check[0], check[1]))