mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-11-04 07:51:21 +00: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:
		@@ -145,6 +145,10 @@ class Target(object):
 | 
			
		||||
        else:
 | 
			
		||||
            return None
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def dryrun(self):
 | 
			
		||||
        return self._dryrun
 | 
			
		||||
 | 
			
		||||
    def __init__(self,
 | 
			
		||||
                 connection_settings=None,
 | 
			
		||||
                 platform=None,
 | 
			
		||||
@@ -186,6 +190,8 @@ class Target(object):
 | 
			
		||||
        self._cache = {}
 | 
			
		||||
        self._connections = {}
 | 
			
		||||
        self.busybox = None
 | 
			
		||||
        self._dryrun_enabled = False
 | 
			
		||||
        self._dryrun = []
 | 
			
		||||
 | 
			
		||||
        if load_default_modules:
 | 
			
		||||
            module_lists = [self.default_modules]
 | 
			
		||||
@@ -311,8 +317,20 @@ class Target(object):
 | 
			
		||||
 | 
			
		||||
    # 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):
 | 
			
		||||
        return self.conn.execute(command, timeout, check_exit_code, as_root)
 | 
			
		||||
        if self._dryrun_enabled:
 | 
			
		||||
            self._dryrun.append(command)
 | 
			
		||||
        else:
 | 
			
		||||
            return self.conn.execute(command, timeout, check_exit_code, as_root)
 | 
			
		||||
 | 
			
		||||
    def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False):
 | 
			
		||||
        return self.conn.background(command, stdout, stderr, as_root)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user