understands this and returns None.
Further tests and fixes for disorder-dump.
.B get \fITRACK\fR \fIPREF\fR
Gets a preference value. On success the second field of the response line will
have the value.
+.IP
+If the track or preference do not exist then the response code is 555.
.TP
.B get-global \fIKEY\fR
Get a global preference.
+.IP
+If the preference does not exist then the response code is 555.
.TP
.B length \fITRACK\fR
Gets the length of the track in seconds. On success the second field of the
Text part is just commentary; an indefinite dot-stuffed body follows. (Used
for \fBlog\fR.)
.TP
+.B 5
+Used with "normal" errors, for instance a preference not being found. The text
+part is commentary.
+.TP
.B 9
The text part is just commentary (but would normally be a response for this
command) e.g. \fBplaying\fR.
The return value is the preference
"""
ret, details = self._simple("get", track, key)
- return details
+ if ret == 555:
+ return None
+ else:
+ return details
def prefs(self, track):
"""Get all the preferences for a track.
The return value is the preference
"""
ret, details = self._simple("get-global", key)
- return details
+ if ret == 555:
+ return None
+ else:
+ return details
########################################################################
# I/O infrastructure
#
# If an I/O error occurs, disconnect from the server.
#
- # On success returns response as a (code, details) tuple
+ # On success or 'normal' errors returns response as a (code, details) tuple
#
# On error raise operationError
if self.state == 'disconnected':
else:
cmd = None
res, details = self._response()
- if res / 100 == 2:
+ if res / 100 == 2 or res == 555:
return res, details
raise operationError(res, details, cmd)
if(fseek(fp, 0, SEEK_SET) < 0)
fatal(errno, "error calling fseek on %s", tag);
if((err = truncdb(tid, trackdb_prefsdb))) return err;
+ if((err = truncdb(tid, trackdb_globaldb))) return err;
if((err = truncdb(tid, trackdb_searchdb))) return err;
+ if((err = truncdb(tid, trackdb_tagsdb))) return err;
c = getc(fp);
while(!ferror(fp) && !feof(fp)) {
switch(c) {
if(vec[1][0] != '_' && (v = trackdb_get(vec[0], vec[1])))
sink_printf(ev_writer_sink(c->w), "252 %s\n", v);
else
- sink_writes(ev_writer_sink(c->w), "550 not found\n");
+ sink_writes(ev_writer_sink(c->w), "555 not found\n");
return 1;
}
if(s)
sink_printf(ev_writer_sink(c->w), "252 %s\n", s);
else
- sink_writes(ev_writer_sink(c->w), "550 not found\n");
+ sink_writes(ev_writer_sink(c->w), "555 not found\n");
return 1;
}
print "changing global pref"
c.setglobal("foo", "after");
assert c.getglobal("foo") == "after", "checking global foo=before"
+ print "adding fresh track pref"
+ c.set(track, "bar", "after")
+ print "adding fresh global pref"
+ c.setglobal("bar", "after")
dtest.stop_daemon();
print "restoring database"
print dtest.command(["disorder-dump", "--config", disorder._configfile,
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"
+ print "checking fresh track pref"
+ assert c.get(track, "bar") is None, "checking fresh track pref has gone"
+ print "checking fresh global pref"
+ assert c.getglobal("bar") is None, "checking fresh global pref has gone"
if __name__ == '__main__':
dtest.run()