← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #206597]: Problem with importing "external" modules

 

Question #206597 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/206597

RaiMan posted a new comment:
Ok, but this only makes sense, if your main script IS IN FACT
RUNME.sikuli (contains a RUNME.py).

>From your initial question one could get the impression, that it CONTAINS a runme.sikuli:
... All these files are opened via \\FILESERVER\Directory\Directory\Directory\Runme.sikuli (for the runme.sikuli) ...

and using 
dir = os.path.dirname(getBundlePath())

made this even more probable, since this gives the directory, that CONTAINS the some_script.sikuli, in your real case
\\FILESERVER\Directory\Directory\Directory\

so if your directory structure really is like this:

some-path\
  -- RUNME.sikuli
     -- RUNME.py
     -- InitSystem.sikuli
     -- GlobalSettings.sikuli
     -- Tests
         -- Test1.sikuli
         -- Test2.sikuli

then the real (general solution) is, to take the return of
getBundlePath() as the base directory for the sys.path manipulation.

BTW: I guess in the last time it has to read 
InitSystem.getCurrentTime()

# main script (content of RUNME.py)
import InitSystem
import GlobalSettings
import os
dir = getBundlePath()                                          # changed ###
testsModulePath = os.path.join(dir, "Tests")  # changed ###

modulesToRun = ("Test1", "Test2", "Test_OCR")

print("Testing started: " + InitSystem.getCurrentTime())

if (InitSystem.startUp(GlobalSettings.screenT, GlobalSettings.screenQ, GlobalSettings.screenP)==0): # Init the tests
    popup("ERROR during startup, cancelling all tests...")
    exit
else: # Startup was OK
    # Iterating through all Test-Modules
    popup("OK starting Tests in Modules")

    if not testsModulePath in sys.path:
        sys.path.append(testsModulePath)
    for currentModule in modulesToRun:
       popup("Working with module " + currentModule + " in directory " + testsModulePath)
       popup("Opening " + currentModule)
       exec("import " + currentModule)
       exec(currentModule + ".runModule()")

InitSystem.shutDown() # Shut down the test
print("Testing ended: " + InitSystem.getCurrentTime()) # changed ###

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.