#!/usr/bin/python # Force MythTV to reschedule. # Adam Sampson import socket def receive_myth(sock): ret = "" count = int(sock.recv(8)) while count > 0: data = sock.recv(65536) ret += data count -= len(data) return ret def send_myth(sock, req): msg = "%-8d%s" % (len(req), req) sock.send(msg) def request(sock, req): send_myth(sock, req) return receive_myth(sock) def main(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('localhost', 6543)) reply = request(s, "MYTH_PROTO_VERSION 40") assert reply.startswith("ACCEPT") # We could be clever and just try again with whatever it said its # protocol version was when we're rejected... reply = request(s, "ANN Monitor %s 0" % socket.gethostname()) assert reply == "OK" reply = request(s, "RESCHEDULE_RECORDINGS -1") assert reply == "1" send_myth(s, "DONE") s.close() if __name__ == "__main__": main()