/
ivysync-remote.py
executable file
·129 lines (83 loc) · 3.43 KB
/
ivysync-remote.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/python
# python xmlrpc client for ivysync
# (C)2006 by Denis "Jaromil" Rojo
# released under the GNU General Public License
# general system functions
import sys
from string import atoi
# xmlrpclib client functions
from socket import gethostname
from xmlrpclib import Transport, dumps
######################################################################
# XMLRPC Client connection class
class xmlrpc_connection:
"""The xmlrpc_connection class tests the xmlrpc_server. You must
download and install the medusa and xmlrpclib libraries to run
this code: http://www.nightmare.com http://www.pythonware.com"""
def __init__(self, host=None, port=2640):
if host is None:
host = gethostname()
self.host = "%s:%s" % (host, port)
self.transport = Transport()
def remote(self, method, params=()):
"""remote invokes the server with the method name and an
optional set of parameters. The return value is always a
tuple."""
response = self.transport.request(self.host,
'/RPC2',
dumps(params, method))
return response
###################################################################
###################################################################
## MAIN
if __name__ == '__main__':
commands = ("Play", "Stop", "Open", "Pause", "Quit", "GetPos", "SetPos", "GetOffset", "SetOffset")
connection = xmlrpc_connection()
# if(sys.argc):
# cmd = "none"
# else:
cmd = sys.argv[1]
if not cmd in commands:
print "no valid command recognized, list of valid commands:"
print commands
sys.exit(2)
if cmd == "Quit":
(res,) = connection.remote(cmd, (0, 0))
if res == 1:
answer = "Server is now quitting"
else:
answer = "Server refuses to quit"
elif cmd == "SetPos":
chan = int( sys.argv[2] )
pos = int( sys.argv[3] )
(res,) = connection.remote(cmd, (chan, pos))
answer = "Channel " + str(chan) + " is now at " + str(pos) + "%"
elif cmd == "SetOffset":
chan = int( sys.argv[2] )
pos = int( sys.argv[3] )
(res,) = connection.remote(cmd, (chan, pos))
answer = "Channel " + str(chan) + " is now at " + str(pos) + " byte offset"
elif cmd == "GetPos":
chan = int( sys.argv[2] )
(res,) = connection.remote(cmd, (chan, 0))
answer = "Channel " + str(chan) + " is now at " + str(res) + "%"
elif cmd == "GetOffset":
chan = int( sys.argv[2] )
(res,) = connection.remote(cmd, (chan, 0))
answer = "Channel " + str(chan) + " is now at " + str(res) + " byte offset"
elif cmd == "Open":
chan = int(sys.argv[2] )
path = str(sys.argv[3] )
(res,) = connection.remote(cmd, (chan, path))
if res == 1:
answer = "File " + path + " opened on channel " + str(chan)
else:
answer = "Error opening file " + path
else: # all other commands needing only one argument (channel num)
chan = int( sys.argv[2] )
(res,) = connection.remote(cmd, (chan, 0))
if res == 1:
answer = "Command '" + cmd + "' succesfully executed on channel " + str(chan)
else:
answer = "Error executing command '" + cmd + "' on channel " + str(chan)
print answer # 42! ;D