g3rpcclient.py :  » Network » Rufus-BitTorrent-Client » Rufus_0.7.0_src » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Rufus BitTorrent Client 
Rufus BitTorrent Client » Rufus_0.7.0_src » g3rpcclient.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
# Name:        g3rpcclient.py
# Purpose:     
#
# Author:      Jeremy Arendt
#
# Created:     2004/20/02
# RCS-ID:      $Id: g3rpcclient.py,v 1.3 2005/08/28 00:25:52 Inigo Exp $
# Copyright:   (c) 2002
# Licence:     See G3.LICENCE
#-----------------------------------------------------------------------------
from xmlrpclib import ServerProxy
from g3peerid import *
from traceback import print_exc
from base64 import encodestring
from btconfig import BTConfig
from threading import Thread
import socket

class RequestThread(Thread):

    def __init__(self, requestfunc, param):

        Thread.__init__(self)

        self.done = 0

        self.requestfunc = requestfunc
        self.param = param
        ##self.setDaemonic(True)
        
    def run(self):
        print 'starting thread'
        try:

            self.requestfunc(self.param)
        except socket.error, msg:
            print msg

        self.done = 1
        print 'thread ending'

class T_G3RPCCLient:
    def __init__(self, btconfig, ip="127.0.0.1"): ## needs to be updated in similar way to G3RPCCLient if ever used...
        self.server = ServerProxy("http://%s:%s" % (ip, btconfig.Get('web_interface_port')))
        
    def Announce(self, ip, peerid, port, infohash):
        try:
            t = RequestThread(self.server.FriendAnnounce, [ encodestring(peerid), port, encodestring(infohash)])
            t.start()
        except:
            print_exc()
            pass
        
    def Renounce(self, ip, peerid, port, infohash):
        print 'in Rennounce'
        try:
            t = RequestThread(self.server.FriendRenounce, [ encodestring(peerid), port, encodestring(infohash)])
            t.start()
        except:
            print_exc()
            pass

    def AddTorrent(self, responsefile):
        try:
            self.server.AddTorrent(responsefile)
        except:
            pass
        
            
class G3RPCCLient:
    def __init__(self, path = "", ip="127.0.0.1"):
        self.btconfig = BTConfig(path)
        self.btconfig.LoadOptions()
        self.server = ServerProxy("http://%s:%s" % (ip, self.btconfig.Get('web_interface_port')))

    def Announce(self, peerid, port, infohash):
        try:
            self.server.FriendAnnounce([ encodestring(peerid), port, encodestring(infohash)])
        except:
            pass
        
    def Renounce(self, peerid, port, infohash):
        try:
            self.server.FriendRenounce([ encodestring(peerid), port, encodestring(infohash)])
        except:
            pass

    def AddTorrent(self, responsefile):
        try:
            self.server.AddTorrent(responsefile)
        except:
            pass
        
def test_announce(client):
    client.Announce("-G3g3rmz000000000000", 6881, "GARRYYYYYYYYYYYYYYYY")
    client.Announce("-G3g3rmz000000000000", 6882, "BARRYYYYYYYYYYYYYYYY")
    client.Announce("-G3g3rmz000000000000", 6883, "MARRYYYYYYYYYYYYYYYY")

    ##client.Renounce("-G3g3rmz000000000000", 6881, "GARRYYYYYYYYYYYYYYYY")
    ##client.Renounce("-G3g3rmz000000000000", 6882, "BARRYYYYYYYYYYYYYYYY")
    ##client.Renounce("-G3g3rmz000000000000", 6883, "MARRYYYYYYYYYYYYYYYY")

if __name__ == "__main__":
    g = T_G3RPCCLient(argv[1])
    test_announce(g)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.