chiark / gitweb /
Synchronize with disorder.dev
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 May 2008 12:18:17 +0000 (13:18 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 May 2008 12:18:17 +0000 (13:18 +0100)
14 files changed:
python/disorder.py.in
server/server.c
tests/Makefile.am
tests/aliases.py [new file with mode: 0755]
tests/cookie.py
tests/dbversion.py
tests/dump.py
tests/files.py
tests/play.py
tests/queue.py
tests/recode.py
tests/search.py
tests/user-upgrade.py
tests/user.py

index 595ee9254ea324cbbc0272a4e0f73d9bd2cdfe04..23f840cccd1749de5746627c3e34566a2676d103 100644 (file)
@@ -62,8 +62,8 @@ _userconf = True
 
 # various regexps we'll use
 _ws = re.compile(r"^[ \t\n\r]+")
-_squote = re.compile("'(([^\\\\']|\\\\[\\\\\"'n])+)'")
-_dquote = re.compile("\"(([^\\\\\"]|\\\\[\\\\\"'n])+)\"")
+_squote = re.compile("'(([^\\\\']|\\\\[\\\\\"'n])*)'")
+_dquote = re.compile("\"(([^\\\\\"]|\\\\[\\\\\"'n])*)\"")
 _unquoted = re.compile("[^\"' \\t\\n\\r][^ \t\n\r]*")
 
 _response = re.compile("([0-9]{3}) ?(.*)")
index 3d593987264018a1b0a9e6b4aafa62f83a1ee0b1..fd0fcd884ed29977d025beaeca07bc3ccff2a707 100644 (file)
@@ -614,9 +614,13 @@ static int c_allfiles(struct conn *c,
 static int c_get(struct conn *c,
                 char **vec,
                 int attribute((unused)) nvec) {
-  const char *v;
+  const char *v, *track;
 
-  if(vec[1][0] != '_' && (v = trackdb_get(vec[0], vec[1])))
+  if(!(track = trackdb_resolve(vec[0]))) {
+    sink_writes(ev_writer_sink(c->w), "550 cannot resolve track\n");
+    return 1;
+  }
+  if(vec[1][0] != '_' && (v = trackdb_get(track, vec[1])))
     sink_printf(ev_writer_sink(c->w), "252 %s\n", quoteutf8(v));
   else
     sink_writes(ev_writer_sink(c->w), "555 not found\n");
@@ -642,7 +646,13 @@ static int c_length(struct conn *c,
 static int c_set(struct conn *c,
                 char **vec,
                 int attribute((unused)) nvec) {
-  if(vec[1][0] != '_' && !trackdb_set(vec[0], vec[1], vec[2]))
+  const char *track;
+
+  if(!(track = trackdb_resolve(vec[0]))) {
+    sink_writes(ev_writer_sink(c->w), "550 cannot resolve track\n");
+    return 1;
+  }
+  if(vec[1][0] != '_' && !trackdb_set(track, vec[1], vec[2]))
     sink_writes(ev_writer_sink(c->w), "250 OK\n");
   else
     sink_writes(ev_writer_sink(c->w), "550 not found\n");
@@ -653,8 +663,13 @@ static int c_prefs(struct conn *c,
                   char **vec,
                   int attribute((unused)) nvec) {
   struct kvp *k;
+  const char *track;
 
-  k = trackdb_get_all(vec[0]);
+  if(!(track = trackdb_resolve(vec[0]))) {
+    sink_writes(ev_writer_sink(c->w), "550 cannot resolve track\n");
+    return 1;
+  }
+  k = trackdb_get_all(track);
   sink_writes(ev_writer_sink(c->w), "253 prefs follow\n");
   for(; k; k = k->next)
     if(k->name[0] != '_')              /* omit internal values */
@@ -667,6 +682,7 @@ static int c_prefs(struct conn *c,
 static int c_exists(struct conn *c,
                    char **vec,
                    int attribute((unused)) nvec) {
+  /* trackdb_exists() does its own alias checking */
   sink_printf(ev_writer_sink(c->w), "252 %s\n", noyes[trackdb_exists(vec[0])]);
   return 1;
 }
@@ -931,8 +947,14 @@ static int c_moveafter(struct conn *c,
 static int c_part(struct conn *c,
                  char **vec,
                  int attribute((unused)) nvec) {
+  const char *track;
+
+  if(!(track = trackdb_resolve(vec[0]))) {
+    sink_writes(ev_writer_sink(c->w), "550 cannot resolve track\n");
+    return 1;
+  }
   sink_printf(ev_writer_sink(c->w), "252 %s\n",
-             quoteutf8(trackdb_getpart(vec[0], vec[1], vec[2])));
+             quoteutf8(trackdb_getpart(track, vec[1], vec[2])));
   return 1;
 }
 
index 6795672a9a23909e8656319306b5b232a15ff68f..d21edcbdbd57fd0c106d7a10d44273dfd5df4524 100644 (file)
@@ -27,10 +27,11 @@ disorder_udplog_LDADD=$(LIBOBJS) ../lib/libdisorder.a
 disorder_udplog_DEPENDENCIES=../lib/libdisorder.a
 
 TESTS=cookie.py dbversion.py dump.py files.py play.py queue.py \
-       recode.py search.py user-upgrade.py user.py
+       recode.py search.py user-upgrade.py user.py aliases.py
+
+TESTS_ENVIRONMENT=${PYTHON} -u
 
 clean-local:
        rm -rf testroot *.log *.pyc
 
-EXTRA_DIST=dtest.py dbversion.py search.py \
-       queue.py dump.py play.py cookie.py user-upgrade.py user.py recode.py
+EXTRA_DIST=dtest.py ${TESTS}
diff --git a/tests/aliases.py b/tests/aliases.py
new file mode 100755 (executable)
index 0000000..6ff74d8
--- /dev/null
@@ -0,0 +1,70 @@
+#! /usr/bin/env python -u
+#
+# This file is part of DisOrder.
+# Copyright (C) 2008 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,disorder
+
+def test():
+    """Exercise alias logic"""
+    dtest.start_daemon()
+    dtest.create_user()
+    dtest.rescan()
+    c = disorder.client()
+
+    print " creating an alias in new directory"
+    track = "%s/misc/blahblahblah.ogg" % dtest.tracks
+    c.set(track,
+          "trackname_display_artist",
+          "Fred Smith")
+    c.set(track,
+          "trackname_display_album",
+          "wibble")
+
+    print " checking it shows up in the right place"
+    alias = "%s/Fred Smith/wibble/blahblahblah.ogg" % dtest.tracks
+    files = c.files("%s/Fred Smith/wibble" % dtest.tracks)
+    assert files == [alias]
+
+    print " checking part calculation"
+    artist = c.part(track, "display", "artist")
+    assert artist == "Fred Smith", "checking artist part"
+    album = c.part(track, "display", "album")
+    assert album == "wibble", "checking album part"
+    title = c.part(track, "display", "title")
+    assert title == "blahblahblah", "checking title part"
+
+    print " checking part calculation on alias"
+    artist = c.part(alias, "display", "artist")
+    assert artist == "Fred Smith", "checking artist part"
+    album = c.part(alias, "display", "album")
+    assert album == "wibble", "checking album part"
+    title = c.part(alias, "display", "title")
+    assert title == "blahblahblah", "checking title part"
+
+    # See defect #20
+    print " checking that prefs always belong to the canonical name"
+    c.set(alias, "wibble", "spong")
+    value = c.get(track, "wibble")
+    assert value == "spong", "checking pref ended up on resolved track"
+    c.set(track, "foo", "bar")
+    value = c.get(alias, "foo")
+    assert value == "bar", "checking pref visible via alias"
+
+if __name__ == '__main__':
+    dtest.run()
index 21353b08a8eeb24dff9d53f8805147c6c7c8ed3b..8a9182977286011d0d67fc1ee03295f607f889d1 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2007 Richard Kettlewell
index c93e1e8e4d33f1f470086f41c6c516e0ca6a3679..218e0c9023056442f3cad13539c2859e5fb185c9 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2007, 2008 Richard Kettlewell
index c935f204d46bf4d8d52d25f92b9d141212d00343..ff28a0ffc32001c3187f723dbd546f22e4a1dd41 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2007, 2008 Richard Kettlewell
index 65211dc16d6ee24e5389c4a6fea6c9cae7dfa883..984c6cca89dd839d05e26f10112aada72b96a592 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2007, 2008 Richard Kettlewell
index 35cc7a3fa384881d57db1d21c48796bdb1a5d7f5..0013d7e3e62b420d4c0b496ffa3d598e1a2c0000 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2007, 2008 Richard Kettlewell
index a1ddedfe8217f8656ff6a88b4d90e2eb45a671d6..dae37b47d473206d825940eb4e7c55796a6e5dbe 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2007, 2008 Richard Kettlewell
index d57db022445ac10811b3ab3ef1136186ecd676b9..2878e68fe62c00f3ba0e7e8a612af56f1a04a3db 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2008 Richard Kettlewell
index 556a24c4ad798809f1fdbd7835e638caf8c30dae..5e3d2008c7deb0d8231a48810905844816e7495a 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2007, 2008 Richard Kettlewell
index ffd30ea2d15ad46810302c86d5662701ea80c86a..d35e4f6adf1771d17477f8f3889ae7c2ad629952 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2007, 2008 Richard Kettlewell
index 4c4fa4884cd1051938e6d1f361972b857eb639f4..ffc1fdca7340e329279b93075ea35d23672ec4a0 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -u
+#! /usr/bin/env python
 #
 # This file is part of DisOrder.
 # Copyright (C) 2007, 2008 Richard Kettlewell