-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
search for (read-only) extensions in XDG_DATA_DIRS
- Loading branch information
Showing
10 changed files
with
60 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import os | ||
|
||
from ulauncher.modes.extensions.extension_finder import find_extensions | ||
from ulauncher.modes.extensions.extension_finder import iter_extensions | ||
|
||
|
||
def test_find_extensions__test_extension__is_found(): | ||
ext_dir = os.path.dirname(os.path.abspath(__file__)) | ||
(id, path) = next(iter(find_extensions(ext_dir))) | ||
(id, path) = next(iter(iter_extensions(ext_dir))) | ||
assert id == "test_extension" | ||
assert path == f"{ext_dir}/test_extension" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
import os | ||
|
||
|
||
def find_extensions(ext_dir): | ||
def is_extension(directory): | ||
""" | ||
Yields `(extension_id, extension_path)` tuples found in a given extensions dir | ||
Tells whether the argument is an extension directory | ||
""" | ||
if os.path.exists(ext_dir): | ||
manifest = os.path.join(directory, "manifest.json") | ||
manifest = os.path.realpath(manifest) | ||
return os.path.isfile(manifest) | ||
|
||
|
||
def locate_extension(ext_id, ext_dirs, default=None, default_first=False): | ||
ret = default | ||
for ext_dir in ext_dirs: | ||
ext_path = os.path.join(ext_dir, ext_id) | ||
if default_first and ret is None: | ||
ret = ext_path | ||
elif is_extension(ext_path): | ||
ret = ext_path | ||
break | ||
if ret: | ||
ret = os.path.realpath(ret) | ||
return ret | ||
|
||
|
||
def iter_extensions(ext_dirs, duplicates=False): | ||
""" | ||
Yields `(extension_id, extension_path)` tuples found in a given extensions dirs | ||
""" | ||
occurrences = set() | ||
for ext_dir in ext_dirs: | ||
if not os.path.exists(ext_dir): | ||
continue | ||
for entry in os.scandir(ext_dir): | ||
if entry.is_dir() and os.path.isfile(f"{ext_dir}/{entry.name}/manifest.json"): | ||
yield (entry.name, f"{ext_dir}/{entry.name}") | ||
if is_extension(entry.path) and (duplicates or entry.name not in occurrences): | ||
occurrences.add(entry.name) | ||
yield entry.name, os.path.realpath(entry.path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters