Permalink
Browse files

prepared code for favorite-groups

  • Loading branch information...
wendlers committed Sep 28, 2012
1 parent 1ed6899 commit 559bd3df1a2facf988a9f81bbab7ea763be28533
Showing with 53 additions and 28 deletions.
  1. +10 −1 etc/pyscmpd.conf
  2. +29 −17 src/pyscmpd/daemon.py
  3. +3 −1 src/pyscmpd/pyscmpdctrl.py
  4. +2 −2 src/pyscmpd/scmpd.py
  5. +9 −7 src/pyscmpd/scprovider.py
View
@@ -26,10 +26,19 @@ file=/tmp/pyscmpd.log
#
# format: <category>: <user1>, <user2>, ...
##
-[favorites]
+[favorite-users]
electroswing : shemian
gethoswing : maddecent, barelylegit
electrosoul : griz
deephouse : freudeamtanzen, adriatique
worldtrance : gogmusic
+
+##
+# Favorite groups
+#
+# format: groups: <group1>, <user2>, ...
+##
+[favorite-groups]
+
+groups: deep-house-4, minimal-tech-house
View
@@ -38,22 +38,26 @@
class PyScMpd:
- stdin = None
- stdout = None
- stderr = None
- pidfile = None
- mpd = None
- mainloop = None
- favorites = None
- port = 9900
+ stdin = None
+ stdout = None
+ stderr = None
+ pidfile = None
+ mpd = None
+ mainloop = None
+ port = 9900
+
+ favoriteUsers = None
+ favoriteGroups = None
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
- self.stdin = stdin
- self.stdout = stdout
- self.stderr = stderr
- self.pidfile = pidfile
- self.favorites = []
+ self.stdin = stdin
+ self.stdout = stdout
+ self.stderr = stderr
+ self.pidfile = pidfile
+
+ self.favoriteUsers = []
+ self.favoriteGroups = []
def daemonize(self):
@@ -219,17 +223,25 @@ def readConfig(self, cfgFile, foreground=False):
sys.stdout.write("Logging to file: %s\n" % logFile)
- if parser.has_section("favorites"):
+ if parser.has_section("favorite-users"):
- for category, values in parser.items("favorites"):
+ for category, values in parser.items("favorite-users"):
usersRaw = values.split(",")
users = []
for user in usersRaw:
users.append(user.strip())
- self.favorites.append({"name" : category.strip(), "users" : users})
+ self.favoriteUsers.append({"name" : category.strip(), "users" : users})
+
+ if parser.has_option("favorite-groups", "groups"):
+
+ groupsRaw = parser.get("favorite-groups", "groups").split(",")
+ groups = []
+
+ for group in groupsRaw:
+ self.favoriteGroups.append(group.strip())
except Exception as e:
@@ -239,7 +251,7 @@ def readConfig(self, cfgFile, foreground=False):
def run(self):
logging.info("pyscmpd v%s started" % PYSCMPD_VERSION)
- mpd = scmpd.ScMpdServerDaemon(self.favorites, self.port)
+ mpd = scmpd.ScMpdServerDaemon(self.favoriteUsers, self.favoriteGroups, self.port)
self.mainloop = gobject.MainLoop()
self.mainloop.run()
@@ -49,9 +49,11 @@ def prepare():
f.write("\n[logging]\n")
f.write("level=info\n")
f.write("file=%s\n" % DEF_LOG_FILE)
- f.write("\n[favorites]\n")
+ f.write("\n[favorite-users]\n")
f.write("gethoswing : maddecent, barelylegit\n")
f.write("electrosoul: griz\n")
+ f.write("\n[favorite-groups]\n")
+ f.write("groups: deep-house-4, minimal-tech-hous\n")
f.close()
try:
View
@@ -34,10 +34,10 @@ class ScMpdServerDaemon(mpdserver.MpdServerDaemon):
scroot = None
player = None
- def __init__(self, favorites, serverPort = 9900):
+ def __init__(self, favoriteUsers, favoriteGroups, serverPort = 9900):
ScMpdServerDaemon.player = gstplayer.GstPlayer()
- ScMpdServerDaemon.scp = provider.ResourceProvider(favorites)
+ ScMpdServerDaemon.scp = provider.ResourceProvider(favoriteUsers, favoriteGroups)
ScMpdServerDaemon.scroot = ScMpdServerDaemon.scp.getRoot()
mpdserver.MpdServerDaemon.__init__(self, serverPort)
View
@@ -21,7 +21,6 @@
This file is part of the pyscmpd project.
'''
-import pickle
import logging
import soundcloud
@@ -34,19 +33,19 @@ class ResourceProvider:
sc = None
root = None
- def __init__(self, favorites):
+ def __init__(self, favoriteUsers, favoriteGroups):
ResourceProvider.sc = soundcloud.Client(client_id='aa13bebc2d26491f7f8d1e77ae996a64')
- self.root = Root(favorites)
+ self.root = Root(favoriteUsers, favoriteGroups)
def getRoot(self):
return self.root
class Root(resource.DirectoryResource):
- def __init__(self, favorites):
+ def __init__(self, favoriteUsers, favoriteGroups):
resource.DirectoryResource.__init__(self, 0, "pyscmpd", "pyscmpd")
@@ -56,12 +55,15 @@ def __init__(self, favorites):
ufav = resource.DirectoryResource(0, favgrp ,favgrp )
ufav.setMeta({"directory" : favgrp})
- for fav in favorites:
- f = Favorites(fav["name"], fav["users"], favgrp)
+ for fav in favoriteUsers:
+ f = FavoriteUsers(fav["name"], fav["users"], favgrp)
ufav.addChild(f)
grps = Groups("random-groups")
+ for fav in favoriteGroups:
+ logging.info("Adding favorite group: %s" % fav)
+
self.addChild(ufav)
self.addChild(uall)
self.addChild(grps)
@@ -116,7 +118,7 @@ def retriveChildren(self):
except Exception as e:
logging.warn("Unable to retrive data for URI users: %s" % `e`)
-class Favorites(resource.DirectoryResource):
+class FavoriteUsers(resource.DirectoryResource):
retriveLock = None
users = None

0 comments on commit 559bd3d

Please sign in to comment.