|
@@ -10,7 +10,39 @@ import getpass
|
|
|
import json
|
|
|
import re
|
|
|
|
|
|
-MICE_TOILET_TEMPLATE = 'http://parts.shimatta.net/api/v1/parts/storages/075acbaf-ed60-47b9-9bd5-98bfbc3a79ea/'
|
|
|
+MICE_TOILET_TEMPLATE = 'https://parts.shimatta.net/api/v1/parts/storages/075acbaf-ed60-47b9-9bd5-98bfbc3a79ea/'
|
|
|
+
|
|
|
+def get_component_print_name(comp):
|
|
|
+ '''
|
|
|
+ Generates a human readeable string from the parameters depending on the type
|
|
|
+ '''
|
|
|
+ param_dict = {param['ro_parameter_type']: param for param in comp['ro_parameters']}
|
|
|
+
|
|
|
+ if comp['ro_component_type'] in ['Resistor', 'Resistor NTC']:
|
|
|
+ resistor_value = param_dict['Resistance']['value']
|
|
|
+ if resistor_value >= 10e8:
|
|
|
+ comp_name = f'{int(resistor_value / 10e8)}G{str(int(resistor_value % 10e8)).rstrip('0')}'
|
|
|
+ elif resistor_value >= 10e5:
|
|
|
+ comp_name = f'{int(resistor_value / 10e5)}M{str(int(resistor_value % 10e5)).rstrip('0')}'
|
|
|
+ elif resistor_value >= 10e2:
|
|
|
+ comp_name = f'{int(resistor_value / 10e2)}K{str(int(resistor_value % 10e2)).rstrip('0')}'
|
|
|
+ elif resistor_value >= 1.0:
|
|
|
+ comp_name = f'{int(resistor_value)}R{str(round(resistor_value % 1, 6))[2:].rstrip('0')}'
|
|
|
+ elif resistor_value == 0.0:
|
|
|
+ comp_name = '0R'
|
|
|
+ else:
|
|
|
+ comp_name = f'R{str(round(resistor_value % 1, 6))[2:]}'
|
|
|
+
|
|
|
+ if comp['ro_component_type'] == 'Resistor NTC':
|
|
|
+ comp_name += ' NTC'
|
|
|
+
|
|
|
+ if param_dict['Resistor technology']['text_value'] == 'laser trim':
|
|
|
+ comp_name += ' L'
|
|
|
+ else:
|
|
|
+ print(f'Unknown component type: {comp['ro_component_type']}')
|
|
|
+ return None
|
|
|
+
|
|
|
+ return comp_name
|
|
|
|
|
|
def char_range(c1, c2):
|
|
|
"""Generates the characters from `c1` to `c2`, exclusive."""
|
|
@@ -38,19 +70,27 @@ def handle_storage_qr_code(base_url, token, uuid):
|
|
|
|
|
|
if storage['template'] == MICE_TOILET_TEMPLATE:
|
|
|
|
|
|
+ side = input('Select type to be printed (top, bottom, storage) [t,b,s]:')
|
|
|
+ if side not in ['t', 'b', 's']:
|
|
|
+ print('Error - invalid side')
|
|
|
+ return None
|
|
|
+
|
|
|
+ if side == 's':
|
|
|
+ label = shimatta_label.storage_label.StorageLabelSmdMiceToilet()
|
|
|
+ storage = storage_json['results'][0]
|
|
|
+ label.put_content(f'[stor_uuid]{storage["id"]}',
|
|
|
+ storage['full_path'],
|
|
|
+ storage['verbose_name'])
|
|
|
+ return [label]
|
|
|
+
|
|
|
row = input('Select which row shall be printed [1..3]:')
|
|
|
if row not in char_range('1', '4'):
|
|
|
print('Error - invalid row')
|
|
|
return None
|
|
|
row = int(row)
|
|
|
|
|
|
- side = input('Select which side shall be printed [t,b]:')
|
|
|
- if side not in ['t', 'b']:
|
|
|
- print('Error - invalid side')
|
|
|
- return None
|
|
|
-
|
|
|
# get children
|
|
|
- query_res = requests.get(storage_query_url, headers={'Authorization': f'Token {token}'}, params={'parent_storage':uuid})
|
|
|
+ query_res = requests.get(storage_query_url, headers={'Authorization': f'Token {token}'}, params={'parent_storage':uuid, 'expand_stocks': True})
|
|
|
if query_res.status_code != 200:
|
|
|
print('Request for children unsuccessful')
|
|
|
sys.exit(-3)
|
|
@@ -76,6 +116,28 @@ def handle_storage_qr_code(base_url, token, uuid):
|
|
|
field_uuid = storage_dict[f'{column}{row}']['id']
|
|
|
label.put_content(f'[stor_uuid]{field_uuid}')
|
|
|
labels.append(label)
|
|
|
+
|
|
|
+ elif side == 't':
|
|
|
+
|
|
|
+ for column in char_range('a','i'):
|
|
|
+ label = shimatta_label.storage_label.StorageLabelSmdMiceToiletTop()
|
|
|
+
|
|
|
+ if not storage_dict[f'{column}{row}']['ro_stocks']:
|
|
|
+ print("Only printing start of row!!!")
|
|
|
+ break
|
|
|
+
|
|
|
+ comp = storage_dict[f'{column}{row}']['ro_stocks'][0]['ro_component']
|
|
|
+ param_dict = {param['ro_parameter_type']: param for param in comp['ro_parameters']}
|
|
|
+
|
|
|
+ comp_name = get_component_print_name(comp)
|
|
|
+ if not comp_name:
|
|
|
+ return[]
|
|
|
+
|
|
|
+ label.put_content(comp_name,
|
|
|
+ f"{param_dict['Tolerance']['value']}% {comp['package_data']['name']}",
|
|
|
+ comp['ro_manufacturer_name'])
|
|
|
+
|
|
|
+ labels.append(label)
|
|
|
else:
|
|
|
label = shimatta_label.storage_label.StorageLabel()
|
|
|
label.put_content(f'[stor_uuid]{uuid}', storage['full_path'], storage['verbose_name'])
|
|
@@ -107,7 +169,12 @@ def handle_component_qr_code(base_url, token, uuid):
|
|
|
|
|
|
labels = []
|
|
|
label = shimatta_label.component_label.ComponentLabelSmall()
|
|
|
- label.put_content(f'[comp_uuid]{uuid}', component['name'], manufacturer, pkg)
|
|
|
+
|
|
|
+ comp_name = get_component_print_name(component)
|
|
|
+ if not comp_name:
|
|
|
+ return[]
|
|
|
+
|
|
|
+ label.put_content(f'[comp_uuid]{uuid}', comp_name, manufacturer, pkg)
|
|
|
labels.append(label)
|
|
|
|
|
|
return labels
|