upgrade from previous version: corrupted shopping categories

View: New views
3 Messages — Rating Filter:   Alert me  

upgrade from previous version: corrupted shopping categories

by Jose Miguel Pasini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,

I recently installed gourmet again, after a couple of years. After
running gourmet for the first time again, I tried to import my old
recipes.mk file, but the "import" command didn't work. So I decided to
be more invasive: I went to the .gourmet folder and erased the existing
recipes.db and copied the old recipes.mk into that folder. The next time
I opened gourmet it read the old file and generated a recipes.db file (I
moved the old recipes.mk file away from that folder).

Everything's OK except for one thing: the "shopping categories" appear
to be corrupted, as you can see in the attached screenshot. Is there a
way for me to fix this?

Just in case this is needed:
% gourmet --version
0.13.4
% uname -a
Linux cavafy 2.6.20-16-generic #2 SMP Fri Aug 31 00:55:27 UTC 2007 i686
GNU/Linux

Thanks,
Jose Miguel



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Grecipe-manager-devel mailing list
Grecipe-manager-devel@...
https://lists.sourceforge.net/lists/listinfo/grecipe-manager-devel

corrupted_shopping_categories.png (23K) Download Attachment

Parent Message unknown Re: upgrade from previous version: corrupted shopping categories

by Thomas Mills Hinkle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
On 9/2/07, Thomas Mills Hinkle <tmhinkle@...> wrote:
I've definitely seen this bug before -- I'm pretty sure it won't have been fixed between 0.13.4 (last stable) and 0.13.7 (lastest dev version). You can access the database with sqlite and fix it by hand. The funny strings you're seeing are python pickles.

You can confirm that this is what's going on by doing the following:

$ python
>>> import sqlite3
>>> c = sqlite3.connect('/home/tom/.gourmet/recipes.db')
>>> cursor = c.cursor()
>>> cursor.execute('select * FROM shopcats')
<sqlite3.Cursor object at 0xb7cff530>
>>> cursor.fetchone()
(u'rose hip', u'produce', None)

In my case, I'm not getting a funny string since there's no corruption.

Actually, you can select for just the strange strings by doing something like this:
>>> cursor.execute('select * FROM shopcats WHERE shopcategory LIKE "S\'%"')

Then doing a cursor.fetchone() should show you the corrupted string.

Assuming this is it, you can fix it using SQL commands -- let me know if you get this far and I (or someone else) can help show you how you'd do the fix (I don't know how familiar you are with python/SQL -- if you have some familiarity, you can likely figure it out yourself).

Tom


On 9/2/07, Jose Miguel Pasini <josemiguelpasini@...> wrote:
Dear all,

I recently installed gourmet again, after a couple of years. After
running gourmet for the first time again, I tried to import my old
recipes.mk file, but the "import" command didn't work. So I decided to
be more invasive: I went to the .gourmet folder and erased the existing
recipes.db and copied the old recipes.mk into that folder. The next time
I opened gourmet it read the old file and generated a recipes.db file (I
moved the old recipes.mk file away from that folder).

Everything's OK except for one thing: the "shopping categories" appear
to be corrupted, as you can see in the attached screenshot. Is there a
way for me to fix this?

Just in case this is needed:
% gourmet --version
0.13.4
% uname -a
Linux cavafy 2.6.20-16-generic #2 SMP Fri Aug 31 00:55:27 UTC 2007 i686
GNU/Linux

Thanks,
Jose Miguel


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Grecipe-manager-devel mailing list
Grecipe-manager-devel@...
https://lists.sourceforge.net/lists/listinfo/grecipe-manager-devel





-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Grecipe-manager-devel mailing list
Grecipe-manager-devel@...
https://lists.sourceforge.net/lists/listinfo/grecipe-manager-devel

Parent Message unknown Re: upgrade from previous version: corrupted shopping categories

by Thomas Mills Hinkle-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, 2007-09-02 at 13:07 -0400, Jose Miguel Pasini wrote:

> Tom,
>
> Thanks for answering so quickly! That is exactly the problem:
>
> >>> cursor.execute('select * FROM shopcats WHERE shopcategory LIKE "S
> \'%"')
> <sqlite3.Cursor object at 0xb7d0e350>
> >>> cursor.fetchone()
> (u'rose hip', u"S'produce'\np0\n.", 0)
>
> I think it will be pretty easy to fix. However, I had some SQL as a
> freshman in 1991, so I'm very rusty. I'll be able to understand your
> instructions, but coming up with them on my own will take a long time.
>

Ok, here's a script to fix it. You can type each line of this script in
at the python shell, or you can save it as a file and then run it with:
$ python scriptname.py

I've used Gourmet's API to do all the work, because my SQL is also rusty
-- rustier than it was when I first wrote the SQL backend for Gourmet
anyway :)

Here goes... (the lines with # are comments)

# import
Gourmet...                                                                                
import gourmet.recipeManager
# import python's pickle library to unpickle
stuff...                                              
import pickle
# load the default gourmet data (in
~/.gourmet/recipes.db)                                        
rm = gourmet.recipeManager.default_rec_manager()
shopcats = rm.fetch_all(rm.sview)
for cat in shopcats:
    # unpickle the pickled
category                                                                
    try:
        category = pickle.loads(cat.shopcategory)
    except:
        print "Can't fix",cat.shopcategory,"- it's not a pickle"
    else:
        rm.do_modify(
            rm.sview,cat,
            {'shopcategory':category}
            )

# Commit - this won't work if Gourmet is
running...                                                
rm.save()
print 'Done fixing categories!'

Hope that does the trick.

Tom


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Grecipe-manager-devel mailing list
Grecipe-manager-devel@...
https://lists.sourceforge.net/lists/listinfo/grecipe-manager-devel