Coverage for src/jtech_installer/detector/system.py: 87%

38 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-08-20 15:10 -0300

1""" 

2System detection module for JTECH™ Installer 

3""" 

4 

5import platform 

6import subprocess 

7import sys 

8from pathlib import Path 

9 

10from jtech_installer.core.models import OSType, SystemInfo 

11 

12 

13class SystemDetector: 

14 """Detecta informações do sistema operacional""" 

15 

16 def detect(self) -> SystemInfo: 

17 """Detecta todas as informações do sistema""" 

18 return SystemInfo( 

19 os_type=self._detect_os(), 

20 python_version=self._get_python_version(), 

21 git_available=self._check_git(), 

22 vscode_available=self._check_vscode(), 

23 current_directory=Path.cwd(), 

24 architecture=self._get_architecture(), 

25 ) 

26 

27 def _detect_os(self) -> OSType: 

28 """Detecta o sistema operacional""" 

29 system = platform.system().lower() 

30 if system == "linux": 

31 return OSType.LINUX 

32 elif system == "darwin": 

33 return OSType.MACOS 

34 elif system == "windows": 

35 return OSType.WINDOWS 

36 else: 

37 raise ValueError(f"Sistema operacional não suportado: {system}") 

38 

39 def _get_python_version(self) -> str: 

40 """Obtém a versão do Python""" 

41 return f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" 

42 

43 def _get_architecture(self) -> str: 

44 """Detecta a arquitetura do sistema""" 

45 arch = platform.machine().lower() 

46 if arch in ["x86_64", "amd64"]: 

47 return "x64" 

48 elif arch in ["arm64", "aarch64"]: 

49 return "arm64" 

50 else: 

51 return arch 

52 

53 def _check_git(self) -> bool: 

54 """Verifica se Git está disponível""" 

55 try: 

56 subprocess.run( 

57 ["git", "--version"], 

58 check=True, 

59 capture_output=True, 

60 text=True, 

61 ) 

62 return True 

63 except (subprocess.CalledProcessError, FileNotFoundError): 

64 return False 

65 

66 def _check_vscode(self) -> bool: 

67 """Verifica se VS Code está disponível""" 

68 try: 

69 subprocess.run( 

70 ["code", "--version"], 

71 check=True, 

72 capture_output=True, 

73 text=True, 

74 ) 

75 return True 

76 except (subprocess.CalledProcessError, FileNotFoundError): 

77 return False