Beispiel #1
0
    def __init__(self, conn=None, output=None, after_status=None):
        """Initialize class.
        conn is an mpd.MPDClient() instance, if None a new one will be created.
        if output is False, no output is printed (used by mpd console)
        if after_status is True, commands like clear, next, previous will call
        status() after execution to print status."""
        if conn:
            self.mpc = conn
        else:
            self.mpc = SmartMPDClient()

        if after_status is not None:
            self.after_status = after_status
        elif config_data.has_option("ui", "after_status"):
            self.after_status = config_data.getboolean("ui", "after_status")
        else:
            self.after_status = True

        if output is not None:
            self.output = output
        elif config_data.has_option("console", "output"):
            self.output = config_data.getboolean("console", "output")
        else:
            self.output = True

        # Commands with common argument & return values
        self._common_commands = {
                "commands" : "commands",
                "notcommands" : "notcommands",
                "outputs" : "outputs",
                "stats" : "stats",
                "tagtypes" : "tagtypes",
                "urlhandlers" : "urlhandlers",
                "list" : "results",
                "listall" : "results",
                "listallinfo" : "results",
                "listplaylist" : "results",
                "listplaylistinfo" : "results",
                "lsinfo" : "results",
                "currentsong" : "song",
                "plchangesposid" : "results",
                }
        # Commands that return none
        # Template is rendered before real function is called.
        self._none_commands = ["deleteid", "kill", "load", "rename", "move",
                "moveid", "rm", "save", "swap", "swapid", "playlistadd",
                "playlistclear", "playlistdelete", "playlistmove",]
        # Search commands
        self._search_commands = ["count", "find", "search", "playlistfind",
                "playlistsearch",]
        # Commands that print status after execution.
        self._status_commands = ["clear", "shuffle", "next", "play", "playid",
                "previous", "stop",]
Beispiel #2
0
    def __init__(self):
        """Initialize defaults."""
        if config_data.has_option("console", "ping"):
            self.__ping = config_data.getboolean("console", "ping")
        else:
            self.__ping = True

        if config_data.has_option("console", "ping_interval"):
            self.__ping_interval = config_data.getint("console", "ping_interval")
        else:
            self.__ping_interval = 50

        if config_data.has_option("console", "return"):
            self.__ret = config_data.getboolean("console", "return")
        else:
            self.__ret = False
Beispiel #3
0
    def connect(self, host=None, port=None):
        if host is not None:
            mpd_host = host
        elif "MPD_HOST" in os.environ:
            mpd_host = os.environ["MPD_HOST"]
        elif config_data.has_option("mpd", "host"):
            mpd_host = config_data.get("mpd", "host")
        else:
            mpd_host = "localhost"

        if port is not None:
            mpd_port = port
        elif "MPD_PORT" in os.environ:
            mpd_port = int(os.environ["MPD_PORT"])
        elif config_data.has_option("mpd", "port"):
            mpd_port = config_data.getint("mpd", "port")
        else:
            mpd_port = 6600

        self.mpc.connect(mpd_host, mpd_port)
Beispiel #4
0
 def authenticate(self, funcname):
     """authenticate with the server if not allowed to execute funcname."""
     if funcname in self.mpd_notcommands:
         authfunc = self.__super.__getattr__("password")
         if config_data.has_option("mpd", "password"):
             authfunc(config_data.get("mpd", "password"))
         else:
             import getpass
             printByName("askpass", command=funcname)
             authfunc(getpass.getpass(_("Password: "******"notcommands")()
Beispiel #5
0
from mako.template import Template
from mako.lookup import TemplateLookup

from boogie.config import config_data, template_dir
from boogie.i18n import _

template_dirs = [template_dir]

cache_dir = os.path.join(template_dir, "cache")
if not os.path.exists(cache_dir):
    os.makedirs(cache_dir)

template_dirs.append(__path__[0])

# Encoding
if config_data.has_option("template", "input_encoding"):
    input_encoding = config_data.get_option("template", "input encoding")
    input_encoding = input_encoding.lower()
else:
    input_encoding = "utf-8"

if config_data.has_option("template", "output_encoding"):
    output_encoding = config_data.get_option("template", "output_encoding")
    output_encoding = output_encoding.lower()
else:
    output_encoding = "utf-8"

if input_encoding == "utf-8":
    default_filters = ["decode.utf8"]
else:
    default_filters = ["unicode"]