mirror of
https://github.com/ARM-software/devlib.git
synced 2025-04-17 15:20:03 +01:00
target: Add dry run for command execution
It sometimes can be useful to enable dry-run before calling high-level functions in order to check what individual commands are being called (or do whatever else with them). This patch adds dry-run with an on/off switch: once start_dryrun() is called, every subsequent command passed to execute() will be accumulated in a list. stop_dryrun() disables dry-run, and the accumulated commands can be fetched via Target.dryrun
This commit is contained in:
parent
1f7421bc39
commit
1a5c1dce07
@ -145,6 +145,10 @@ class Target(object):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dryrun(self):
|
||||||
|
return self._dryrun
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
connection_settings=None,
|
connection_settings=None,
|
||||||
platform=None,
|
platform=None,
|
||||||
@ -186,6 +190,8 @@ class Target(object):
|
|||||||
self._cache = {}
|
self._cache = {}
|
||||||
self._connections = {}
|
self._connections = {}
|
||||||
self.busybox = None
|
self.busybox = None
|
||||||
|
self._dryrun_enabled = False
|
||||||
|
self._dryrun = []
|
||||||
|
|
||||||
if load_default_modules:
|
if load_default_modules:
|
||||||
module_lists = [self.default_modules]
|
module_lists = [self.default_modules]
|
||||||
@ -311,7 +317,19 @@ class Target(object):
|
|||||||
|
|
||||||
# execution
|
# execution
|
||||||
|
|
||||||
|
def start_dryrun(self):
|
||||||
|
if not self._dryrun_enabled:
|
||||||
|
self._dryrun_enabled = True
|
||||||
|
self._dryrun = []
|
||||||
|
|
||||||
|
def stop_dryrun(self):
|
||||||
|
if self._dryrun_enabled:
|
||||||
|
self._dryrun_enabled = False
|
||||||
|
|
||||||
def execute(self, command, timeout=None, check_exit_code=True, as_root=False):
|
def execute(self, command, timeout=None, check_exit_code=True, as_root=False):
|
||||||
|
if self._dryrun_enabled:
|
||||||
|
self._dryrun.append(command)
|
||||||
|
else:
|
||||||
return self.conn.execute(command, timeout, check_exit_code, as_root)
|
return self.conn.execute(command, timeout, check_exit_code, as_root)
|
||||||
|
|
||||||
def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False):
|
def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user