Exemple #1
0
    def __init__(self,
                 torrent_path,
                 directory='',
                 port=55308,
                 download_all=False,
                 visualizer=None):
        torrent_dict = tparser.bdecode_file(torrent_path)
        self.torrent_dict = torrent_dict
        self.peer_dict = {}
        self.peer_ips = []
        self.port = port
        self.download_all = download_all
        self.r = None
        self.tracker_response = None
        self.peer_dict = {}
        self.hash_string = None
        self.queued_requests = []
        self.vis_write_sock = ''
        self.reactor = reactor.Reactor()
        self.reactor.add_listeners([
            PeerListener(torrent=self, port=7000),
            VisListener(torrent=self, port=8035)
        ])

        # Try to connect to visualization server
        vis_socket = connect_vis(visualizer) if visualizer else None
        if directory:
            os.chdir(directory)
        if 'files' in self.torrent_dict['info']:
            dirname = self.torrent_dict['info']['name']
        else:
            dirname = None
        file_list = []

        # Multifile case
        if 'files' in self.torrent_dict['info']:
            file_list.extend(self.torrent_dict['info']['files'])
            multifile = True

        # Deal with single-file torrents by building up the kind of dict
        # found in torrent_dict['info']['files']
        elif 'name' in self.torrent_dict['info']:
            info_dict = {}
            info_dict['path'] = self.torrent_dict['info']['name']
            info_dict['length'] = self.torrent_dict['info']['length']
            file_list.append(info_dict)
            multifile = False
        else:
            raise Exception('Invalid .torrent file')

        self.switchboard = Switchboard(dirname=dirname,
                                       file_list=file_list,
                                       piece_length=self.piece_length,
                                       num_pieces=self.num_pieces,
                                       multifile=multifile,
                                       download_all=download_all,
                                       vis_socket=vis_socket)
Exemple #2
0
from flask import Flask
from switchboard import Switchboard, Workflow

app = Flask(__name__)


class TestWorkflow(Workflow):
    pid, form, status = 17921, 'demographics', 2

    def execute(self, trigger):
        print "ah ha"


app.config['SWITCHBOARD_WORKFLOWS'] = [TestWorkflow()]
Switchboard(app)


@app.route('/', methods=['GET'])
def index():
    return "Hello World", 200


if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)