implement: dont return command output by default
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								e715dbb801
							
						
					
				
			
			
				commit
				
					
						ab1d3d16f1
					
				
			
		
					 1 changed files with 10 additions and 4 deletions
				
			
		|  | @ -87,7 +87,7 @@ class Local(object): | ||||||
|         # FIXME: dont set mode here, fix unittest mkdtemp instead |         # FIXME: dont set mode here, fix unittest mkdtemp instead | ||||||
|         os.makedirs(path, mode=0o700, exist_ok=True) |         os.makedirs(path, mode=0o700, exist_ok=True) | ||||||
| 
 | 
 | ||||||
|     def run(self, command, env=None): |     def run(self, command, env=None, return_output=False): | ||||||
|         """Run the given command with the given environment. |         """Run the given command with the given environment. | ||||||
|         Return the output as a string. |         Return the output as a string. | ||||||
| 
 | 
 | ||||||
|  | @ -95,13 +95,16 @@ class Local(object): | ||||||
|         assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command |         assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command | ||||||
|         self.log.debug("Local run: %s", command) |         self.log.debug("Local run: %s", command) | ||||||
|         try: |         try: | ||||||
|  |             if return_output: | ||||||
|                 return subprocess.check_output(command, env=env).decode() |                 return subprocess.check_output(command, env=env).decode() | ||||||
|  |             else: | ||||||
|  |                 subprocess.check_call(command, env=env) | ||||||
|         except subprocess.CalledProcessError: |         except subprocess.CalledProcessError: | ||||||
|             raise cdist.Error("Command failed: " + " ".join(command)) |             raise cdist.Error("Command failed: " + " ".join(command)) | ||||||
|         except OSError as error: |         except OSError as error: | ||||||
|             raise cdist.Error(" ".join(*args) + ": " + error.args[1]) |             raise cdist.Error(" ".join(*args) + ": " + error.args[1]) | ||||||
| 
 | 
 | ||||||
|     def run_script(self, script, env=None): |     def run_script(self, script, env=None, return_output=False): | ||||||
|         """Run the given script with the given environment. |         """Run the given script with the given environment. | ||||||
|         Return the output as a string. |         Return the output as a string. | ||||||
| 
 | 
 | ||||||
|  | @ -114,7 +117,10 @@ class Local(object): | ||||||
|             self.log.debug("Local run script env: %s", env) |             self.log.debug("Local run script env: %s", env) | ||||||
|          |          | ||||||
|         try: |         try: | ||||||
|  |             if return_output: | ||||||
|                 return subprocess.check_output(command, env=env).decode() |                 return subprocess.check_output(command, env=env).decode() | ||||||
|  |             else: | ||||||
|  |                 subprocess.check_call(command, env=env) | ||||||
|         except subprocess.CalledProcessError as error: |         except subprocess.CalledProcessError as error: | ||||||
|             script_content = self.run(["cat", script]) |             script_content = self.run(["cat", script]) | ||||||
|             self.log.error("Code that raised the error:\n%s", script_content) |             self.log.error("Code that raised the error:\n%s", script_content) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue