Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(9)  |  Call(4)  |  Derive(0)  |  Import(5)

        def download(params, filefunc, statusfunc, finfunc, errorfunc, doneflag, cols, pathFunc = None, paramfunc = None, spewflag = Event()):
    if len(params) == 0:
        errorfunc('arguments are -\n' + formatDefinitions(defaults, cols))
        return
    try:
        config, args = parseargs(params, defaults, 0, 1)
        if args:
            if config.get('responsefile', None) == None:
                raise ValueError, 'must have responsefile as arg or parameter, not both'
            if path.isfile(args[0]):
                config['responsefile'] = args[0]
            else: 
                config['url'] = args[0]
        if (config['responsefile'] == '') == (config['url'] == ''):
            raise ValueError, 'need responsefile or url'
    except ValueError, e:
        errorfunc('error: ' + str(e) + '\nrun with no args for parameter explanations')
        return
    
    try:
        if config['responsefile'] != '':
            h = open(config['responsefile'], 'rb')
        else:
            h = urlopen(config['url'])
        response = h.read()
        h.close()
    except IOError, e:
        if config['responsefile'] != '' and config['responsefile'].find('Temporary Internet Files') != -1:
            errorfunc('BitTorrent was passed a filename that doesn\'t exist.  ' +
                'Either clear your Temporary Internet Files or right-click the link ' + 
                'and save the .torrent to disk first.')
        else:
            errorfunc('problem getting response info - ' + str(e))
        return

    try:
        response = bdecode(response)
        check_message(response)
    except ValueError, e:
        errorfunc("got bad file info - " + str(e))
        return
    
    try:
        def make(f, forcedir = False):
            if not forcedir:
                f = path.split(f)[0]
            if f != '' and not path.exists(f):
                makedirs(f)
                
        info = response['info']
        if info.has_key('length'):
            file_length = info['length']
            file = filefunc(info['name'], file_length, config['saveas'], False)
            if file is None:
                return
            make(file)
            files = [(file, file_length)]
        else:
            file_length = 0
            for x in info['files']:
                file_length += x['length']
            file = filefunc(info['name'], file_length, config['saveas'], True)
            if file is None:
                return
  
            # if this path exists, and no files from the info dict exist, we assume it's a new download and 
            # the user wants to create a new directory with the default name
            existing = 0
            if path.exists(file):
                for x in info['files']:
                    if path.exists(path.join(file, x['path'][0])):
                        existing = 1
                if not existing:
                    file = path.join(file, info['name'])
                    
            make(file, True)
            
            # alert the UI to any possible change in path
            if pathFunc != None:
                pathFunc(file)
                
            files = []
            for x in info['files']:
                n = file
                for i in x['path']:
                    n = path.join(n, i)
                files.append((n, x['length']))
                make(n)
    except OSError, e:
        errorfunc("Couldn't allocate dir - " + str(e))
        return
    
    finflag = Event()
    ann = [None]
    myid = 'M' + version.replace('.', '-')
    myid = myid + ('-' * (8 - len(myid))) + b2a_hex(sha(repr(time()) + ' ' + str(getpid())).digest()[-6:])
    seed(myid)
    pieces = [info['pieces'][x:x+20] for x in xrange(0, 
        len(info['pieces']), 20)]
    def failed(reason, errorfunc = errorfunc, doneflag = doneflag):
        doneflag.set()
        if reason is not None:
            errorfunc(reason)
    rawserver = RawServer(doneflag, config['timeout_check_interval'], config['timeout'], errorfunc = errorfunc, maxconnects = config['max_allow_in'])
    try:
        try:
            storage = Storage(files, open, path.exists, path.getsize)
        except IOError, e:
            errorfunc('trouble accessing files - ' + str(e))
            return
        def finished(finfunc = finfunc, finflag = finflag, 
                ann = ann, storage = storage, errorfunc = errorfunc):
            finflag.set()
            try:
                storage.set_readonly()
            except (IOError, OSError), e:
                errorfunc('trouble setting readonly at end - ' + str(e))
            if ann[0] is not None:
                ann[0](1)
            finfunc()
        rm = [None]
        def data_flunked(amount, rm = rm, errorfunc = errorfunc, report_hash_failures = config['report_hash_failures']):
            if rm[0] is not None:
                rm[0](amount)
            if report_hash_failures:
                errorfunc('a piece failed hash check, re-downloading it')
        storagewrapper = StorageWrapper(storage, 
            config['download_slice_size'], pieces, 
            info['piece length'], finished, failed, 
            statusfunc, doneflag, config['check_hashes'], data_flunked)
    except ValueError, e:
        failed('bad data - ' + str(e))
    except IOError, e:
        failed('IOError - ' + str(e))
    if doneflag.isSet():
        return

    e = 'maxport less than minport - no ports to check'
    for listen_port in xrange(config['minport'], config['maxport'] + 1):
        try:
            rawserver.bind(listen_port, config['bind'])
            break
        except socketerror, e:
            pass
    else:
        errorfunc("Couldn't listen - " + str(e))
        return

    choker = Choker(config['max_uploads'], rawserver.add_task, finflag.isSet, 
        config['min_uploads'])
    upmeasure = Measure(config['max_rate_period'], 
        config['upload_rate_fudge'])
    downmeasure = Measure(config['max_rate_period'])
    def make_upload(connection, choker = choker, 
            storagewrapper = storagewrapper, 
            max_slice_length = config['max_slice_length'],
            max_rate_period = config['max_rate_period'],
            fudge = config['upload_rate_fudge']):
        return Upload(connection, choker, storagewrapper, 
            max_slice_length, max_rate_period, fudge)
    ratemeasure = RateMeasure(storagewrapper.get_amount_left())
    rm[0] = ratemeasure.data_rejected
    picker = PiecePicker(len(pieces), config['rarest_first_cutoff'])
    for i in xrange(len(pieces)):
        if storagewrapper.do_I_have(i):
            picker.complete(i)
    downloader = Downloader(storagewrapper, picker,
        config['request_backlog'], config['max_rate_period'],
        len(pieces), downmeasure, config['snub_time'], 
        ratemeasure.data_came_in)
    connecter = Connecter(make_upload, downloader, choker,
        len(pieces), upmeasure, config['max_upload_rate'] * 1024, rawserver.add_task)
    infohash = sha(bencode(info)).digest()
    encoder = Encoder(connecter, rawserver, 
        myid, config['max_message_length'], rawserver.add_task, 
        config['keepalive_interval'], infohash, config['max_initiate'])
    rerequest = Rerequester(response['announce'], config['rerequest_interval'], 
        rawserver.add_task, connecter.how_many_connections, 
        config['min_peers'], encoder.start_connection, 
        rawserver.add_task, storagewrapper.get_amount_left, 
        upmeasure.get_total, downmeasure.get_total, listen_port, 
        config['ip'], myid, infohash, config['http_timeout'], errorfunc, 
        config['max_initiate'], doneflag, upmeasure.get_rate, downmeasure.get_rate,
        encoder.ever_got_incoming)
    if config['spew']:
        spewflag.set()
    DownloaderFeedback(choker, rawserver.add_task, statusfunc, 
        upmeasure.get_rate, downmeasure.get_rate, 
        upmeasure.get_total, downmeasure.get_total, ratemeasure.get_time_left, 
        ratemeasure.get_size_left, file_length, finflag,
        config['display_interval'], spewflag)


    # useful info and functions for the UI
    if paramfunc:
        paramfunc({ 'max_upload_rate' : connecter.change_max_upload_rate,  # change_max_upload_rate()
                    'max_uploads': choker.change_max_uploads, # change_max_uploads()
                    'listen_port' : listen_port, # int
                    'peer_id' : myid, # string
                    'info_hash' : infohash, # string
                    'start_connection' : encoder._start_connection # start_connection((, ), )
                    })
    
    statusfunc({"activity" : 'connecting to peers'})
    ann[0] = rerequest.announce
    rerequest.begin()
    rawserver.listen_forever(encoder)
    storage.close()
    rerequest.announce(2)
        


src/b/e/benflix-HEAD/videoportal/BitTorrent/btdownloadheadless.py   benflix(Download)
# see LICENSE.txt for license information
 
from BitTorrent.download import download
from threading import Event
from os.path import abspath
 
    h = HeadlessDisplayer()
    download(params, h.chooseFile, h.display, h.finished, h.error, Event(), cols, h.newpath)
    if not h.done:
        h.failed()

src/b/e/benflix-HEAD/videoportal/BitTorrent/btdownloadgui.py   benflix(Download)
from sys import argv
from BitTorrent import version
from BitTorrent.download import download
from btdownloadheadless import print_spew
from threading import Event, Thread
            else:
                dlg.Destroy()
        download(params, d.chooseFile, d.updateStatus, d.finished, d.error, doneflag, 100, d.newpath)
        if not d.fin:
            d.failed()

src/b/e/benflix-HEAD/videoportal/BitTorrent/btdownloadcurses.py   benflix(Download)
# see LICENSE.txt for license information
 
from BitTorrent.download import download
from threading import Event
from os.path import abspath
def run(mainerrlist, params):
    d = CursesDisplayer(mainerrlist)
    try:
        download(params, d.chooseFile, d.display, d.finished, d.error, mainkillflag, fieldw)
    except KeyboardInterrupt:

src/b/e/benflix-HEAD/videoportal/BitTorrent/btdownloadlibrary.py   benflix(Download)
def download(url, file):
    ev = Event()
    def fin(ev = ev):
        ev.set()
    BitTorrent.download.download(['--url', url, '--saveas', file], 

src/b/e/benflix-HEAD/videoportal/BitTorrent/btlaunchmanycurses.py   benflix(Download)
# see LICENSE.txt for license information
 
from BitTorrent.download import download
from threading import Thread, Event, Lock
from os import listdir

src/b/e/benflix-HEAD/videoportal/BitTorrent/btlaunchmany.py   benflix(Download)
# see LICENSE.txt for license information
 
from BitTorrent.download import download
from threading import Thread, Event, Lock
from os import listdir