Skip to content

Commit 063a00c

Browse files
committed
fix: fixed module detection and naming
1 parent 02aba37 commit 063a00c

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

aw_qt/manager.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ def _discover_modules_in_directory(path: str) -> List["Module"]:
2828
modules = []
2929
matches = glob(os.path.join(path, "aw-*"))
3030
for match in matches:
31+
# TODO: Filter matches the same as done by _filter_filenames
3132
if os.path.isfile(match) and os.access(match, os.X_OK):
32-
name = os.path.basename(match)
33+
filename = os.path.basename(match)
34+
name = _filename_to_name(filename)
3335
modules.append(Module(name, Path(match), "bundled"))
3436
elif os.path.isdir(match) and os.access(match, os.X_OK):
3537
modules.extend(_discover_modules_in_directory(match))
@@ -40,10 +42,25 @@ def _discover_modules_in_directory(path: str) -> List["Module"]:
4042
return modules
4143

4244

45+
def _filename_to_name(filename: str) -> str:
46+
return filename.replace(".exe", "")
47+
48+
49+
def _filter_filenames(filenames: List[str]) -> List[str]:
50+
return [
51+
fn
52+
for fn in filenames
53+
if fn.startswith("aw-")
54+
and (".manifest" not in fn)
55+
and (".desktop" not in fn)
56+
and (".service" not in fn)
57+
]
58+
59+
4360
def _discover_modules_bundled() -> List["Module"]:
4461
"""Use ``_discover_modules_in_directory`` to find all bundled modules """
4562
_search_paths = [_module_dir, _parent_dir]
46-
logger.info("Search paths: {}".format(_search_paths))
63+
logger.info("Searching for bundled modules in: {}".format(_search_paths))
4764
modules: List[Module] = []
4865
for path in _search_paths:
4966
modules += _discover_modules_in_directory(path)
@@ -61,18 +78,15 @@ def _discover_modules_system() -> List["Module"]:
6178
if _parent_dir in search_paths:
6279
search_paths.remove(_parent_dir)
6380

64-
logger.info(search_paths)
81+
logger.debug("Searching for system modules in PATH: {}".format(search_paths))
6582
modules: List["Module"] = []
66-
for path in search_paths:
67-
if os.path.isdir(path):
68-
files = os.listdir(path)
69-
for filename in files:
70-
if filename.startswith("aw-"):
71-
# Only pick the first match
72-
if filename not in [m.name for m in modules]:
73-
modules.append(
74-
Module(filename, Path(path) / filename, "system")
75-
)
83+
paths = [p for p in search_paths if os.path.isdir(p)]
84+
for path in paths:
85+
for filename in _filter_filenames(os.listdir(path)):
86+
name = _filename_to_name(filename)
87+
# Only pick the first match (to respect PATH priority)
88+
if name not in [m.name for m in modules]:
89+
modules.append(Module(name, Path(path) / filename, "system"))
7690

7791
logger.info("Found system modules:")
7892
_log_modules(modules)

0 commit comments

Comments
 (0)