RaiMan / SikuliX-2014

SikuliX version 1.1.2 (until February 2018)
http://sikulix.com
806 stars 235 forks source link

[request] deleting not used images on save should detect incomplete comments -- fixed 1.1.1 2016-07-06+ #216

Closed audus closed 8 years ago

audus commented 8 years ago

I have a lot of codes in one library where one main code imports all other scripts and run their functions in a specific order to make a test. I have created a very similar system before on 1.0.1 and I have come far without any unsolvable problem. Here's kinda what it looks like:

from sikuli import * # importing full sikuli to prevent import errors in main.sikuli import os import shutil

print "importing" import start_l import start_x import close_x import start_s import close_l import close_s import test_s print "import done"

theFailure = None Settings.MoveMouseDelay = 1.5

try: start_l.start_l() wait(3) start_x.startx() start_s.start() test_s.test()

But now when i run my code it gives me this error halfway through the second function, [error] Image: could not be loaded: file:/C:/jenkins2/workspace/test/test_s.sikuli/1453217794652.png [error] Image: Image not valid, but TextSearch is switched off! Its loading the right image but from the wrong directory as the function being run is start_x.startx() which is actually almost copied from the working 1.0.1 script(1.0.1 script works in 1.1.0). start_x is imported correctly and work when run separately. All the other parts of the script work since this function was newly added and none have had the problem of loading from the wrong directory. Thanks in advance for help given even if its a workaround, bugfix or just pointing out where I'm wrong!

RaiMan commented 8 years ago

when importing a xxx.sikuli script, the folder xxx.sikuli is also added to the imagepath.

So to check your imagepath add this after the print "import done"

for entry in getImagePath():
    print entry

In your case, you seem to have an imagefile with the same name in a different .sikuli folder. The search on the imagepath stops with the first matching filename. So precedence is relevant.

Generally in some professional environment one should have a strict naming convention, that avoids such name clashes.

audus commented 8 years ago

well this is actually not a bug or error in sikuli but just a faulty error message as it didnt find the picture in our .sikuli files and for some reason gave the error with the latest imported modules path. The real problem we did find tough was that when saving a script sikulis image removal stopped reading the code at one point and therefore removed all the pictures I had implemented after that point. We dont know why this happened but it have happened 2 times but we have solved it by finding the point were it stops reading and recoding from that point(by copy and pasting between Sikuli and Word). So the first time it happened we had a code like this 33 click("a.png") 34 click("b.png") 35 wait("c.png") 36 doubleClick("d.png") 37 click("a.png") and when we saved it c.png and d.png was removed since sikuli removes pictures not used in the code. So we think the bug here is that sikuli reads the code wrong when saving and removing all non-duplicate files(a.png wasn't removed as it was found before line 35). we have recorded this bug in a logfile with debugging level 3.

we also use and print the imagepath in the code becasue the test saves the failing image in a folder if it fails but left that part out since it was just gonna be irrelavent nonsens as it all triggers after the error we came across.

audus commented 8 years ago

we have found the real source of the problem and that is that we were missing a ". that made it offset all the strings and make sikuli not recognize them(or that's my guess). But i think there should be a pop-up for syntax errors or auto-removing files with sikuli so this doesn't happen as easily for a clumsy keyboard user like me. Sorry for wasting your time Raiman but could you take this suggestion into account when making 1.1.1 or should i make this a new post for this to get considered being put in.

RaiMan commented 8 years ago

thanks. I already thought, that it has been something like that.

I agree: this is a bit odd.

I will have a look, wether the current implementation can be changed, to recognize your situation. Until then I simply leave this one open.

audus commented 8 years ago

i thought of an idea where sikuli could search for ".png" instead of strings making it recognize images even if there's a missing " in the code. something like this import re p = re.compile("FindFailed: can not find (..png) .*") # parentheses for capture groups filename = p.match(str(exception)).group(1) # 1st match (there is only one) but maybe you have already tried and considered this deeming it slow or unusable.

RaiMan commented 8 years ago

I have fixed this situation. available with tonight's nightly. I would appreciate if you have a look at it.

audus commented 8 years ago

I checked out the nightly build by downloading it from the link on http://nightly.sikuli.de/#dailynews . But when testing it by writing the code click("a.png") print "hey" click("b.png") and then saving it making sure all images are saved and the code is runnable I then looked if the change was implemented by changing it to. click("a.png") print "hey click("b.png") the problem with b.png being removed and/or being removed without a warning or abort is still there. i don't know if we misunderstood each other, if the build just hadn't come yet(download time was 07-05 08:55 and what i got the release was 07-05 1:00) or if its just my environment being different from yours. Anyhow i ask you again to look into this and do the same test yourself so we can implement something to help here.

RaiMan commented 8 years ago

Again tested: works. On save you get a popup, that in line 2 is a possible uncompleted comment, which then aborts the image cleanup.

Maybe you ran into the setup trap: when asked about reusing the sikulix stuff already downloaded, you have to say no, to get the latest stuff (at least for sikulixsetupAPI-1.1.1-... and sikulixsetupIDE-1.1.1-... you have to say NO)

audus commented 8 years ago

ok then i ran into the trap and i will retry

audus commented 8 years ago

Thanks so much for helping me and solving the issue! sidenote in pop-up you say comment when it really is a string so clarify with "comment or string"

RaiMan commented 8 years ago

-- so clarify with "comment or string" thanks, but it must read string only, because it detects: ..... "some text .... <new-line> hence meaning: odd number of apostrophs on one line no matter wether inside or outside of comments.