Image caching loop goes wrong for my recipe searching program (daemon)

Go To StackoverFlow.com

2

I wrote a daemon program, for searching through recipes from Gourmet Recipe Manager's database ( that is a recipe manager for GNU/Linux )

My program reads the information that it needs for each recipe element over a loop from the sqlite database.

(Such a daemon for Ubuntu Linux is called a 'scope'.
Such scopes give ubuntu unity more sources for its searching.)

'model' has the information, which gets delivered over DBUS to Ubuntu Unity.

In theory you are able to use an URI as the source for the image in 'model' ,
but the developers said me in IRC I am not able to use data URI's.

I tested that, too, and for me it did not work.

So I cache(d) the images in /tmp.

Now you are able to see all recipes, and search for specific one's per title, but the image asociation is simply wrong. if you search for the 2.th , the recipe of the 2.th gets shown, but with the image of the fist recipe in the sqlite table.

Here are two images, to understand the problem:
The 2.th recipe gets the image of the first recipe

I already looked in some IRC rooms for help, but no one could help me...

I think you have to save the state of each image somehow.

I would be pleased, if you have a solution that does not requiere to cache images.

The full source file can be viewed here: http://bazaar.launchpad.net/~gotwig/lens-cooking/lens-cooking/view/head:/unity-scope-gourmet

So, here is the specific part of my code:

if row[14]:
        open('/tmp/unity-scope-gourmet/icon' + str(i), 'wb').write(row[14])
        model.append(uri, '/tmp/unity-scope-gourmet/icon' + str(i), 1, "text/html", title, comment, uri)
else:
        if os.path.exists('/tmp/unity-scope-gourmet/icon' + str(i)):    os.remove('/tmp/unity-scope-gourmet/icon' + str(i))
        model.append(uri, '', 1, "text/html", title, comment, uri)
2012-04-05 17:42
by Eduard Gotwig


1

It sounds like you a describing a simple counter error. It's not clear to me how you are initializing your counter 'i', but if it's off by one, the simple solution is to simply add one to it before using it, ie:

open('/tmp/unity-scope-gourmet/icon' + str(i+1), 'wb').write(row[14])
                                           ^^^
2012-04-05 19:21
by user590028
Please read my question more carefuly. It does only happen when I search for something specific. when i search for the 5.th or the sixt recipe, they show up correctly with the right images. And when I search for nothing , all images show up correctly, too. see sourcecode Trouh your solution the 2th recipe has the wrong image, and all other recipes do not even have images - Eduard Gotwig 2012-04-05 19:35
As a courtesy, I have re-read your message a second time...but I cannot find the reference you are talking about. I did however see this comment, which was what my answer attempted to assist with "if you search for the 2.th , the recipe of the 2.th gets shown, but with the image of the fist recipe in the sqlite table.". I'd be happy to assist, but I can't clearly follow what you are describin - user590028 2012-04-05 19:48
Can you understand what you see on the images here ?http://imgur.com/81Otj,tFCbX# - Eduard Gotwig 2012-04-05 19:49
I'm afraid not - user590028 2012-04-05 19:51
Ok. You see when I search for nothing, my daemon program in the background shows all my recipes in the database, but when I search for something the recipe elements get the wrong images. My english is not good. But you see I documented very much... Is it so hard to understand - Eduard Gotwig 2012-04-05 19:57
Are you saying the problem is with sqlite, or with your rendering code? In the code snippet you quoted, you specifically referenced the rendering code, so I focused there. Furthermore, you said it is displaying the correct RECIPE, but the incorrect IMAGE. And further that the incorrect IMAGE bore some sort of sequential relationship to the intended IMAGE. I'd like to help, but unless you can explain the problem simply, I don't think I will be of much assistance to you - user590028 2012-04-05 20:09
Yeah, the recipe has the wrong image, it should have an other image. All images show up correctly when you search for nothing. Get it - Eduard Gotwig 2012-04-05 20:25
Got it. And are the images "offset by one", or is it just some random image - user590028 2012-04-05 20:37
I have to use somehow other image names, and I cant take simply one, becouse Ubuntu Unity does cache the images somehow - Eduard Gotwig 2012-04-05 20:40
DO you understand it - Eduard Gotwig 2012-04-05 20:51
I think I now understand. You think this is a problem in Unity...not your code. I mis-interpreted the fact you were posting in StackOverflow as request for code related assistance, but it looks more like you are asking a Unity/Lenses related question. Can I suggest you try adding 'file:///' to your model.append call? Something like: model.append(uri, 'file:///tmp/unity-scope-gourmet/icon' + str(i - user590028 2012-04-05 21:01
I have to reuse for every image a new file I think. The problem is that when I search for something, the first result gets the image0.png or image1.png as name. But becouse unity caches images, it simply uses the old one, and does not overwrite the old one. I have to use for realy every image an imagefile, so nothing gets cached. I dont know how to do that. Of course that would be easier, if you could turn this unity filter simply off, but its not a problem that you can't solve. I realy dont thing that file:/// would change anything, becouse unity is able to access the files - Eduard Gotwig 2012-04-05 21:39
If you just want to ensure you are generating a completely UNIQUE file name, why not append a uuid string? Something like: str(uuid.uuid4()) - user590028 2012-04-05 21:54


1

I solved the problem with combining the filename of the cached image with each ID of the recipe.

Code:

i = row[0]

See the complete solution here : http://bazaar.launchpad.net/~gotwig/lens-cooking/lens-cooking/revision/32

2012-04-06 13:31
by Eduard Gotwig
Ads