Automatically stash local changes, pull updates, and drop the temporary stash.
()
| 9876 | |
| 9877 | def _get_active_ethernet_name(): |
| 9878 | """Get the name of the active ethernet interface, or empty string.""" |
| 9879 | try: |
| 9880 | iface = get_active_ethernet_interface() |
| 9881 | return iface.get('name', '') if iface else '' |
| 9882 | except Exception: |
| 9883 | return '' |
| 9884 | |
| 9885 | def get_current_wifi_ssid(): |
| 9886 | """Get the current WiFi SSID for file naming""" |
| 9887 | global _wifi_ssid_cache |
| 9888 | |
| 9889 | current_timestamp = time.time() |
| 9890 | if _wifi_ssid_cache['ssid'] and (current_timestamp - _wifi_ssid_cache['timestamp']) < _WIFI_SSID_CACHE_TTL: |
| 9891 | return _wifi_ssid_cache['ssid'] |
| 9892 | |
| 9893 | try: |
| 9894 | if hasattr(shared_data, 'wifi_manager') and getattr(shared_data, 'wifi_manager', None): |
| 9895 | wifi_manager = getattr(shared_data, 'wifi_manager') |
| 9896 | ssid = wifi_manager.get_current_ssid() |
| 9897 | if ssid: |
| 9898 | # Sanitize SSID for filename |
| 9899 | sanitized = re.sub(r'[^\w\-_]', '_', ssid) |
| 9900 | _wifi_ssid_cache['ssid'] = sanitized |
| 9901 | _wifi_ssid_cache['timestamp'] = current_timestamp |
| 9902 | return sanitized |
| 9903 | |
| 9904 | # Fallback to direct system command |
| 9905 | result = subprocess.run(['nmcli', '-t', '-f', 'ACTIVE,SSID', 'dev', 'wifi'], |
| 9906 | capture_output=True, text=True, timeout=10) |
| 9907 | if result.returncode == 0: |
| 9908 | for line in result.stdout.strip().split('\n'): |
| 9909 | if line.startswith('yes:'): |
| 9910 | ssid = line.split(':', 1)[1] |
| 9911 | if ssid: |
| 9912 | # Sanitize SSID for filename |
| 9913 | sanitized = re.sub(r'[^\w\-_]', '_', ssid) |
| 9914 | _wifi_ssid_cache['ssid'] = sanitized |
| 9915 | _wifi_ssid_cache['timestamp'] = current_timestamp |
| 9916 | return sanitized |
| 9917 | |
| 9918 | # Cache the default value too |
| 9919 | _wifi_ssid_cache['ssid'] = "unknown_network" |
| 9920 | _wifi_ssid_cache['timestamp'] = current_timestamp |
| 9921 | return "unknown_network" |
| 9922 | except Exception as e: |
| 9923 | logger.debug(f"Error getting current WiFi SSID: {e}") |
| 9924 | # Cache the error result |
| 9925 | _wifi_ssid_cache['ssid'] = "unknown_network" |
| 9926 | _wifi_ssid_cache['timestamp'] = current_timestamp |
| 9927 | return "unknown_network" |
| 9928 | |
| 9929 | |
| 9930 | def get_wifi_specific_network_file(): |
| 9931 | """Get the WiFi-specific network data file path""" |
| 9932 | current_ssid = get_current_wifi_ssid() |
| 9933 | data_dir = os.path.join('data', 'network_data') |
| 9934 | os.makedirs(data_dir, exist_ok=True) |
| 9935 | return os.path.join(data_dir, f'network_{current_ssid}.csv') |
nothing calls this directly
no test coverage detected