Closed caprageon closed 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 ?
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
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/","")
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 :)
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.
@caprageon so it s better now ?
@caprageon ?
Hi Smanar sorry I couldn't test earlier. So I pulled fonctions.py from beta and the frontend is installing OK. Thanks !
Nice, thx. Will use that for the moment, on next problem I will use Parameters['HomeFolder'] and Parameters['StartupFolder']
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.