MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / safe_run_command

Function safe_run_command

scripts/python_ui/streamlit.py:141–165  ·  view source on GitHub ↗

Safely run a command with retries.

(command: List[str], retry: bool = True)

Source from the content-addressed store, hash-verified

139
140
141def safe_run_command(command: List[str], retry: bool = True) -> Tuple[bool, str, str]:
142 """Safely run a command with retries."""
143 cmd_str = " ".join(command)
144 logger.info(f"Executing command: {cmd_str}")
145
146 for attempt in range(MAX_RETRIES if retry else 1):
147 try:
148 logger.debug(f"Attempt {attempt + 1}/{MAX_RETRIES if retry else 1}")
149 result = run(command, capture_output=True, text=True)
150 if result.returncode == 0:
151 logger.debug("Command executed successfully")
152 return True, result.stdout, ""
153 if attempt == MAX_RETRIES - 1 or not retry:
154 logger.error(
155 f"Command failed with return code {result.returncode}: {result.stderr}"
156 )
157 return False, "", result.stderr
158 except Exception as e:
159 if attempt == MAX_RETRIES - 1 or not retry:
160 logger.error(f"Command execution failed: {str(e)}")
161 return False, "", str(e)
162 logger.debug(f"Retrying in {RETRY_DELAY} seconds...")
163 time.sleep(RETRY_DELAY)
164 logger.error("Max retries exceeded")
165 return False, "", "Max retries exceeded"
166
167
168def fetch_models_once() -> Dict[str, List[str]]:

Callers 1

fetch_models_onceFunction · 0.85

Calls 1

runFunction · 0.85

Tested by

no test coverage detected