Helper function to run gsettings command and return cleaned string output.
(command_parts: List[str])
| 202 | """ |
| 203 | |
| 204 | def _run_gsettings_command(command_parts: List[str]) -> Optional[str]: |
| 205 | """Helper function to run gsettings command and return cleaned string output.""" |
| 206 | try: |
| 207 | process_result = subprocess.run( |
| 208 | command_parts, |
| 209 | capture_output=True, |
| 210 | text=True, |
| 211 | check=False, # Do not raise CalledProcessError for non-zero exit codes |
| 212 | timeout=1, # Timeout for the subprocess call |
| 213 | ) |
| 214 | if process_result.returncode == 0: |
| 215 | value = process_result.stdout.strip() |
| 216 | if value.startswith("'") and value.endswith( |
| 217 | "'" |
| 218 | ): # Remove surrounding single quotes |
| 219 | value = value[1:-1] |
| 220 | |
| 221 | # If after stripping quotes, value is empty, or it's a gsettings "empty" representation |
| 222 | if not value or value == "''" or value == "@as []" or value == "[]": |
| 223 | return None |
| 224 | return value |
| 225 | else: |
| 226 | return None |
| 227 | except subprocess.TimeoutExpired: |
| 228 | return None |
| 229 | except Exception: # Broad exception as per pseudocode |
| 230 | return None |
| 231 | |
| 232 | proxy_mode = _run_gsettings_command( |
| 233 | ["gsettings", "get", "org.gnome.system.proxy", "mode"] |
no test coverage detected