1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
# Twisted, the Framework of Your Internet
# Copyright (C) 2001 Matthew W. Lefkowitz
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
I am the support module for making an Mc Foo DJ server with mktap.
"""
from twisted.python import usage
from twisted.internet import reactor
from twisted.cred import service
from twisted.cred.authorizer import DefaultAuthorizer
from twisted.spread import pb
import McFoo.config
import McFoo.score
import McFoo.suggest
import McFoo.playqueue
import McFoo.volume
import McFoo.dj
class Options(usage.Options):
synopsis = "Usage: mktap dj [options] SONGDIR.."
longdesc = "Makes a DJ server."
songdirs=[]
def parseArgs(self, *songdirs):
self.songdirs=songdirs
def postOptions(self):
if not self.songdirs:
raise usage.error, "wrong number of arguments."
port=McFoo.config.store.port
def opt_port(self, opt):
"""set the port to listen on
"""
try:
self.port = int(opt)
except ValueError:
raise usage.error("Invalid argument to 'port'!")
opt_p = opt_port
class SaveService(service.Service):
interval = 60
def startService(self):
reactor.callLater(self.interval, self.save)
def save(self):
self.application.save(tag='snapshot')
reactor.callLater(self.interval, self.save)
def updateApplication(app, config):
profileTable=McFoo.score.ProfileTable()
filler=McFoo.suggest.Suggestions(config.songdirs, profileTable)
playqueue = McFoo.playqueue.PlayQueue(filler.get)
volume = McFoo.volume.VolumeControl()
auth = DefaultAuthorizer()
auth.setApplication(app)
dj=McFoo.dj.Dj(app, auth,
playqueue, volume, profileTable)
perspective=dj.getPerspectiveNamed("guest")
perspective.setService(dj)
perspective.makeIdentity("guest")
portno = config.port
prot = pb.BrokerFactory(pb.AuthRoot(auth))
app.listenTCP(portno, prot)
SaveService("save", app, auth)
|