Debian Codegraph @

check-dependencies.py

raw
1 #!/usr/bin/env python3
2
3 import os
4 import sys
5 from dataclasses import dataclass
6 from typing import List, Optional
7
8 @dataclass
9 class Dependency:
10 name: str
11 depType: str # screen, input, sound, speech, core
12 moduleName: str
13 checkCommands: Optional[List[str]] = None # Command-line tools to check
14 pythonImports: Optional[List[str]] = None # Python packages to check
15 devicePaths: Optional[List[str]] = None # Device files to check
16
17 def check_dependency(dep: Dependency) -> bool:
18 """Check if a single dependency is satisfied."""
19 isAvailable = True
20
21 if dep.pythonImports:
22 for package in dep.pythonImports:
23 try:
24 moduleName = package.split('.')[0]
25 __import__(moduleName)
26 print(f'{package}: OK')
27 except ImportError:
28 print(f'{package}: FAIL')
29 isAvailable = False
30
31 if dep.checkCommands:
32 for cmd in dep.checkCommands:
33 if os.path.exists(f'/usr/bin/{cmd}') or os.path.exists(f'/bin/{cmd}'):
34 print(f'{cmd}: OK')
35 else:
36 print(f'{cmd}: FAIL')
37 isAvailable = False
38
39 if dep.devicePaths:
40 for path in dep.devicePaths:
41 if os.path.exists(path):
42 print(f'{path}: OK')
43 else:
44 print(f'{path}: FAIL')
45 isAvailable = False
46
47 return isAvailable
48
49 # Define all dependencies
50 dependencyList = [
51 # Core dependencies
52 Dependency('FenrirCore', 'core', 'core',
53 pythonImports=[
54 'daemonize',
55 'enchant',
56 'pyperclip',
57 'setproctitle',
58 'xdg'
59 ]),
60
61 # Screen drivers
62 Dependency('DummyScreen', 'screen', 'dummyDriver'),
63 Dependency('VCSA', 'screen', 'vcsaDriver',
64 pythonImports=['dbus'],
65 devicePaths=['/dev/vcsa']),
66 Dependency('PTY', 'screen', 'ptyDriver',
67 pythonImports=['pyte']),
68
69 # Input drivers
70 Dependency('DummyInput', 'input', 'dummyDriver'),
71 Dependency('DebugInput', 'input', 'debugDriver'),
72 Dependency('Evdev', 'input', 'evdevDriver',
73 pythonImports=['evdev', 'evdev.InputDevice', 'evdev.UInput', 'pyudev']),
74 # Sound drivers
75 Dependency('DummySound', 'sound', 'dummyDriver'),
76 Dependency('DebugSound', 'sound', 'debugDriver'),
77 Dependency('GenericSound', 'sound', 'genericDriver',
78 checkCommands=['play', 'sox']),
79 Dependency('GStreamer', 'sound', 'gstreamerDriver',
80 pythonImports=['gi', 'gi.repository.GLib', 'gi.repository.Gst']),
81
82 # Speech drivers
83 Dependency('DummySpeech', 'speech', 'dummyDriver'),
84 Dependency('DebugSpeech', 'speech', 'debugDriver'),
85 Dependency('Speechd', 'speech', 'speechdDriver',
86 pythonImports=['speechd']),
87 Dependency('GenericSpeech', 'speech', 'genericDriver',
88 checkCommands=['espeak-ng'])
89 ]
90
91 defaultModules = {
92 'FenrirCore',
93 'VCSA',
94 'Evdev',
95 'GenericSpeech',
96 'GenericSound'
97 }
98
99 def check_all_dependencies():
100 print('Checking dependencies...\n')
101 availableModules = []
102
103 # Group dependencies by type for organized output
104 for depType in ['core', 'screen', 'input', 'sound', 'speech']:
105 print(f'{depType.upper()} DRIVERS')
106 print('-' * 20)
107
108 depsOfType = [d for d in dependencyList if d.depType == depType]
109 for dep in depsOfType:
110 print(f'\nChecking {dep.name}:')
111 if check_dependency(dep):
112 availableModules.append(dep.name)
113 print('')
114
115 print_summary(availableModules)
116
117 def print_summary(availableModules: List[str]):
118 print('=' * 20)
119 print('SUMMARY')
120 print('=' * 20)
121
122 missingModules = defaultModules - set(availableModules)
123 if missingModules:
124 print('Default Setup: FAIL')
125 print('\nUnavailable Default Modules:')
126 for module in missingModules:
127 print(f'- {module}')
128 print('\nYou may need to install the missing dependencies for the modules above or reconfigure fenrir to not use them.')
129 else:
130 print('Default Setup: OK')
131
132 print('\nAvailable Modules:')
133 for module in availableModules:
134 print(f'- {module}')
135
136 if __name__ == '__main__':
137 check_all_dependencies()