示例#1
0
def stop(request):
    mythtv_key, mythtv_secret = utils.get_mythtv_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=mythtv_key,
        secret=mythtv_secret)
    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
    jail = json.loads(server.plugins.jail.info())[0]
    assert auth

    try:
        mythtv = models.MythTV.objects.order_by('-id')[0]
        mythtv.enable = False
        mythtv.save()
    except IndexError:
        mythtv = models.MythTV.objects.create(enable=False)

    try:
        form = forms.MythTVForm(mythtv.__dict__, instance=mythtv, jail=jail)
        form.is_valid()
        form.save()
    except ValueError:
        pass

    cmd = "%s onestop" % utils.mythtv_control
    pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
        shell=True, close_fds=True)

    out = pipe.communicate()[0]
    return HttpResponse(simplejson.dumps({
        'error': False,
        'message': out,
        }))
示例#2
0
def start(request):
    mythtv_key, mythtv_secret = utils.get_mythtv_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=mythtv_key,
        secret=mythtv_secret)
    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
    jail = json.loads(server.plugins.jail.info())[0]
    assert auth

    try:
        mythtv = models.MythTV.objects.order_by('-id')[0]
        mythtv.enable = True
        mythtv.save()
    except IndexError:
        mythtv = models.MythTV.objects.create(enable=True)

    try:
        form = forms.MythTVForm(mythtv.__dict__, instance=mythtv, jail=jail)
        form.is_valid()
        form.save()
    except ValueError:
        return HttpResponse(simplejson.dumps({
            'error': True,
            'message': 'MythTV data did not validate, please configure it first.',
            }), content_type='application/json')


    libc = ctypes.cdll.LoadLibrary("libc.so.7")
    omask = (ctypes.c_uint32 * 4)(0, 0, 0, 0)
    mask = (ctypes.c_uint32 * 4)(0, 0, 0, 0)
    pmask = ctypes.pointer(mask)
    pomask = ctypes.pointer(omask)
    libc.sigprocmask(signal.SIGQUIT, pmask, pomask)
    cmd = "%s onestart" % utils.mythtv_control
    _popen = os.popen(cmd)
    #pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
    #    shell=True)


    out = ''
    time.sleep(3)
    libc.sigprocmask(signal.SIGQUIT, pomask, None)
    return HttpResponse(simplejson.dumps({
        'error': False,
        'message': out,
        }))
示例#3
0
def edit(request):
    mythtv_key, mythtv_secret = utils.get_mythtv_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=mythtv_key,
        secret=mythtv_secret)

    """
    Get the MythTV object
    If it does not exist create a new entry
    """
    try:
        mythtv = models.MythTV.objects.order_by('-id')[0]
    except IndexError:
        mythtv = models.MythTV.objects.create()

    try:
        server = jsonrpclib.Server(url, transport=trans)
        jail = json.loads(server.plugins.jail.info())[0]
        auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
        assert auth
    except Exception, e:
        raise