Skip to content

Commit f3d6a42

Browse files
committed
Add in more progress calls.
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
1 parent 0149e04 commit f3d6a42

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

pycdlib/pycdlib.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,7 @@ def _outfp_write_with_check(self, outfp, data, enable_overwrite_check=True):
25632563
bisect.insort_left(self._write_check_list, self._WriteRange(start, end - 1))
25642564

25652565
def _output_file_data(self, outfp, blocksize, ino):
2566-
# type: (BinaryIO, int, inode.Inode) -> int
2566+
# type: (BinaryIO, int, inode.Inode) -> Generator
25672567
"""
25682568
Internal method to write a directory record entry out.
25692569
@@ -2575,25 +2575,25 @@ def _output_file_data(self, outfp, blocksize, ino):
25752575
The total number of bytes written out.
25762576
"""
25772577
outfp.seek(ino.extent_location() * self.logical_block_size)
2578-
tmp_start = outfp.tell()
2578+
start_offset = outfp.tell()
25792579
with inode.InodeOpenData(ino, self.logical_block_size) as (data_fp, data_len):
2580-
utils.copy_data(data_len, blocksize, data_fp, outfp)
2581-
utils.zero_pad(outfp, data_len, self.logical_block_size)
2580+
for len_copied in utils.copy_data_yield(data_len, blocksize, data_fp, outfp):
2581+
yield len_copied
2582+
yield utils.zero_pad(outfp, data_len, self.logical_block_size)
25822583

25832584
if self._track_writes:
25842585
end = outfp.tell()
25852586
bisect.insort_left(self._write_check_list,
2586-
self._WriteRange(tmp_start, end - 1))
2587+
self._WriteRange(start_offset, end - 1))
25872588

25882589
# If this file is being used as a bootfile, and a boot info table is
25892590
# present, patch the boot info table into offset 8 here.
25902591
if ino.boot_info_table is not None:
25912592
old = outfp.tell()
2592-
outfp.seek(tmp_start + 8)
2593-
self._outfp_write_with_check(outfp, ino.boot_info_table.record(),
2594-
enable_overwrite_check=False)
2593+
outfp.seek(start_offset + 8)
2594+
rec = ino.boot_info_table.record()
2595+
self._outfp_write_with_check(outfp, rec, enable_overwrite_check=False)
25952596
outfp.seek(old)
2596-
return outfp.tell() - tmp_start
25972597

25982598
class _Progress(object):
25992599
"""
@@ -2939,7 +2939,8 @@ def func(done, total, progress_data).
29392939
# file out of the original, so do that here.
29402940
for ino in self.inodes:
29412941
if ino.get_data_length() > 0:
2942-
progress.call(self._output_file_data(outfp, blocksize, ino))
2942+
for len_copied in self._output_file_data(outfp, blocksize, ino):
2943+
progress.call(len_copied)
29432944

29442945
# Pad out to the total size of the disk, in case that the last thing
29452946
# written is shorter than a full logical block size. Not all file-like
@@ -4494,8 +4495,7 @@ def modify_file_in_place(self, fp, length, iso_path, rr_name=None, # pylint: di
44944495
# Write out the actual file contents.
44954496
self._seek_to_extent(child.extent_location())
44964497
with inode.InodeOpenData(child.inode, self.logical_block_size) as (data_fp, data_len):
4497-
utils.copy_data(data_len, self.logical_block_size, data_fp,
4498-
self._cdfp)
4498+
utils.copy_data(data_len, self.logical_block_size, data_fp, self._cdfp)
44994499
utils.zero_pad(self._cdfp, data_len, self.logical_block_size)
45004500

45014501
# Finally write out the directory record entry.

pycdlib/utils.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
# For mypy annotations
4747
if False: # pylint: disable=using-constant-test
48-
from typing import BinaryIO, List, Optional, Tuple # NOQA pylint: disable=unused-import
48+
from typing import BinaryIO, Generator, List, Optional, Tuple # NOQA pylint: disable=unused-import
4949

5050

5151
def swab_32bit(x):
@@ -98,8 +98,8 @@ def ceiling_div(numer, denom):
9898
return -(-numer // denom)
9999

100100

101-
def copy_data(data_length, blocksize, infp, outfp):
102-
# type: (int, int, BinaryIO, BinaryIO) -> None
101+
def copy_data_yield(data_length, blocksize, infp, outfp):
102+
# type: (int, int, BinaryIO, BinaryIO) -> Generator
103103
"""
104104
A utility function to copy data from the input file object to the output
105105
file object.
@@ -127,6 +127,25 @@ def copy_data(data_length, blocksize, infp, outfp):
127127
data_len = left
128128
outfp.write(data)
129129
left -= data_len
130+
yield data_len
131+
132+
133+
def copy_data(data_length, blocksize, infp, outfp):
134+
# type: (int, int, BinaryIO, BinaryIO) -> None
135+
"""
136+
A utility function to copy data from the input file object to the output
137+
file object.
138+
139+
Parameters:
140+
data_length - The amount of data to copy.
141+
blocksize - How much data to copy per iteration.
142+
infp - The file object to copy data from.
143+
outfp - The file object to copy data to.
144+
Returns:
145+
Nothing.
146+
"""
147+
for len_unused in copy_data_yield(data_length, blocksize, infp, outfp):
148+
pass
130149

131150

132151
def encode_space_pad(instr, length, encoding):
@@ -230,7 +249,7 @@ def gmtoffset_from_tm(tm, localtime):
230249

231250

232251
def zero_pad(fp, data_size, pad_size):
233-
# type: (BinaryIO, int, int) -> None
252+
# type: (BinaryIO, int, int) -> int
234253
"""
235254
A function to write padding out from data_size up to pad_size
236255
efficiently.
@@ -240,15 +259,16 @@ def zero_pad(fp, data_size, pad_size):
240259
data_size - The current size of the data.
241260
pad_size - The boundary size of data to pad out to.
242261
Returns:
243-
Nothing.
262+
The number of bytes that were padded.
244263
"""
245264
padbytes = pad_size - (data_size % pad_size)
246265
if padbytes == pad_size:
247266
# Nothing to pad, get out.
248-
return
267+
return 0
249268

250269
fp.seek(padbytes - 1, os.SEEK_CUR)
251270
fp.write(b'\x00')
271+
return padbytes - 1
252272

253273

254274
def starts_with_slash(path):

tests/integration/test_parse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ def _progress(done, total):
10601060
iso.open(str(outfile))
10611061
iso.write(str(tmpdir.join('writetest.iso')), progress_cb=_progress)
10621062

1063-
assert(test_parse_write_with_progress.num_progress_calls == 14)
1063+
assert(test_parse_write_with_progress.num_progress_calls == 16)
10641064
assert(test_parse_write_with_progress.done == 73728)
10651065

10661066
iso.close()
@@ -1087,7 +1087,7 @@ def _progress(done, total, opaque):
10871087
collect = {'num_calls': 0, 'done': 0}
10881088
iso.write(str(tmpdir.join('writetest.iso')), progress_cb=_progress, progress_opaque=collect)
10891089

1090-
assert(collect['num_calls'] == 14)
1090+
assert(collect['num_calls'] == 16)
10911091
assert(collect['done'] == 73728)
10921092

10931093
iso.close()

tools/pycdlib-genisoimage

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,9 @@ def main():
913913
PyCdlib object, and prints out the current progress of the mastering.
914914
915915
Parameters (as prescribed by PyCdlib):
916-
done - The amount of data written so far
917-
total - The total amount of data to write
918-
progress_data - An object of type ProgressData to track progress
916+
done - The amount of data written so far in bytes.
917+
total - The total amount of data to write in bytes.
918+
progress_data - An object of type ProgressData to track progress.
919919
Returns:
920920
Nothing.
921921
"""

0 commit comments

Comments
 (0)