5
5
import logging
6
6
import subprocess
7
7
import shutil
8
- from typing import Optional , List , Dict , Set
8
+ from typing import Optional , List , Dict , Set , Tuple
9
9
10
10
import aw_core
11
11
@@ -35,7 +35,7 @@ def _is_system_module(name: str) -> bool:
35
35
return shutil .which (name ) is not None
36
36
37
37
38
- def _locate_executable (name : str ) -> Optional [str ]:
38
+ def _locate_executable (name : str ) -> Tuple [ Optional [str ], Optional [ str ] ]:
39
39
"""
40
40
Will return the path to the executable if bundled,
41
41
otherwise returns the name if it is available in PATH.
@@ -44,41 +44,38 @@ def _locate_executable(name: str) -> Optional[str]:
44
44
"""
45
45
exec_path = _locate_bundled_executable (name )
46
46
if exec_path is not None : # Check if it exists in bundle
47
- return exec_path
47
+ return exec_path , "bundle"
48
48
elif _is_system_module (name ): # Check if it's in PATH
49
- return name
49
+ return name , "system"
50
50
else :
51
51
logger .warning (
52
52
"Could not find module '{}' in installation directory or PATH" .format (name )
53
53
)
54
- return None
54
+ return None , None
55
55
56
56
57
- def _discover_modules_in_directory (modules : List [ str ], search_path : str ) -> None :
57
+ def _discover_modules_in_directory (search_path : str ) -> List [ str ] :
58
58
"""Look for modules in given directory path and recursively in subdirs matching aw-*"""
59
+ modules = []
59
60
matches = glob (os .path .join (search_path , "aw-*" ))
60
61
for match in matches :
61
62
if os .path .isfile (match ) and os .access (match , os .X_OK ):
62
63
name = os .path .basename (match )
63
64
modules .append (name )
64
65
elif os .path .isdir (match ) and os .access (match , os .X_OK ):
65
- _discover_modules_in_directory (modules , match )
66
+ modules . extend ( _discover_modules_in_directory (match ) )
66
67
else :
67
68
logger .warning (
68
69
"Found matching file but was not executable: {}" .format (match )
69
70
)
71
+ return modules
70
72
71
73
72
74
def _discover_modules_bundled () -> List [str ]:
73
75
"""Use ``_discover_modules_in_directory`` to find all bundled modules """
74
- modules : List [str ] = []
75
76
cwd = os .getcwd ()
76
- _discover_modules_in_directory (modules , cwd )
77
-
78
- if len (modules ) > 0 :
79
- logger .info ("Found bundled modules: {}" .format (set (modules )))
80
- else :
81
- logger .info ("Found no bundles modules" )
77
+ modules = _discover_modules_in_directory (cwd )
78
+ logger .info ("Found bundled modules: {}" .format (set (modules )))
82
79
return modules
83
80
84
81
@@ -90,7 +87,7 @@ def _discover_modules_system() -> List[str]:
90
87
if os .path .isdir (path ):
91
88
files = os .listdir (path )
92
89
for filename in files :
93
- if "aw-" in filename :
90
+ if filename . startswith ( "aw-" ) :
94
91
modules .append (filename )
95
92
96
93
logger .info ("Found system modules: {}" .format (set (modules )))
@@ -116,9 +113,10 @@ def start(self) -> None:
116
113
if platform .system () != "Windows" :
117
114
os .setpgrp ()
118
115
119
- exec_path = _locate_executable (self .name )
116
+ exec_path , location = _locate_executable (self .name )
120
117
if exec_path is None :
121
118
logger .error ("Tried to start nonexistent module {}" .format (self .name ))
119
+ return
122
120
else :
123
121
exec_cmd = [exec_path ]
124
122
if self .testing :
@@ -132,7 +130,7 @@ def start(self) -> None:
132
130
startupinfo = subprocess .STARTUPINFO () # type: ignore
133
131
startupinfo .dwFlags |= subprocess .STARTF_USESHOWWINDOW # type: ignore
134
132
elif platform .system () == "Darwin" :
135
- logger .info ("Macos : Disable dock icon" )
133
+ logger .info ("macOS : Disable dock icon" )
136
134
import AppKit
137
135
138
136
AppKit .NSBundle .mainBundle ().infoDictionary ()["LSBackgroundOnly" ] = "1"
@@ -200,9 +198,7 @@ def read_log(self) -> str:
200
198
201
199
class Manager :
202
200
def __init__ (self , testing : bool = False ) -> None :
203
- self .settings : AwQtSettings = AwQtSettings (testing )
204
201
self .modules : Dict [str , Module ] = {}
205
- self .autostart_modules : Set [str ] = set (self .settings .autostart_modules )
206
202
self .testing = testing
207
203
208
204
self .discover_modules ()
@@ -211,7 +207,7 @@ def discover_modules(self) -> None:
211
207
# These should always be bundled with aw-qt
212
208
found_modules = set (_discover_modules_bundled ())
213
209
found_modules |= set (_discover_modules_system ())
214
- found_modules ^= {"aw-qt" } # Exclude self
210
+ found_modules ^= {"aw-qt" , "aw-client" } # Exclude self
215
211
216
212
for m_name in found_modules :
217
213
if m_name not in self .modules :
@@ -230,26 +226,26 @@ def start(self, module_name: str) -> None:
230
226
"Manager tried to start nonexistent module {}" .format (module_name )
231
227
)
232
228
233
- def autostart (self , autostart_modules : Optional [List [str ]]) -> None :
234
- if autostart_modules is None :
235
- autostart_modules = []
236
- if len (autostart_modules ) > 0 :
237
- logger .info (
238
- "Modules to start weren't specified in CLI arguments. Falling back to configuration."
239
- )
240
- autostart_modules = self .settings .autostart_modules
229
+ def autostart (self , autostart_modules : List [str ]) -> None :
241
230
# We only want to autostart modules that are both in found modules and are asked to autostart.
242
- modules_to_start = set (autostart_modules ).intersection (set (self .modules .keys ()))
231
+ not_found = []
232
+ for name in autostart_modules :
233
+ if name not in self .modules .keys ():
234
+ logger .error (f"Module { name } not found" )
235
+ not_found .append (name )
236
+ autostart_modules = list (set (autostart_modules ) - set (not_found ))
243
237
244
238
# Start aw-server-rust first
245
- if "aw-server-rust" in modules_to_start :
239
+ if "aw-server-rust" in autostart_modules :
246
240
self .start ("aw-server-rust" )
247
- elif "aw-server" in modules_to_start :
241
+ elif "aw-server" in autostart_modules :
248
242
self .start ("aw-server" )
249
243
250
- modules_to_start = set (autostart_modules ) - {"aw-server" , "aw-server-rust" }
251
- for module_name in modules_to_start :
252
- self .start (module_name )
244
+ autostart_modules = list (
245
+ set (autostart_modules ) - {"aw-server" , "aw-server-rust" }
246
+ )
247
+ for name in autostart_modules :
248
+ self .start (name )
253
249
254
250
def stop_all (self ) -> None :
255
251
for module in filter (lambda m : m .is_alive (), self .modules .values ()):
0 commit comments