Пример #1
0
def checkDatabaseWithRetries():
    tries = 0
    failed = True

    while tries < MAX_INTERNET_CONNECT_ATTEMPTS and failed:
        failed = False
        #md_api_on = MDapi.md_api_on()

        misfitDevice = MDapi.misfitProductionGetDeviceFromSerialInternal(
            "SZ2ZZ00H5F")

        if misfitDevice == -50 or misfitDevice == -1:
            failed = True
            tries += 1
            print "\nDatabase contact attempt %s/%s\n" % (
                tries, MAX_INTERNET_CONNECT_ATTEMPTS)

    if tries >= MAX_INTERNET_CONNECT_ATTEMPTS:
        print "\n...\n...\n..."
        print "\nFailed contacting database after %s retries." % tries
        print "...\n...\n..."

    if failed == False:
        print "\nContacted the database on attempt %s." % tries

    return not failed
Пример #2
0
def getIEEEfromDatabase(serial_number, serial_num_type):
    duplicateEntries = False
    serial_from_database = None
    serial_internal_from_database = None
    serial_smt_from_database = None
    tries = 0
    failed = True

    # TODO: If the device is empty, don't retry, fail.
    while tries < MAX_DATABASE_READ_ATTEMPTS and failed:
        failed = False
        if serial_num_type == 'internal':
            misfitDevice = MDapi.misfitProductionGetDeviceFromSerialInternal(
                serial_number)
            serial_number_internal = serial_number
        elif serial_num_type == 'smt':
            misfitDevice = MDapi.misfitProductionGetDeviceFromSerialSMT(
                serial_number)
            serial_number_smt = serial_number
        elif serial_num_type == 'packaging':
            misfitDevice = MDapi.misfitProductionGetDeviceFromSerial(
                serial_number)
            if misfitDevice == -1:  # if the serial number doesn't exist or device is empty, return
                print "\nPackaging serial number does not exist in database"
                return (None, None, None, None, False)
        if misfitDevice == -50 or misfitDevice == -1:
            failed = True
            tries += 1
            print "\nRead attempt %s/%s\n" % (tries,
                                              MAX_DATABASE_READ_ATTEMPTS)

    if failed == False:
        print "..."
        print "Read after %s retries." % tries
        print "...\n"

    if tries >= MAX_DATABASE_POST_ATTEMPTS:
        print "\n...\n...\n..."
        print "\nFailed reading after %s retries." % tries
        print "...\n...\n..."

    if failed == True:
        return (None, None, None, None, None)

    misfitDevice = util.convertUnicode(misfitDevice)

    ieee_addresses = []
    serial_numbers_internal = []
    serial_numbers_smt = []
    serial_numbers = []

    print "\nmisfitDevice: ", misfitDevice
    for i, x in enumerate(misfitDevice['devices']):
        ieee_addresses.append(x['ieee_address'])
        serial_numbers_internal.append(x['serial_number_internal'])
        serial_numbers_smt.append(x['serial_number_smt'])
        serial_numbers.append(x['serial_number'])
    if len(ieee_addresses) == 0:
        if serial_num_type == 'internal':
            print "\nError: no ieee addresses exist in database for this internal serial number (%s).\n" % serial_number
        elif serial_num_type == 'smt':
            print "\nError: no ieee addresses exist in database for this SMT serial number (%s).\n" % serial_number
        elif serial_num_type == 'packaging':
            print "\nError: no ieee addresses exist in database for this serial number (%s).\n" % serial_number
        ieee_address = None
    elif len(ieee_addresses) > 1:
        print "\nError: %s ieee addresses exist for this serial number.\n" % len(
            ieee_addresses)
        for x in ieee_addresses:
            print "     %s" % x
        # ieee_address = ieee_addresses[0]
        # print "\nieee address: %s \n" % ieee_address
        ieee_address = None
        duplicateEntries = True
    else:
        ieee_address = ieee_addresses[0]
        print "\nieee address: %s \n" % ieee_address

    if ieee_address is not None:
        # print "serial_numbers: %s" % serial_numbers
        if len(serial_numbers) == 0:
            print "\nError: no serial numbers exist for this IEEE address.\n"
            serial_from_database = None
        elif len(serial_numbers) > 1:
            print "\nError: %s serial numbers exist for this IEEE address." % len(
                serial_numbers)
            for x in serial_numbers:
                print "     %s" % x
            # serial_number = serial_numbers[0]
            # print "\nserial number: %s \n" % serial_number
            serial_from_database = None
            duplicateEntries = True
        else:
            serial_from_database = serial_numbers[0]
            print "\nserial number: %s \n" % serial_from_database

        # print "serial_numbers_internal: %s" % serial_numbers_internal
        if len(serial_numbers_internal) == 0:
            print "\nError: no internal serial numbers exist for this IEEE address."
            serial_internal_from_database = None
        elif len(serial_numbers_internal) > 1:
            print "\nError: %s internal serial numbers exist for this IEEE address." % len(
                serial_numbers_internal)
            for x in serial_numbers_internal:
                print "     %s" % x
            # serial_number_internal = serial_numbers_internal[0]
            # print "\nserial number internal: %s \n" % serial_number_internal
            serial_internal_from_database = None
            duplicateEntries = True
        else:
            serial_internal_from_database = serial_numbers_internal[0]
            print "\nserial number internal: %s \n" % serial_internal_from_database

        # print "serial_numbers_internal: %s" % serial_numbers_internal
        if len(serial_numbers_smt) == 0:
            print "\nError: no SMT serial numbers exist for this IEEE address."
            serial_smt_from_database = None
        elif len(serial_numbers_smt) > 1:
            print "\nError: %s SMT serial numbers exist for this IEEE address." % len(
                serial_numbers_internal)
            for x in serial_numbers_smt:
                print "     %s" % x
            # serial_number_internal = serial_numbers_internal[0]
            # print "\nserial number internal: %s \n" % serial_number_internal
            serial_smt_from_database = None
            duplicateEntries = True
        else:
            serial_smt_from_database = serial_numbers_smt[0]
            print "\nserial number SMT: %s \n" % serial_smt_from_database

    return (ieee_address, serial_from_database, serial_internal_from_database,
            serial_smt_from_database, duplicateEntries)