-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from ChanceNCounter/refactor/languages_cleanup
Refactor: function discovery and introspection
- Loading branch information
Showing
64 changed files
with
3,874 additions
and
2,580 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 |
---|---|---|
|
@@ -103,5 +103,7 @@ venv.bak/ | |
# mypy | ||
.mypy_cache/ | ||
|
||
# vscode settings | ||
# VSCod(e/ium) | ||
.vscode/ | ||
vscode/ | ||
*.code-workspace |
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,66 +1,4 @@ | ||
import os | ||
from os.path import join, expanduser | ||
|
||
|
||
def _log_unsupported_language(language, supported_languages): | ||
""" | ||
Log a warning when a language is unsupported | ||
Arguments: | ||
language: str | ||
The language that was supplied. | ||
supported_languages: [str] | ||
The list of supported languages. | ||
""" | ||
supported = ' '.join(supported_languages) | ||
print('Language "{language}" not recognized! Please make sure your ' | ||
'language is one of the following: {supported}.' | ||
.format(language=language, supported=supported)) | ||
|
||
|
||
def resolve_resource_file(res_name, data_dir=None): | ||
"""Convert a resource into an absolute filename. | ||
Resource names are in the form: 'filename.ext' | ||
or 'path/filename.ext' | ||
The system wil look for ~/.mycroft/res_name first, and | ||
if not found will look at /opt/mycroft/res_name, | ||
then finally it will look for res_name in the 'mycroft/res' | ||
folder of the source code package. | ||
Example: | ||
With mycroft running as the user 'bob', if you called | ||
resolve_resource_file('snd/beep.wav') | ||
it would return either '/home/bob/.mycroft/snd/beep.wav' or | ||
'/opt/mycroft/snd/beep.wav' or '.../mycroft/res/snd/beep.wav', | ||
where the '...' is replaced by the path where the package has | ||
been installed. | ||
Args: | ||
res_name (str): a resource path/name | ||
Returns: | ||
str: path to resource or None if no resource found | ||
""" | ||
# First look for fully qualified file (e.g. a user setting) | ||
if os.path.isfile(res_name): | ||
return res_name | ||
|
||
# Now look for ~/.mycroft/res_name (in user folder) | ||
filename = os.path.expanduser("~/.mycroft/" + res_name) | ||
if os.path.isfile(filename): | ||
return filename | ||
|
||
# Next look for /opt/mycroft/res/res_name | ||
data_dir = data_dir or expanduser("/opt/mycroft/res/") | ||
filename = os.path.expanduser(join(data_dir, res_name)) | ||
if os.path.isfile(filename): | ||
return filename | ||
|
||
# Finally look for it in the source package | ||
filename = os.path.join(os.path.dirname(__file__), 'res', res_name) | ||
filename = os.path.abspath(os.path.normpath(filename)) | ||
if os.path.isfile(filename): | ||
return filename | ||
|
||
return None # Resource cannot be resolved | ||
from .internal import get_default_lang, set_default_lang, get_default_loc, \ | ||
get_active_langs, _set_active_langs, get_primary_lang_code, \ | ||
get_full_lang_code, resolve_resource_file, load_language, \ | ||
load_languages, unload_language, unload_languages, get_supported_langs |
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
Oops, something went wrong.