1
# -*- coding: utf-8 -*-
3
# Author: Ingelrest François (Francois.Ingelrest@gmail.com)
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU Library General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
import dbus, os.path, sys, tools.consts
21
(CMD_ARGS, CMD_HELP, CMD_MSG) = range(3)
24
'play': ( '', 'Start playing the current track', tools.consts.MSG_CMD_TOGGLE_PAUSE ),
25
'pause': ( '', 'Pause or continue playing the current track', tools.consts.MSG_CMD_TOGGLE_PAUSE ),
26
'next': ( '', 'Jump to the next track', tools.consts.MSG_CMD_NEXT ),
27
'prev': ( '', 'Jump to the previous track', tools.consts.MSG_CMD_PREVIOUS ),
28
'stop': ( '', 'Stop playback', tools.consts.MSG_CMD_STOP ),
29
'pl-set': ( 'file1 file2...', 'Set the playlist to the given files', tools.consts.MSG_CMD_TRACKLIST_SET ),
30
'pl-add': ( 'file1 file2...', 'Append the given files to the playlist', tools.consts.MSG_CMD_TRACKLIST_ADD ),
31
'pl-clr': ( '', 'Clear the playlist', tools.consts.MSG_CMD_TRACKLIST_CLR ),
32
'shuffle': ( '', 'Shuffle the playlist', tools.consts.MSG_CMD_TRACKLIST_SHUFFLE ),
33
'volume': ( 'value (0 -- 100)', 'Set the volume', tools.consts.MSG_CMD_SET_VOLUME ),
36
# Check the command line
42
if cmdName not in commands: print '%s is not a valid command\n' % cmdName
43
elif len(sys.argv) == 2 and commands[cmdName][CMD_ARGS] != '': print '%s needs some arguments\n' % cmdName
44
elif len(sys.argv) > 2 and commands[cmdName][CMD_ARGS] == '': print '%s does not take any argument\n' % cmdName
45
else: cmdLineOk = True
48
print 'Usage: %s command [arg1 arg2...]\n' % os.path.basename(sys.argv[0])
49
print 'Command | Arguments | Description'
50
print '-----------------------------------------------------------------------'
51
for cmd, data in sorted(commands.iteritems()):
52
print '%s| %s| %s' % (cmd.ljust(9), data[CMD_ARGS].ljust(17), data[CMD_HELP])
55
# Get a valid D-Bus interface
56
session = dbus.SessionBus()
57
activeServices = session.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus').ListNames()
59
if not tools.consts.dbusService in activeServices:
60
print '%s is not running, or D-Bus support is not available' % tools.consts.appName
63
remoteObject = session.get_object(tools.consts.dbusService, tools.consts.dbusObject)
64
remoteInterface = dbus.Interface(remoteObject, tools.consts.dbusInterface)
67
if not remoteInterface.sendMsg(commands[cmdName][CMD_MSG], sys.argv[2:]):
68
print '%s returned an error' % tools.consts.appName