get and get-global now return 555 for not found. The Python interface
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 2 Dec 2007 12:04:26 +0000 (12:04 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 2 Dec 2007 12:04:26 +0000 (12:04 +0000)
understands this and returns None.

Further tests and fixes for disorder-dump.

doc/disorder_protocol.5.in
python/disorder.py.in
server/dump.c
server/server.c
tests/dump.py

index bf293e9..b98c0f5 100644 (file)
@@ -83,9 +83,13 @@ If \fIREGEXP\fR is present only matching files are returned.
 .B get \fITRACK\fR \fIPREF\fR
 Gets a preference value.  On success the second field of the response line will
 have the value.
 .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.
 .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
 .TP
 .B length \fITRACK\fR
 Gets the length of the track in seconds.  On success the second field of the
@@ -293,6 +297,10 @@ Text part is just commentary; a dot-stuffed body follows.
 Text part is just commentary; an indefinite dot-stuffed body follows.  (Used
 for \fBlog\fR.)
 .TP
 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.
 .B 9
 The text part is just commentary (but would normally be a response for this
 command) e.g. \fBplaying\fR.
index 01b92ed..2ad2b44 100644 (file)
@@ -585,7 +585,10 @@ class client:
     The return value is the preference 
     """
     ret, details = self._simple("get", track, key)
     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.
 
   def prefs(self, track):
     """Get all the preferences for a track.
@@ -781,7 +784,10 @@ class client:
     The return value is the preference 
     """
     ret, details = self._simple("get-global", key)
     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
 
   ########################################################################
   # I/O infrastructure
@@ -837,7 +843,7 @@ class client:
     #
     # If an I/O error occurs, disconnect from the server.
     #
     #
     # 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':
     #
     # On error raise operationError
     if self.state == 'disconnected':
@@ -847,7 +853,7 @@ class client:
     else:
       cmd = None
     res, details = self._response()
     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)
 
       return res, details
     raise operationError(res, details, cmd)
 
index 9363a34..7e49111 100644 (file)
@@ -281,7 +281,9 @@ static int undump_from_fp(DB_TXN *tid, FILE *fp, const char *tag) {
   if(fseek(fp, 0, SEEK_SET) < 0)
     fatal(errno, "error calling fseek on %s", tag);
   if((err = truncdb(tid, trackdb_prefsdb))) return err;
   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_searchdb))) return err;
+  if((err = truncdb(tid, trackdb_tagsdb))) return err;
   c = getc(fp);
   while(!ferror(fp) && !feof(fp)) {
     switch(c) {
   c = getc(fp);
   while(!ferror(fp) && !feof(fp)) {
     switch(c) {
index c8b4a62..5d88db4 100644 (file)
@@ -580,7 +580,7 @@ static int c_get(struct conn *c,
   if(vec[1][0] != '_' && (v = trackdb_get(vec[0], vec[1])))
     sink_printf(ev_writer_sink(c->w), "252 %s\n", v);
   else
   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;
 }
 
   return 1;
 }
 
@@ -924,7 +924,7 @@ static int c_get_global(struct conn *c,
   if(s)
     sink_printf(ev_writer_sink(c->w), "252 %s\n", s);
   else
   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;
 }
 
   return 1;
 }
 
index 99d29b6..d308b84 100755 (executable)
@@ -41,6 +41,10 @@ def test():
     print "changing global pref"
     c.setglobal("foo", "after");
     assert c.getglobal("foo") == "after", "checking global foo=before"
     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,
     dtest.stop_daemon();
     print "restoring database"
     print dtest.command(["disorder-dump", "--config", disorder._configfile,
@@ -51,6 +55,10 @@ def test():
     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"
     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()
 
 if __name__ == '__main__':
     dtest.run()