Example #1
0
def do_it_live(con, rows):

    pylantorrent.log(logging.INFO, "lan torrent daemon setting up to send %d in a group" % (len(rows)))

    c = con.cursor()
    dests = []
    last_host = None
    last_port = None
    json_dest = None
    rids_all = []
    for r in rows:
        new_host = r[0]
        new_port = int(r[1])
        dst_filename = r[3]
        src_filename = r[2]
        rid = r[4]
        rids_all.append(rid)
        sz = os.path.getsize(src_filename)
        # if it is the same host just tack on another dest file
        if new_host == last_host and last_port == new_port:
            reqs = json_dest['requests']
            new_req = {"filename" : dst_filename, "id" : rid, 'rename' : True}
            reqs.append(new_req)
            json_dest['requests'] = reqs
        else:
            if json_dest != None:
                dests.append(json_dest)
            last_host = new_host
            last_port = new_port

            json_dest = {}
            json_dest['host'] = new_host
            json_dest['port'] = new_port
            json_dest['requests'] = [{"filename" : dst_filename, "id" : rid, 'rename' : True}]
            json_dest['block_size'] = 128*1024
            json_dest['degree'] = 1
            json_dest['length'] = sz
    
    if json_dest != None:
        dests.append(json_dest)

    final = {}
    # for the sake of code resuse this will just be piped into an
    # lt daemon processor.  /dev/null is used to supress a local write
    final['requests'] = [{'filename' : "/dev/null", 'id' : str(uuid.uuid1()), 'rename' : False}]
    final['host'] = "localhost"
    final['port'] = 2893
    final['block_size'] = 131072
    final['degree'] = 1
    final['destinations'] = dests

    pylantorrent.log(logging.INFO, "request send %s" % (json.dumps(final, sort_keys=True, indent=4)))
    pylantorrent.log(logging.INFO, "sending em!")

    client = LTClient(src_filename, final)
    v = LTServer(client, client)
    try:
        v.store_and_forward()
    except Exception, ex:
        pylantorrent.log(logging.ERROR, "an error occured on store and forward: %s" % (str(ex)), traceback)
Example #2
0
def do_it_live(con, rows):

    pylantorrent.log(logging.INFO, "lan torrent daemon setting up to send %d in a group" % (len(rows)))

    c = con.cursor()
    dests = []
    last_host = None
    last_port = None
    json_dest = None
    rids_all = []
    for r in rows:
        new_host = r[0]
        new_port = int(r[1])
        dst_filename = r[3]
        src_filename = r[2]
        rid = r[4]
        rids_all.append(rid)
        sz = os.path.getsize(src_filename)
        # if it is the same host just tack on another dest file
        if new_host == last_host and last_port == new_port:
            reqs = json_dest['requests']
            new_req = {"filename" : dst_filename, "id" : rid, 'rename' : True}
            reqs.append(new_req)
            json_dest['requests'] = reqs
        else:
            if json_dest != None:
                dests.append(json_dest)
            last_host = new_host
            last_port = new_port

            json_dest = {}
            json_dest['host'] = new_host
            json_dest['port'] = new_port
            json_dest['requests'] = [{"filename" : dst_filename, "id" : rid, 'rename' : True}]
            json_dest['block_size'] = 128*1024
            json_dest['degree'] = 1
            json_dest['length'] = sz
    
    if json_dest != None:
        dests.append(json_dest)

    final = {}
    # for the sake of code resuse this will just be piped into an
    # lt daemon processor.  /dev/null is used to supress a local write
    final['requests'] = [{'filename' : "/dev/null", 'id' : str(uuid.uuid1()), 'rename' : False}]
    final['host'] = "localhost"
    final['port'] = 2893
    final['block_size'] = 131072
    final['degree'] = 1
    final['destinations'] = dests

    pylantorrent.log(logging.INFO, "request send %s" % (json.dumps(final, sort_keys=True, indent=4)))
    pylantorrent.log(logging.INFO, "sending em!")

    client = LTClient(src_filename, final)
    v = LTServer(client, client)
    try:
        v.store_and_forward()
    except Exception, ex:
        pylantorrent.log(logging.ERROR, "an error occured on store and forward: %s" % (str(ex)))
Example #3
0
def main(argv=sys.argv[1:]):
    
    dests = [] 
    cnt = 1
    l = sys.stdin.readline()
    data_size = os.path.getsize(argv[0])
    while l:
        # each line is a url to be broken down
        a = l.split(":", 1)
        if len(a) != 2:
            raise Exception("url %d not properly formatted: %s" % (cnt, l))
        host = a[0]
        l = a[1]
        a = l.split("/", 1)
        if len(a) != 2:
            raise Exception("url %d not properly formatted: %s" % (cnt, l))
        port = a[0]
        x = int(port)
        filename = "/" + a[1].strip()

        degree = 1
        block_size = 128 * 1024
        filenames = [filename,]
        print "%s:%d %s" % (host, x, filename)

        json_dest = pylantorrent.create_endpoint_entry(host, filenames, data_size, port, block_size, degree)
        dests.append(json_dest)

        l = sys.stdin.readline()
        cnt = cnt + 1

    # for the sake of code resuse this will just be piped into an
    # lt daemon processor.  /dev/null is used to supress a local write
    final = pylantorrent.create_endpoint_entry("localhost", ["/dev/null",], data_size, rename=False)
    final['destinations'] = dests

    c = LTClient(argv[0], final)
    v = LTServer(c, c)
    v.store_and_forward()
    v.clean_up()
    c.close()
    c.check_sum()

    es = c.get_incomplete()
    for k in es:
        e = es[k]
        if e['emsg'] == None:
            e['message'] = "Unknown error.  Please retry"
        else:
            e['message'] = e['emsg']
        print "ERROR: %s:%s%s %s" % (e['host'], e['port'], str(e['filename']), e['message'])       
    print "Succesfully sent to %d" % (c.success_count)

    return 0
Example #4
0
def main(argv=sys.argv[1:]):
    
    dests = [] 
    cnt = 1
    l = sys.stdin.readline()
    data_size = os.path.getsize(argv[0])
    while l:
        # each line is a url to be broken down
        a = l.split(":", 1)
        if len(a) != 2:
            raise Exception("url %d not properly formatted: %s" % (cnt, l))
        host = a[0]
        l = a[1]
        a = l.split("/", 1)
        if len(a) != 2:
            raise Exception("url %d not properly formatted: %s" % (cnt, l))
        port = a[0]
        x = int(port)
        filename = "/" + a[1].strip()

        filenames = [filename,]
        json_dest = pylantorrent.create_endpoint_entry(host, filenames, data_size, port, block_size, degree)
        dests.append(json_dest)

        l = sys.stdin.readline()
        cnt = cnt + 1

    # for the sake of code resuse this will just be piped into an
    # lt daemon processor.  /dev/null is used to supress a local write
    final = pylantorrent.create_endpoint_entry("localhost", ["/dev/null",], data_size, rename=False)
    final['destinations'] = dests

    c = LTClient(argv[0], final)
    v = LTServer(c, c)
    v.store_and_forward()
    v.clean_up()
    c.close()
    c.check_sum()

    es = c.get_incomplete()
    for k in es:
        e = es[k]
        if e['emsg'] == None:
            e['message'] = "Unknown error.  Please retry"
        else:
            e = e['emsg']
        print "ERROR: %s:%s%s %s" % (e['host'], e['port'], str(e['filename']), e['message'])       
    print "Succesfully sent to %d" % (c.success_count)

    return 0
Example #5
0
def do_it_live(con, rows):

    pylantorrent.log(logging.INFO, "lan torrent daemon setting up to send %d in a group" % (len(rows)))

    c = con.cursor()
    dests = []
    last_host = None
    last_port = None
    json_dest = None
    rids_all = []
    for r in rows:
        new_host = r[0]
        new_port = int(r[1])
        dst_filename = r[3]
        src_filename = r[2]
        rid = r[4]
        rids_all.append(rid)
        sz = os.path.getsize(src_filename)
        # if it is the same host just tack on another dest file
        if new_host == last_host and last_port == new_port:
            reqs = json_dest['requests']
            new_req = {"filename" : dst_filename, "id" : rid, 'rename' : True}
            reqs.append(new_req)
            json_dest['requests'] = reqs
        else:
            if json_dest != None:
                dests.append(json_dest)
            last_host = new_host
            last_port = new_port

            json_dest = {}
            json_dest['host'] = new_host
            json_dest['port'] = new_port
            json_dest['requests'] = [{"filename" : dst_filename, "id" : rid, 'rename' : True}]
            json_dest['block_size'] = 128*1024
            json_dest['degree'] = 1
            json_dest['length'] = sz
    
    if json_dest != None:
        dests.append(json_dest)

    final = {}
    # for the sake of code resuse this will just be piped into an
    # lt daemon processor.  /dev/null is used to supress a local write
    final['requests'] = [{'filename' : "/dev/null", 'id' : str(uuid.uuid1()), 'rename' : False}]
    final['host'] = "localhost"
    final['port'] = 2893
    final['block_size'] = 131072
    final['degree'] = 1
    final['destinations'] = dests

    pylantorrent.log(logging.INFO, "request send %s" % (json.dumps(final, sort_keys=True, indent=4)))
    pylantorrent.log(logging.INFO, "sending em!")

    client = LTClient(src_filename, final)
    v = LTServer(client, client)
    v.store_and_forward()

    rc = 0
    es = client.get_incomplete()
    bad_rid = []
    for k in es:
        rc = rc + 1
        e = es[k]
        pylantorrent.log(logging.ERROR, "error trying to send %s" % (str(e)))
        rid = e['id']
        bad_rid.append(rid)
        # set to retry
        u = "update requests set state = ?, message = ?, attempt_count = attempt_count + 1 where rid = ?"
        data = (0,str(e),rid,)
        c.execute(u, data)
        rids_all.remove(rid)

    for rid in rids_all:
        # set to compelte
        u = "update requests set state = ?, message = ? where rid = ?"
        data = (1,"Success",rid,)
        c.execute(u, data)

    con.commit()

    if len(bad_rid) > 0:
        # wait for soemthing in the system to change
        # obviously we need something more sophisticated than this
        # eventually
        time.sleep(5)
    return rc
Example #6
0
def do_it_live(con, rows):

    pylantorrent.log(
        logging.INFO,
        "lan torrent daemon setting up to send %d in a group" % (len(rows)))

    c = con.cursor()
    dests = []
    last_host = None
    last_port = None
    json_dest = None
    rids_all = []
    for r in rows:
        new_host = r[0]
        new_port = int(r[1])
        dst_filename = r[3]
        src_filename = r[2]
        rid = r[4]
        rids_all.append(rid)
        sz = os.path.getsize(src_filename)
        # if it is the same host just tack on another dest file
        if new_host == last_host and last_port == new_port:
            reqs = json_dest['requests']
            new_req = {"filename": dst_filename, "id": rid, 'rename': True}
            reqs.append(new_req)
            json_dest['requests'] = reqs
        else:
            if json_dest != None:
                dests.append(json_dest)
            last_host = new_host
            last_port = new_port

            json_dest = {}
            json_dest['host'] = new_host
            json_dest['port'] = new_port
            json_dest['requests'] = [{
                "filename": dst_filename,
                "id": rid,
                'rename': True
            }]
            json_dest['block_size'] = 128 * 1024
            json_dest['degree'] = 1
            json_dest['length'] = sz

    if json_dest != None:
        dests.append(json_dest)

    final = {}
    # for the sake of code resuse this will just be piped into an
    # lt daemon processor.  /dev/null is used to supress a local write
    final['requests'] = [{
        'filename': "/dev/null",
        'id': str(uuid.uuid1()),
        'rename': False
    }]
    final['host'] = "localhost"
    final['port'] = 2893
    final['block_size'] = 131072
    final['degree'] = 1
    final['destinations'] = dests

    pylantorrent.log(
        logging.INFO,
        "request send %s" % (json.dumps(final, sort_keys=True, indent=4)))
    pylantorrent.log(logging.INFO, "sending em!")

    client = LTClient(src_filename, final)
    v = LTServer(client, client)
    v.store_and_forward()

    rc = 0
    es = client.get_incomplete()
    bad_rid = []
    for k in es:
        rc = rc + 1
        e = es[k]
        pylantorrent.log(logging.ERROR, "error trying to send %s" % (str(e)))
        rid = e['id']
        bad_rid.append(rid)
        # set to retry
        u = "update requests set state = ?, message = ?, attempt_count = attempt_count + 1 where rid = ?"
        data = (
            0,
            str(e),
            rid,
        )
        c.execute(u, data)
        rids_all.remove(rid)

    for rid in rids_all:
        # set to compelte
        u = "update requests set state = ?, message = ? where rid = ?"
        data = (
            1,
            "Success",
            rid,
        )
        c.execute(u, data)

    con.commit()

    if len(bad_rid) > 0:
        # wait for soemthing in the system to change
        # obviously we need something more sophisticated than this
        # eventually
        time.sleep(5)
    return rc