DRYer: Get hostname

This commit is contained in:
pagedown
2022-11-26 15:28:32 +08:00
parent 63a08dc6cc
commit 6a1b456bac
4 changed files with 20 additions and 15 deletions

View File

@@ -595,6 +595,14 @@ def natsort_ints(iterable: Iterable[str]) -> List[str]:
return sorted(iterable, key=alphanum_key)
def get_hostname(fallback: str = '') -> str:
import socket
try:
return socket.gethostname() or fallback
except Exception:
return fallback
def resolve_editor_cmd(editor: str, shell_env: Mapping[str, str]) -> Optional[str]:
import shlex
editor_cmd = shlex.split(editor)