mirror of
				https://github.com/HorlogeSkynet/archey4
				synced 2025-10-30 08:00:14 +01:00 
			
		
		
		
	 121b1cc796
			
		
	
	121b1cc796
	
	
	
		
			
			Co-authored-by: Michael Bromilow <12384431+ingrinder@users.noreply.github.com> Co-authored-by: Samuel FORESTIER <samuel+dev@forestier.app>
		
			
				
	
	
		
			28 lines
		
	
	
		
			732 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			732 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| """Host-name detection class"""
 | |
| 
 | |
| import platform
 | |
| from typing import Optional
 | |
| 
 | |
| from archey.entry import Entry
 | |
| 
 | |
| 
 | |
| class Hostname(Entry):
 | |
|     """Read system file with fallback on `platform` module to retrieve the system host-name"""
 | |
| 
 | |
|     _ICON = "\U000f0318"  # md_lan_connect
 | |
| 
 | |
|     def __init__(self, *args, **kwargs):
 | |
|         super().__init__(*args, **kwargs)
 | |
| 
 | |
|         self.value = self._read_etc_hostname()
 | |
|         if not self.value:
 | |
|             self.value = platform.node()
 | |
| 
 | |
|     @staticmethod
 | |
|     def _read_etc_hostname() -> Optional[str]:
 | |
|         try:
 | |
|             with open("/etc/hostname", encoding="UTF-8") as f_hostname:
 | |
|                 return f_hostname.read().rstrip()
 | |
|         except FileNotFoundError:
 | |
|             return None
 |