Search and replace an image path

72 views
Skip to first unread message

Gnome

unread,
Nov 1, 2012, 11:21:48 AM11/1/12
to mnemosyne-...@googlegroups.com
After doing some cleaning in 'default.db_media' i have renamed one directory. Can I just search and replace the path name in 'default.db', after taking backup of course?

Best regards,
Gn.

Peter Bienstman

unread,
Nov 1, 2012, 11:33:21 AM11/1/12
to mnemosyne-...@googlegroups.com
You mean you want to do a binary search an replace inside the file
'default.db'? I'm not sure how well sqlite would like this...

Better do this inside an sql viewer / editor.

Cheers,

Peter
> --
> You received this message because you are subscribed to the Google
> Groups "mnemosyne-proj-users" group.
> To post to this group, send email to mnemosyne-...@googlegroups.com.
> To unsubscribe from this group, send email to
> mnemosyne-proj-u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mnemosyne-proj-users/-/lzRBgdPCHxEJ.
> For more options, visit https://groups.google.com/groups/opt_out.

Gnome

unread,
Nov 2, 2012, 4:34:21 AM11/2/12
to mnemosyne-...@googlegroups.com
I'm trying to make a plugin based on the add menu plugin and search and replace script you have written instead. But I can't figure out how to add the menu item to the cards menu instead of the help menu, for example I have tried 'self.main_widget().menu_Cards.addAction(self.action_hello)'. Something seems to be wrong with the script since the button doesn't display "Hi there!"(?).


kl. 16:33:26 UTC+1 torsdag 1. november 2012 skrev Peter Bienstman følgende:
You mean you want to do a binary search an replace inside the file
'default.db'? I'm not sure how well sqlite would like this...

Better do this inside an sql viewer / editor.

Cheers,

Peter

On 11/01/2012 04:21 PM, Gnome wrote:
> After doing some cleaning in 'default.db_media' i have renamed one
> directory. Can I just search and replace the path name in 'default.db',
> after taking backup of course?
>
> Best regards,
> Gn.
>
> --
> You received this message because you are subscribed to the Google
> Groups "mnemosyne-proj-users" group.
> To post to this group, send email to mnemosyne-...@googlegroups.com.
> To unsubscribe from this group, send email to
> mnemosyne-proj-users+unsub...@googlegroups.com.

Gnome

unread,
Nov 2, 2012, 5:07:56 AM11/2/12
to mnemosyne-...@googlegroups.com
I was able to change the menu item location now.

Gnome

unread,
Nov 2, 2012, 5:02:24 PM11/2/12
to mnemosyne-...@googlegroups.com
The line "QtCore.QObject.connect(self.action_hello, QtCore.SIGNAL("activated()"),
self.hello_world)", didn't do anything on my machine. I did some modifications to the script and now it works here.

#
# add_menu_item.py <Peter.B...@UGent.be>
#

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from mnemosyne.libmnemosyne.plugin import Plugin


class HelloWorldPlugin(Plugin):

    name = "Hello world"
    description = "Add a menu item to the help menu"

    def __init__(self, component_manager):
        Plugin.__init__(self, component_manager)
        self.action_hello = None

    def activate(self):
        Plugin.activate(self)

        self.action_hello = QAction("&Hello world!", self.main_widget(),
                triggered=self.hello_world)

        self.main_widget().menu_Help.addAction(self.action_hello)

    def deactivate(self):
        Plugin.deactivate(self)
        if self.action_hello:
            self.main_widget().menu_Help.removeAction(self.action_hello)
            self.actionHello = None

    def hello_world(self):
        self.main_widget().show_information("Hi there!")

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(HelloWorldPlugin)

Peter Bienstman

unread,
Nov 5, 2012, 3:47:59 AM11/5/12
to mnemosyne-...@googlegroups.com
Strange, the existing script works for me. Perhaps an issue with Qt
versions?

Cheers,

Peter

On 11/02/2012 10:02 PM, Gnome wrote:
> The line
> "QtCore.QObject.connect(self.action_hello,QtCore.SIGNAL("activated()"),
> --
> You received this message because you are subscribed to the Google
> Groups "mnemosyne-proj-users" group.
> To post to this group, send email to mnemosyne-...@googlegroups.com.
> To unsubscribe from this group, send email to
> mnemosyne-proj-u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mnemosyne-proj-users/-/GerIvVm2of4J.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
Peter Bienstman
Ghent University, Dept. of Information Technology
Sint-Pietersnieuwstraat 41, B-9000 Gent, Belgium
tel: +32 9 264 34 46, fax: +32 9 264 35 93
WWW: http://photonics.intec.UGent.be
email: Peter.B...@UGent.be

Gwern Branwen

unread,
Feb 2, 2013, 1:42:25 PM2/2/13
to mnemosyne-...@googlegroups.com
I ran into a similar problem: on ~150 flashcards, I had written
"<sound src=" rather than "<audio src=". Too many to fix by hand. I
think the following `sqlite3 default.db` transcript illustrates how
one could successfully update a deck:

sqlite> .table
card_types data_for_fact global_variables partnerships
cards fact_views log tags
criteria facts media tags_for_card
sqlite>
sqlite> .schema cards
CREATE TABLE cards(
_id integer primary key,
id text,
card_type_id text,
_fact_id integer,
fact_view_id text,

question text,
answer text,
tags text,

grade integer,
next_rep integer,
last_rep integer,
easiness real,
acq_reps integer,
ret_reps integer,
lapses integer,
acq_reps_since_lapse integer,
ret_reps_since_lapse integer,
creation_time integer,
modification_time integer,
extra_data text default "",
scheduler_data integer default 0,
active boolean default 1
);
CREATE INDEX i_cards on cards (id);
CREATE INDEX i_cards_2 on cards (fact_view_id);
CREATE INDEX i_cards_3 on cards (_fact_id);
sqlite>
sqlite> SELECT question FROM cards WHERE question like '%<sound %';
<small><small>define:</small></small> extant (adj.) <sound
src="english/extant_1.ogg"/><sound src="english/extant_2.ogg"/><sound
src="english/extant_3.ogg"/><sound src="english/extant_4.ogg"/><sound
src="english/extant_5.ogg"/>

<small><small>define:</small></small> gamut <sound
src="english/gamut_1.ogg"/><sound src="english/gamut_2.ogg"/><sound
src="english/gamut_3.ogg"/><sound src="english/gamut_4.ogg"/>

<small><small>define:</small></small> glabrous
(<i>/'glæbɹəs/</i>; adj.) <sound src="english/glabrous_1.ogg"/><sound
src="english/glabrous_2.ogg"/><sound src="english/glabrous_3.ogg"/>
...
sqlite>
sqlite> UPDATE cards SET question = replace(question, '<sound', '<audio');
sqlite> SELECT question FROM cards WHERE question like '%<sound%';
sqlite>
sqlite> UPDATE cards SET answer = replace(answer, '<sound', '<audio');
sqlite> SELECT answer FROM cards WHERE answer like '%<sound%';

--
gwern
http://www.gwern.net

Peter Bienstman

unread,
Feb 2, 2013, 4:44:33 PM2/2/13
to mnemosyne-...@googlegroups.com
Note that this will cause the syncing mechanism to get confused. Much better to use Mnemosyne's Python API for that. There is a search and replace example script in the repository.

Cheers,

Peter
Reply all
Reply to author
Forward
0 new messages