+def default_config(encoding="UTF-8"):
+ """Write the default config"""
+ open("%s/config" % testroot, "w").write(
+ """home %s/home
+collection fs %s %s/tracks
+scratch %s/scratch.ogg
+queue_pad 5
+stopword 01 02 03 04 05 06 07 08 09 10
+stopword 1 2 3 4 5 6 7 8 9
+stopword 11 12 13 14 15 16 17 18 19 20
+stopword 21 22 23 24 25 26 27 28 29 30
+stopword the a an and to too in on of we i am as im for is
+username fred
+password fredpass
+plugins
+plugins %s/plugins
+plugins %s/plugins/.libs
+player *.mp3 execraw disorder-decode
+player *.ogg execraw disorder-decode
+player *.wav execraw disorder-decode
+player *.flac execraw disorder-decode
+tracklength *.mp3 disorder-tracklength
+tracklength *.ogg disorder-tracklength
+tracklength *.wav disorder-tracklength
+tracklength *.flac disorder-tracklength
+api rtp
+broadcast 127.0.0.1 %d
+broadcast_from 127.0.0.1 %d
+mail_sender no.such.user.sorry@greenend.org.uk
+""" % (testroot, encoding, testroot, testroot, top_builddir, top_builddir,
+ port, port + 1))
+
+def common_setup():
+ remove_dir(testroot)
+ os.mkdir(testroot)
+ # Choose a port
+ global port
+ port = random.randint(49152, 65530)
+ while not bindable(port + 1):
+ print "port %d is not bindable, trying another" % (port + 1)
+ port = random.randint(49152, 65530)
+ # Log anything sent to that port
+ packetlog = "%s/packetlog" % testroot
+ subprocess.Popen(["disorder-udplog",
+ "--output", packetlog,
+ "127.0.0.1", "%d" % port])
+ # disorder-udplog will quit when its parent process terminates
+ copyfile("%s/sounds/scratch.ogg" % top_srcdir,
+ "%s/scratch.ogg" % testroot)
+ default_config()
+
+def start_daemon():
+ """start_daemon()
+
+Start the daemon."""
+ global daemon, errs, port
+ assert daemon == None, "no daemon running"
+ if not bindable(port + 1):
+ print "waiting for port %d to become bindable again..." % (port + 1)
+ time.sleep(1)
+ while not bindable(port + 1):
+ time.sleep(1)