WebThingsIO / addon-list

List of installable add-ons for WebThings Gateway

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refreshing addons to no longer use "mozilla_iot"

opened this issue · comments

I was wondering what the recommended way is to change the paths in addons still referring to MOZIOT.

For example, the MySensors addon has:

_CONFIG_PATHS = [
    os.path.join(os.path.expanduser('~'), '.mozilla-iot', 'config'),
]

if 'MOZIOT_HOME' in os.environ:
    _CONFIG_PATHS.insert(0, os.path.join(os.environ['MOZIOT_HOME'], 'config'))

Is that still ok like this?

The addon also uses hardcoded paths:

self.addon_path = os.path.join(os.path.expanduser('~'), '.mozilla-iot', 'addons', 'mysensors-adapter')

Any suggestion on how to adapt this? Could I use some generic code to figure out if the addon should use .mozilla-iot or some new directory name?

If so, what would you recommend? A quick code example of how to find the base directory in the most future-proof manner would be much appreciated.

You shouldn't be hardcoding paths anymore, since the required paths are available to your adapter. Here's an example from a JS add-on, that you could adapt to Python:

In Python, you can access self.user_profile['configDir'] (I believe).

user_profile also contains baseDir, addonsDir, and several others.