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

Commit

Permalink
Merge pull request #63 from agherzan/psplash
Browse files Browse the repository at this point in the history
bmaptool: Implement flag to interact with psplash progress
  • Loading branch information
dedekind authored Oct 20, 2020
2 parents 81d3cc1 + 81958f7 commit 1c48e2b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions bmaptools/BmapCopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def __init__(self, image, dest, bmap=None, image_size=None):
self._progress_file = None
self._progress_format = None
self.set_progress_indicator(None, None)
self._psplash_pipe = None

self._f_image = image
self._image_path = image.name
Expand Down Expand Up @@ -211,6 +212,28 @@ def __init__(self, image, dest, bmap=None, image_size=None):

self._batch_blocks = self._batch_bytes // self.block_size

def set_psplash_pipe(self, path):
"""
Set the psplash named pipe file path to be used when updating the
progress - best effort.
The 'path' argument is the named pipe used by the psplash process to get
progress bar commands. When the path argument doesn't exist or is not a
pipe, the function will ignore with a warning. This behavior is
considered as such because the progress is considered a decoration
functionality which might or might not be available even if requested.
When used as a boot service, the unavailability of the psplash service
(due to various reasons: no screen, racing issues etc.) should not
break the writting process. This is why this implementation is done as
a best effort.
"""

if os.path.exists(pipe) and stat.S_ISFIFO(os.stat(pipe).st_mode):
self._psplash_pipe = pipe
else:
_log.warning("'%s' is not a pipe, so psplash progress will not be "
"updated" % pipe)

def set_progress_indicator(self, file_obj, format_string):
"""
Setup the progress indicator which shows how much data has been copied
Expand Down Expand Up @@ -404,6 +427,17 @@ def _update_progress(self, blocks_written):
self._progress_file.write(progress)
self._progress_file.flush()

# Update psplash progress when configured. This is using a best effort
# strategy to not affect the writing process when psplash breaks, is
# not available early enough or screen is not available.
if self._psplash_pipe and self.mapped_cnt:
try:
mode = os.O_WRONLY | os.O_NONBLOCK
with os.fdopen(os.open(self._psplash_pipe, mode), 'w') as p_fo:
p_fo.write("PROGRESS %d\n" % percent)
except:
pass

def _get_block_ranges(self):
"""
This is a helper generator that parses the bmap XML file and for each
Expand Down
7 changes: 7 additions & 0 deletions bmaptools/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ def copy_command(args):
% (os.path.basename(args.image), dest_str,
os.path.basename(bmap_path)))

if args.psplash_pipe:
writer.set_psplash_pipe(args.psplash_pipe)

try:
try:
writer.copy(False, not args.no_verify)
Expand Down Expand Up @@ -640,6 +643,10 @@ def parse_arguments():
text = "do not verify the data checksum while writing"
parser_copy.add_argument("--no-verify", action="store_true", help=text)

# The --psplash-pipe option
text = "write progress to a psplash pipe"
parser_copy.add_argument("--psplash-pipe", help=text)

return parser.parse_args()


Expand Down

0 comments on commit 1c48e2b

Please sign in to comment.