Smanar / Domoticz-deCONZ

deCONZ plugin for Domoticz (Zigbee application)
GNU General Public License v3.0
36 stars 27 forks source link

wrong templates_path in installFE() and uninstallFE() with dockerized domoticz #128

Closed caprageon closed 2 years ago

caprageon commented 2 years ago

When running domoticz in docker with the official image domoticz/domoticz the path to the plugins folder is /opt/domoticz/userdata/plugins instead of /opt/domoticz/plugins, for persistance reasons.

This causes the plugin to fail when attempting to install the custom frontend.

The folder /opt/domoticz/plugins exists in the docker image although it doesn't seem to be used.

Smanar commented 2 years ago

Hello, something similar to https://github.com/Smanar/Domoticz-deCONZ/issues/91

I m using dynamic path on the code

    source_path = os.path.dirname(os.path.abspath(__file__)) + '/frontend'
    templates_path = os.path.abspath(source_path + '/../../../www/templates')

Can you give me the correct path, and the plugin file path ?

caprageon commented 2 years ago

Hello !

Yes you're right it looks like it might be a similar issue.

So from my understanding, I think the source_path is alright with : source_path = os.path.dirname(os.path.abspath(__file__)) + '/frontend'

Here it gives source_path = /opt/domoticz/userdata/plugins/Domoticz-deCONZ/frontend

But then, since there is a supplementary 'userdata' folder in our file tree , the templates path is wrong.

it should be templates_path = /opt/domoticz/www/templates

but we get templates_path = /opt/domoticz/userdata/www/templates (which doesn't exist)

For testing purposes i added a '/..' in the templates_path :

templates_path = os.path.abspath(source_path + '/../../../../www/templates') instead of : templates_path = os.path.abspath(source_path + '/../../../www/templates')

and it works OK.

Maybe you could check the distance between the 'domoticz' folder and the 'frontend' folder (in source_path) to adjust dynamically the number of "/.." but i'm really not sure about it

Smanar commented 2 years ago

So, correct me if I m wrong;

Maybe you could check the distance between the 'domoticz' folder and the 'frontend' folder (in source_path) to adjust dynamically the number of "/.." but i'm really not sure about it

IDK, I see a "brutal" solution, with remove the chain "/userdata" in the path, but I m not sure this path NEVER exist. Or a less brutal with checking if the path exist.

Can you try the beta branch ? Have added some code

    #Special part for dockers
    if not os.path.exists(templates_path):
        templates_path = templates_path.replace("userdata/","")
caprageon commented 2 years ago

So, correct me if I m wrong;

  • the plugin file is in /opt/domoticz/userdata/plugins/Domoticz-deCONZ
  • the source_path for file become /opt/domoticz/userdata/plugins/Domoticz-deCONZ/frontend
  • the template path is /opt/domoticz/www/templates for docker installation

You are absolutely right.

Your approach looks safe. If anyone has any custom/exotic file tree with two userdata in the path it won't work, but it wouldn't work either in the first place with the initial code. I don't see any other case where it could cause a problem.

I'll give it a try and give you my feedback.

Another -less brutal- approach would be to query domoticz parameters as the guys from domoticz-zigbee2mqtt-plugin did here

source_path = Parameters['HomeFolder'] + 'frontend' templates_path = Parameters['StartupFolder'] + 'www/templates'

This would benefit to all of the exotic paths lovers out there :)

Smanar commented 2 years ago

Another -less brutal- approach would be to query domoticz parameters as the guys from domoticz-zigbee2mqtt-plugin did here

Yes, totally right, but now it's late, will use this method on next issue, or if my method don't work.

Smanar commented 2 years ago

@caprageon so it s better now ?

Smanar commented 2 years ago

@caprageon ?

caprageon commented 2 years ago

Hi Smanar sorry I couldn't test earlier. So I pulled fonctions.py from beta and the frontend is installing OK. Thanks !

Smanar commented 2 years ago

Nice, thx. Will use that for the moment, on next problem I will use Parameters['HomeFolder'] and Parameters['StartupFolder']