Adds driver ID lookup
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
import json
|
import json
|
||||||
import click
|
import click
|
||||||
import boto3
|
import boto3
|
||||||
|
import csv
|
||||||
|
import urllib2
|
||||||
|
|
||||||
CONFIG_FILE_NAME = "driverConfig.json"
|
CONFIG_FILE_NAME = "driverConfig.json"
|
||||||
CONFIG_OUTPUT_FILENAME = "config.txt"
|
CONFIG_OUTPUT_FILENAME = "config.txt"
|
||||||
@@ -28,6 +30,36 @@ def get_driver_files():
|
|||||||
files.append(x)
|
files.append(x)
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
def get_driver_ids():
|
||||||
|
"""Retrieve the master list of driver IDs from the S3 bucket."""
|
||||||
|
ids = []
|
||||||
|
url = 'https://s3.amazonaws.com/{}/deviceIds.csv'.format(DRIVER_BUCKET)
|
||||||
|
response = urllib2.urlopen(url)
|
||||||
|
csvreader = csv.DictReader(response)
|
||||||
|
for row in csvreader:
|
||||||
|
ids.append(row)
|
||||||
|
return ids
|
||||||
|
|
||||||
|
def check_driver_id(driver_name):
|
||||||
|
"""Check if a driver ID exists and if not, create an ID for it."""
|
||||||
|
id_list = get_driver_ids()
|
||||||
|
for id in id_list:
|
||||||
|
if id['driver'] == driver_name:
|
||||||
|
return id['id']
|
||||||
|
# if you get here, you didn't find the driver in the list
|
||||||
|
last_id = int(id_list[-1]['id'])
|
||||||
|
new_id = ("0000" + str(last_id + 10))[-4:]
|
||||||
|
new_csv_contents = "driver,id\n"
|
||||||
|
for id in id_list:
|
||||||
|
new_csv_contents += "{},{}\n".format(id['driver'], id['id'])
|
||||||
|
new_csv_contents += "{},{}\n".format(driver_name, new_id)
|
||||||
|
file_key = "deviceIds.csv"
|
||||||
|
s3.Bucket(DRIVER_BUCKET).put_object(Key=file_key, Body=new_csv_contents)
|
||||||
|
s3.ObjectAcl(DRIVER_BUCKET, file_key).put(ACL='public-read')
|
||||||
|
return new_id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def cli():
|
def cli():
|
||||||
pass
|
pass
|
||||||
@@ -70,10 +102,12 @@ def prepare(dry_run, version):
|
|||||||
else:
|
else:
|
||||||
version = driver_config['version']
|
version = driver_config['version']
|
||||||
|
|
||||||
|
driver_id = check_driver_id(driver_config['name'])
|
||||||
|
|
||||||
config_object = {
|
config_object = {
|
||||||
"driverFileName": driver_config['driverFilename'],
|
"driverFileName": driver_config['driverFilename'],
|
||||||
"deviceName": driver_config['name'],
|
"deviceName": driver_config['name'],
|
||||||
"driverId": driver_config['driverId'],
|
"driverId": driver_id,
|
||||||
"releaseVersion": "{}".format(version),
|
"releaseVersion": "{}".format(version),
|
||||||
"files": file_object
|
"files": file_object
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user