Indicates whether the current environment is a headless Linux server. The environment is considered a Linux server when: - the host platform is Linux and not mobile; - it is not Windows Subsystem for Linux (WSL); - the `DISPLAY` environment variable is not set. Returns:
()
| 112 | |
| 113 | |
| 114 | def is_linux_server(): |
| 115 | """ |
| 116 | Indicates whether the current environment is a headless Linux server. |
| 117 | |
| 118 | The environment is considered a Linux server when: |
| 119 | - the host platform is Linux and not mobile; |
| 120 | - it is not Windows Subsystem for Linux (WSL); |
| 121 | - the `DISPLAY` environment variable is not set. |
| 122 | |
| 123 | Returns: |
| 124 | `True` for headless Linux server environments, otherwise `False`. |
| 125 | """ |
| 126 | if not is_mobile() and platform.system() == "Linux": |
| 127 | # check if it's WSL |
| 128 | p = "/proc/version" |
| 129 | if os.path.exists(p): |
| 130 | with open(p, encoding="utf-8") as file: |
| 131 | if "microsoft" in file.read(): |
| 132 | return False # it's WSL, not a server |
| 133 | return os.environ.get("DISPLAY") is None |
| 134 | return False |
| 135 | |
| 136 | |
| 137 | def is_macos(): |