ret, details = self._simple("part", track, context, part)
return details
+ def setglobal(self, key, value):
+ """Set a global preference value.
+
+ Arguments:
+ key -- the preference name
+ value -- the new preference value
+ """
+ self._simple("set-global", key, value)
+
+ def unsetglobal(self, key):
+ """Unset a global preference value.
+
+ Arguments:
+ key -- the preference to remove
+ """
+ self._simple("set-global", key, value)
+
+ def getglobal(self, key):
+ """Get a global preference value.
+
+ Arguments:
+ key -- the preference to look up
+
+ The return value is the preference
+ """
+ ret, details = self._simple("get-global", key)
+ return details
+
########################################################################
# I/O infrastructure
fatal(errno, "error calling ftruncate");
if(fprintf(fp, "V%c\n", (tracksdb || searchdb) ? '1' : '0') < 0)
fatal(errno, "error writing to %s", tag);
+ /* dump the preferences */
cursor = trackdb_opencursor(trackdb_prefsdb, tid);
err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d),
DB_FIRST);
if(trackdb_closecursor(cursor)) { cursor = 0; goto fail; }
cursor = 0;
+ /* dump the global preferences */
+ cursor = trackdb_opencursor(trackdb_globaldb, tid);
+ err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d),
+ DB_FIRST);
+ while(err == 0) {
+ if(fputc('G', fp) < 0
+ || urlencode(s, k.data, k.size)
+ || fputc('\n', fp) < 0
+ || urlencode(s, d.data, d.size)
+ || fputc('\n', fp) < 0)
+ fatal(errno, "error writing to %s", tag);
+ err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d),
+ DB_NEXT);
+ }
+ if(trackdb_closecursor(cursor)) { cursor = 0; goto fail; }
+ cursor = 0;
+
if(tracksdb) {
cursor = trackdb_opencursor(trackdb_tracksdb, tid);
err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d),
static int undump_from_fp(DB_TXN *tid, FILE *fp, const char *tag) {
int err, c;
DBT k, d;
+ const char *which_name;
+ DB *which_db;
info("undumping");
if(fseek(fp, 0, SEEK_SET) < 0)
case 'E':
return 0;
case 'P':
+ case 'G':
+ if(c == 'P') {
+ which_db = trackdb_prefsdb;
+ which_name = "prefs.db";
+ } else {
+ which_db = trackdb_globaldb;
+ which_name = "global.db";
+ }
if(undump_dbt(fp, tag, prepare_data(&k))
|| undump_dbt(fp, tag, prepare_data(&d)))
break;
- switch(err = trackdb_prefsdb->put(trackdb_prefsdb, tid, &k, &d, 0)) {
+ switch(err = trackdb_prefsdb->put(which_db, tid, &k, &d, 0)) {
case 0:
break;
case DB_LOCK_DEADLOCK:
- error(0, "error updating prefs.db: %s", db_strerror(err));
+ error(0, "error updating %s: %s", which_name, db_strerror(err));
return err;
default:
- fatal(0, "error updating prefs.db: %s", db_strerror(err));
+ fatal(0, "error updating %s: %s", which_name, db_strerror(err));
}
break;
case 'T':
${PYTHON} ${srcdir}/alltests
EXTRA_DIST=alltests dtest.py nothing.py version.py dbversion.py search.py \
- queue.py
+ queue.py dump.py
--- /dev/null
+#! /usr/bin/env python
+#
+# This file is part of DisOrder.
+# Copyright (C) 2007 Richard Kettlewell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+#
+import dtest,time,disorder,re
+
+def test():
+ """Exercise database dumper"""
+ dtest.start_daemon()
+ c = disorder.client()
+ track = "%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
+ dump = "%s/dumpfile" % dtest.testroot
+ print "setting a track pref"
+ c.set(track, "foo", "before")
+ assert c.get(track, "foo") == "before", "checking track foo=before"
+ print "setting a global pref"
+ c.setglobal("foo", "before");
+ assert c.getglobal("foo") == "before", "checking global foo=before"
+ print "dumping database"
+ print dtest.command(["disorder-dump", "--config", disorder._configfile,
+ "--dump", dump])
+ print "changing track pref"
+ c.set(track, "foo", "after");
+ assert c.get(track, "foo") == "after", "checking track foo=before"
+ print "changing global pref"
+ c.setglobal("foo", "after");
+ assert c.getglobal("foo") == "after", "checking global foo=before"
+ dtest.stop_daemon();
+ print "restoring database"
+ print dtest.command(["disorder-dump", "--config", disorder._configfile,
+ "--undump", dump])
+ dtest.start_daemon();
+ c = disorder.client()
+ print "checking track pref"
+ assert c.get(track, "foo") == "before", "checking track foo=before after undump"
+ print "checking global pref"
+ assert c.getglobal("foo") == "before", "checking global foo=before after undump"
+
+if __name__ == '__main__':
+ dtest.run()