[jython] import other Script, write data to file system

Thanks to everybody involved for all the work on this library!

I have some trouble to find the right concept for these two issues:

I have a class A defined in a.py. Since this class requires a scripting context, it has to be in the ${OPENHAB_CONF}/automation/jsr223/ directory.
It would be great to have unit tests in a separate file and to be able to reuse this class in other files. While imports from ${OPENHAB_CONF}/automation/lib/ directory are working fine, I have not been able to make a successful import from the .../jsr223 directory, could any one point me to the right direction?

When attempting to write to a file from a jython script within the ${OPENHAB_CONF}/automation/jsr223/ directory, a Permission denied is given:

    12:54:59.477 [ERROR] [jsr223.jython.test             ] - exception writing to file:
    Traceback (most recent call last):
      File "<script>", line 202, in writeConfig
    IOError: [Errno 13] Permission denied: '/etc/openhab2/automation/etc/test.txt'

even though file permissions are set:

    ls -l /etc/openhab2/automation/etc
    insgesamt 16
    -rw-r--r-- 1 openhab        openhab 3750 Jul  2 12:46 test.txt

Probably this is a security feature, so would the use of mapdb be an appropriate way to do some short term persistence - is the JSON storage available to scripts?

Thank you in advance for any help!

You can’t import from scripts, so you should put your class in a module. If you need access to the OH scriptExtensions, use core.jsr223.scope in your module.

You’re trying to write to a script from another script?! That sounds like trouble.

Short persistence that is available between script reloads or OH restarts? I’m guessing the latter. You can use jsondb, mapdb, java.io.file, etc., but Jython can also write to files.

Thank you for the prompt reply!

I will have a look again on how components work with core library classes.

I did not attempt to a script file, but to a text (may be future configuration) file. The text in my original post is wrong, it should be ${OPENHAB_CONF}/automation/etc, a randomly chosen name, do you suggest another location? However, the error message and the ln output in my first post are correct. The log message is the result of

            with open('/etc/openhab2/automation/etc/test.txt', 'w') as outfile:  
                json.dump(config, outfile)
        except Exception:
            log.exception("exception writing to file:")

Writing to a file works for me now.
It appears, that write permissions for user openhab on the file is not sufficient, the directory the file is in must have write permissions as well.