import csv, re, os, time
import boto, boto.s3

# Product is hard-coded as 3010 for now
PRODUCT = '3010'

os.system('clear')
print ''
print ' -----------------------------------------------------------'
print '| Boulder Amplifiers 3010 Preamplifier Serial # Assignment  |'
print ' -----------------------------------------------------------'
print ''
print ''

# Read in the DB and store it in memory

bad_device = True
while bad_device == True:
    device = raw_input('Please enter the  device type you would like to assign to the unit (3010 or amp): ')
    # Serial numbers must be alphanumeric


    if device not in  ['3010', '1110', 'amp']:
        print 'Invalid device name must be 3010, 1110, or amp.\n'
    else:
        bad_device = False
PRODUCT = device

# Ask the user which serial address they are assigning
bad_serial = True
while bad_serial == True:
    serial = raw_input('Please enter the serial number that you would like to assign to the unit: ')
    # Serial numbers must be alphanumeric
    serial = re.sub(r'\W+', '', serial)

    serial_confirm = raw_input('Please confirm the serial number: ')
    # Serial numbers must be alphanumeric
    serial_confirm = re.sub(r'\W+', '', serial_confirm)

    if serial != serial_confirm:
        print 'Serial numbers do not match.\n'
    elif len(serial) < 1:
        print 'Serial number must be at least 1 character long.\n'
    else:
        bad_serial = False

assign_ret = os.system('./assign-serial-num-device.sh ' + serial + ' ' + device)

if assign_ret:
    raw_input('There was an error during serial number assignment. Press Enter to quit.\n')
    exit(-1)

raw_input('\n\nSerial number has been assigned! Please press Enter and reboot the unit to complete the procedure.\n')
exit(0)
