sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #31038
Re: [Question #263570]: Let sikuli scripts access their own resources even after imported
Question #263570 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/263570
Status: Open => Answered
RaiMan proposed the following answer:
After an import, the path where it was loaded from is on sys.path and on the image path (reliable only with version 1.0.1+).
so with some naming convention you could add a prolog code (at indent level 0) to the imported script, that evaluates e.g. sys.path, to find the named subfolder and set a module variable:
an example
#script2
myPath = getBundlePath()
import script1
#script1
from sikuli import *
import os
myResources="someUniqueName"
myPath = None
for e in sys.path:
myPath = os.path.join(e, MyResources)
if os.path.exists(myPath):
myPath = e
break
myPath = None
if not myPath:
print "Resource path not found:", myResource
exit(1)
def doSomeThing():
resource1 = os.path.join(myPath, "someFolder/someFile.txt")
# do something with this file
All this only works with a strict naming concept.
As a general feature I will add this to the list for version 2:
myResource = getResource("someUniqueName")
which internally scans sys.path and image path for the resource folder/file and returns the absolute path if found.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.