コード例 #1
0
                m = bs.find("message")
                h = bs.find("info_hash")
                if h is not None and m is not None:
                    raise APIError("%s failed: %s (info_hash=%s)!"% (url, unicode(urllib.unquote(m.text)), unicode(urllib.unquote(h.text))))
                elif m is not None:
                    raise APIError("%s failed: %s!"% (url, unicode(urllib.unquote(m.text))))
                else:
                    raise APIError("%s failed!"% url)


        except Exception, e:
            print "Caught %s uploading piece %d, aborting" % (e, pind)

        sys.stdout.write("\rUploaded %.02f%%..." % (pind / float(pnum) * 100.))
        sys.stdout.flush()



    finished, finishedpieces, finishedbytes = checkTorrentFiles(datadir, tor.torrent, callback = upload)
    
    if finishedbytes != tor.size:
        print "%d bytes failed verification, torrent is probably corrupted!"

        if len(tor.files) > len(finished):
            print "The following files did not match the torrent:"
            for f in tor.files:
                if not os.path.join(datadir, f.path) in finished:
                    print f.path.encode("ascii","xmlcharrefreplace")


    print "\nUpload finished."
コード例 #2
0
    
    # Look for data
    if len(sys.argv) == 5:
        datadir = sys.argv[4]

    else:  
        datadir = '.' 
              
    if len(t.files) > 1:
        datadir = os.path.join(datadir, t.name.replace('/', '_'))
    
    print "Checking data in %s" % datadir.encode("ascii","xmlcharrefreplace")
 
    
    def progress(pnum, pind, ffiles, fpieces, fbytes,  buf):
        sys.stdout.write("\rChecked %.02f%%..." % (pind / float(pnum) * 100.))
        sys.stdout.flush()
    
    finished, finishedpieces, finishedbytes = checkTorrentFiles(datadir, t.torrent, callback = progress)
    
    print 
   
    print "Found %d of %d bytes (%.02f%%)." % (finishedbytes, t.size, finishedbytes / float(t.size) * 100)
    
    if len(t.files) > len(finished):
        print "The following files are unfinished:"
        for f in t.files:
            if not os.path.join(datadir, f.path) in finished:
                print f.path.encode("ascii","xmlcharrefreplace")