def copy_command(args, log):
"""Copy an image to a block device or a regular file using bmap."""
-
image_obj, dest_obj, bmap_obj, bmap_path, image_size, dest_is_blkdev = \
copy_command_open_all(args, log)
try:
def parse_arguments():
"""A helper function which parses the input arguments."""
-
text = "Create block map (bmap) and copy files using bmap. The " \
"documentation can be found here: " \
"source.tizen.org/documentation/reference/bmaptool"
def main():
"""Script entry point."""
-
args = parse_arguments()
if args.quiet:
def _open_image_file(self):
"""Open the image file."""
-
try:
self._f_image = open(self._image_path, 'rb')
except IOError as err:
def _open_bmap_file(self):
"""Open the bmap file."""
-
try:
self._f_bmap = open(self._bmap_path, 'w+')
except IOError as err:
def __del__(self):
"""The class destructor which closes the opened files."""
-
if self._f_image_needs_close:
self._f_image.close()
if self._f_bmap_needs_close:
def human_size(size):
"""Transform size in bytes into a human-readable form."""
-
if size == 1:
return "1 byte"
def human_time(seconds):
"""Transform time in seconds to the HH:MM:SS format."""
-
(minutes, seconds) = divmod(seconds, 60)
(hours, minutes) = divmod(minutes, 60)
def _open_image_file(self):
"""Open the image file."""
-
try:
self._f_image = open(self._image_path, 'rb')
except IOError as err:
def __del__(self):
"""The class destructor which closes the opened files."""
-
if self._f_image_needs_close:
self._f_image.close()
def seek(self, offset, whence=os.SEEK_SET):
"""The 'seek()' method, similar to the one file objects have."""
-
self._pos = _fake_seek_forward(self, self._pos, offset, whence)
def tell(self):
"""The 'tell()' method, similar to the one file objects have."""
-
return self._pos
def _read_from_buffer(self, length):
"""Read from the internal buffer."""
-
buffer_len = len(self._buffer)
if buffer_len - self._buffer_pos > length:
data = self._buffer[self._buffer_pos:self._buffer_pos + length]
def _create_local_copy(self):
"""Create a local copy of a remote or compressed file."""
-
import tempfile
try:
def __del__(self):
"""The class destructor which closes opened files."""
-
if self._transfile_obj:
self._transfile_obj.close()
if self._file_obj:
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, \
offset, whence)
def tell(self):
"""The 'tell()' method, similar to the one file objects have."""
-
if self._force_fake_seek or not hasattr(self._transfile_obj, "tell"):
return self._pos
else:
def close(self):
"""Close the file-like object."""
-
self.__del__()
def __getattr__(self, name):