-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
At OH start, scripts beneath $OPENHAB_CONF/automation/jsr223/community/ run before those under jsr223/core/ #76
Comments
@ScottKinSF What about just having a python(jython) script that the jython interpreter loads automatically and have that script load the various directories and modules under user control rather than relying on specific jython versions that seem to behave differently? |
@mjcumming, my reading of your comment makes me think you may be using a Jython jar other than the recommended jython-standalone-2.7.0.jar. If so, what version do you have installed in $OPENHAB_CONF/automation/jython, also, what load order do you see on your system? |
Nice catch @ScottKinSF ! Can you please confirm that you are using 2.7.0? Have you seen my comments about 2.7.1? I've been restarting OH a lot, and noticed the OWM script running first, and I was attributing that to the updated Jython, but your findings indicate that the directory names ARE considered with 2.7.0. The initial documentation mentioned this (maybe @steve-bate could give us a hint as to the bug mentioned, or if/where OH is loading the scripts), but the OH doc claims directory names are not considered. In testing this early on, I was certain the directory names were not considered, so I removed it. So I screwed up, or something changed. This is unfortunate, since we just did the restructuring. My initial fix was to rename /jsr223/core to /jsr223/000_core. Here is another related development, which would eliminate the need for all/most of the core modules, but that will be a while, and won't fix anything for any core modules that are not absorbed into the API. @mjcumming , that does sound like a possibility, but I think it would be messy to put it in the Java, since not everyone uses these modules. For your solution, maybe we could put the startup delay script at the root of /jsr223/, and have it load the other component scripts, rather than renaming the core directory. Let's look into whether it is OH or Jython that is determining the load order of the scripts. |
@openhab-5iver I was thinking a .py script that loaded modules/scripts/components in directories not loaded by jython so we do not have to worry about relying on directory and file names to control the order of loading. |
I could be wrong, but I'm pretty sure scripts have to be under /automation/ for OH to load them. |
Probably not explaining what I was thinking.... If we only had Jython load one script in the automation folder, that script could load other modules in the order desired without worrying about naming conventions and alphabetical order. Ie. I have a script that loads all of the other scripts its needs to run - it doesn't rely on the Jython to load those scripts. |
Confirmed, my installation currently uses |
In my reading of the OH doc, I don't see such a claim. The doc doesn't seem to say anything about the ordering of the directory traversal during script loading other than it is top down. It would make sense to me that whatever process is performing the traversal and script loading has to have a repeatable method for sequencing through directories that are siblings at any given level of the $OPENHAB_CONF/automation/jsr223/ hierarchy, which to me would reasonably be directory names according to the ASCII collation sequence (case sensitive?). [Update] As you noted above, to fully understand the JSR223 script loading sequence, we need to find where the initial loading of scripts takes place. |
Loading of JSR223 scripts happens in |
The text at the bottom made it less ambiguous for me...
I'll start looking into this... I just wrapped up adding Jython and Groovy script actions in Paper UI, but waiting for ESH migration before submitting! |
Based on my inspection of the relevant Java source code, that text in the documentation is in error. If the files under automation/jsr223/ are as shown in the example:
the load order will be |
I agree. The OH doc was originally submitted with that wording on 7/14/17, but there was a change on 7/24/17 that added the inclusion of the directory name, but the OH doc was never updated. It puzzles me how the old code would have prevented the loading of scripts with the same name. The quick ugly fix is to prefix the directories with a number. The better fix, IMO, is to have ScriptFileWatcher.checkFiles() sort the scripts by filename, ignoring the directory name. But I'm still not fully committed to that. |
I like your preferred fix, sorting on file names. That is much easier to explain such that any user can understand the script loading order. |
I'm updating the docs for something else, and remebered this still needed to be corrected, so I put together some test scripts. These files and directory structure...
... load in this order...
I have a couple OH PRs to wrap up, and will then put in a change to ScriptFileWatcher so that just the names of the files are considered. They would then load in this order...
|
If anyoe has a minute, I've submitted a PR to change the load order and could use some help communicating the need for the change... openhab/openhab-core#724. |
Closed in openhab/openhab-core#724. Wahoo! |
When OH is started, any scripts under $OPENHAB_CONF/automation/jsr223/community/ are loaded and run before any script under $OPENHAB_CONF/automation/jsr223/core/, most notably jsr223/core/000_startup_delay.py.
Logs from my recent OH start:
Possible fixes (untested):
zzz_community
community/
to a new directory immediately belowjsr223
:jsr223/local/community
.The text was updated successfully, but these errors were encountered: