Skip to content

Commit

Permalink
flashscriptdriver: Add cleanup
Browse files Browse the repository at this point in the history
Adds a cleanup parameter to the flashscriptdriver that removes the file
when flashing is complete

Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
  • Loading branch information
JoshuaWatt committed Apr 5, 2023
1 parent 4f5a7e9 commit 69bca20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Release 23.0 (unreleased)

- `ManagedFile` now has the ability to remove the file from the remote exporter
when longer needed
- `FlashScriptDriver` now has the ability to remote the flash script from the
remote exporter when flashing is complete

New Features in 23.0
~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2583,6 +2583,8 @@ Arguments:
- script (str): optional, key in :ref:`images <labgrid-device-config-images>`
containing the script to execute for writing of the flashable device
- args (list of str): optional, list of arguments for flash script execution
- cleanup (bool): optional, remove flash script from remote exporter after
flashing.

The FlashScriptDriver allows running arbitrary programs to flash a device.
Some SoC or devices may require custom, one-off, or proprietary programs to
Expand Down
22 changes: 14 additions & 8 deletions labgrid/driver/flashscriptdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class FlashScriptDriver(Driver):
default=attr.Factory(list),
validator=attr.validators.optional(attr.validators.instance_of(list)),
)
cleanup = attr.ib(
default=False,
validator=attr.validators.optional(attr.validators.instance_of(bool)),
)

def __attrs_post_init__(self):
super().__attrs_post_init__()
Expand All @@ -39,7 +43,7 @@ def on_deactivate(self):

@Driver.check_active
@step(args=["script"])
def flash(self, script=None, args=None):
def flash(self, script=None, args=None, cleanup=None):
"""
Transfers and remotely executes the script
Expand All @@ -50,15 +54,17 @@ def flash(self, script=None, args=None):
script = self.target.env.config.get_image_path(self.script)
assert script, "flash requires a script"

if cleanup is None:
cleanup = self.cleanup

if args is None:
args = self.args

mf = ManagedFile(script, self.device)
mf.sync_to_resource()

cmd = [mf.get_remote_path()] + [a.format(device=self.device, file=mf) for a in args]
with mf.remote_path(cleanup=cleanup) as path:
cmd = [path] + [a.format(device=self.device, file=mf) for a in args]

self.logger.debug("Running command '%s'", " ".join(cmd))
processwrapper.check_output(
self.device.command_prefix + cmd, print_on_silent_log=True
)
self.logger.debug("Running command '%s'", " ".join(cmd))
processwrapper.check_output(
self.device.command_prefix + cmd, print_on_silent_log=True
)

0 comments on commit 69bca20

Please sign in to comment.