Esempio n. 1
0
def handle_file_failed(dongle, remote, channel, files, ret, err):
    logger.info("handle file failed %s[%s]: %s" % (remote, channel, files))
    logger.debug(err)
    try:
        rules = get_campaign_rule(files)
        if rules is None:
            raise Exception("No matching rule for files %s!" % files)
        record = None
        try_again = False

        for rule in get_campaign_rule(files):
            record = RemoteBluetoothDeviceFilesRejected()
            record.dongle = UploaderBluetoothDongle.objects.get(address=dongle)
            record.campaign = rule
            record.ret_value = ret
            record.setRemoteDevice(remote)
            record.save()
            # from here we try again either on timeout or if rejected count is 
            # smaller than filter, for any of the matching rules
            # if only 1 campaign matches we do it all over!
            try_again = try_again | rule.tryAgain(record)

        logger.info("try again: %s" % try_again)
        if try_again:
            from openproximity.rpc.server import OpenProximityService
            uploader = OpenProximityService.getUploader()
            if uploader:
                logger.info("trying again")
                return do_upload(uploader, files, remote)
            else:
                logger.info("no uploader registered")
    except Exception, err:
        logger.error("OOOPS!!!")
        logger.exception(err)
Esempio n. 2
0
def handle_file_failed(dongle, remote, channel, files, ret, err):
    logger.info("handle file failed %s[%s]: %s" % (remote, channel, files))
    logger.debug(err)
    try:
        rules = get_campaign_rule(files)
        if rules is None:
            raise Exception("No matching rule for files %s!" % files)
        record = None
        try_again = False

        for rule in get_campaign_rule(files):
            record = RemoteBluetoothDeviceFilesRejected()
            record.dongle = UploaderBluetoothDongle.objects.get(address=dongle)
            record.campaign = rule
            record.ret_value = ret
            record.setRemoteDevice(remote)
            record.save()
            # from here we try again either on timeout or if rejected count is
            # smaller than filter, for any of the matching rules
            # if only 1 campaign matches we do it all over!
            try_again = try_again | rule.tryAgain(record)

        logger.info("try again: %s" % try_again)
        if try_again:
            from openproximity.rpc.server import OpenProximityService

            uploader = OpenProximityService.getUploader()
            if uploader:
                logger.info("trying again")
                return do_upload(uploader, files, remote)
            else:
                logger.info("no uploader registered")
    except Exception, err:
        logger.error("OOOPS!!!")
        logger.exception(err)
Esempio n. 3
0
def found_action_upload(remote, record = None, line=None):
    from openproximity.rpc.server import OpenProximityService
    
    uploader = OpenProximityService.getUploader()

    if uploader is None:
        line.content+=" no uploaders, can't handle"
        line.save()
        return True

    logger.info("found uploader")

    camps = getMatchingCampaigns(
            remote, 
            enabled=True, 
            record=record, 
            classes=[MarketingCampaign,]
    )


    if len(camps)==0:
        line.content+=" no matching campaings, not handling"
        line.save()
        logger.info("no campaigns")
        return True

    channel = None

    files=list()
    name=None
    service='opp'
    use_same = False

    for camp in camps:
        files.extend( list(get_files_from_campaign(camp, record)) )
        if camp.dongle_name:
            name = camp.dongle_name
        service = camp.get_service_display()
        if camp.fixed_channel and camp.fixed_channel > -1:
          channel = camp.fixed_channel
        if camp.upload_on_discovered:
            use_same = True

    sdp = RemoteBluetoothDeviceSDP.objects.filter(remote__pk=record.remote.pk)
    if sdp.count() > 0:
        channel = sdp.order_by("-time")[0].channel
        line.content += "using previous resolved channel %i" % channel

    logger.info("going to upload %s files" % len(files))
    if len(files) > 0:
        OpenProximityService.addPending(record.remote.address, uploader)
        do_upload(uploader, files, record.remote.address, service, name, 
                channel=channel, dongle=dongle if use_same else None)
        line.content+=" uploading files"
    else:
        line.content+=" no files to upload"
    
    line.save()
Esempio n. 4
0
def handle_sdp_resolved(dongle, remote, channel):
    from openproximity.rpc.server import OpenProximityService
    logger.info("Valid SDP: %s %s" % (remote, channel) )
    remote=RemoteDevice.objects.filter(address=remote).get()
    if RemoteBluetoothDeviceSDP.objects.filter(remote=remote).count() == 0:
        logger.info("New SDP result")
        record = RemoteBluetoothDeviceSDP()
        record.dongle = UploaderBluetoothDongle.objects.get(address=dongle)
        record.channel = channel
        record.remote = remote
        record.save()
    logger.info("Starting bonding process")
    uploader = OpenProximityService.getUploader()
    uploader.start_pairing(remote.address)
Esempio n. 5
0
def handle_sdp_resolved(dongle, remote, channel):
    from openproximity.rpc.server import OpenProximityService

    logger.info("Valid SDP: %s %s" % (remote, channel))
    remote = RemoteDevice.objects.filter(address=remote).get()
    if RemoteBluetoothDeviceSDP.objects.filter(remote=remote).count() == 0:
        logger.info("New SDP result")
        record = RemoteBluetoothDeviceSDP()
        record.dongle = UploaderBluetoothDongle.objects.get(address=dongle)
        record.channel = channel
        record.remote = remote
        record.save()
    logger.info("Starting bonding process")
    uploader = OpenProximityService.getUploader()
    uploader.start_pairing(remote.address)