Exemplo n.º 1
0
def stop(request):
    transmission_key, transmission_secret = utils.get_transmission_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=transmission_key,
        secret=transmission_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:
        transmission = models.Transmission.objects.order_by('-id')[0]
        transmission.enable = False
        transmission.save()
    except IndexError:
        transmission = models.Transmission.objects.create(enable=False)

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

    cmd = "%s onestop" % utils.transmission_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,
        }), content_type='application/json')
Exemplo n.º 2
0
def edit(request):
    transmission_key, transmission_secret = utils.get_transmission_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=transmission_key,
        secret=transmission_secret)

    """
    Get the Transmission object
    If it does not exist create a new entry
    """
    try:
        transmission = models.Transmission.objects.order_by('-id')[0]
    except IndexError:
        transmission = models.Transmission.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