|
@@ -11,6 +11,28 @@ import json
|
|
|
import re
|
|
|
|
|
|
MICE_TOILET_TEMPLATE = 'https://parts.shimatta.net/api/v1/parts/storages/075acbaf-ed60-47b9-9bd5-98bfbc3a79ea/'
|
|
|
+SMD_STRAP_PAGE_TEMPLATE = 'https://parts.shimatta.net/api/v1/parts/storages/4df58899-7338-48f5-9d93-cf5a59a6a400/'
|
|
|
+
|
|
|
+def get_child_storages(storage_query_url, token, uuid, expected_amount):
|
|
|
+ # get children
|
|
|
+ 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)
|
|
|
+
|
|
|
+ storage_json = query_res.json()
|
|
|
+ if storage_json['count'] != expected_amount:
|
|
|
+ print('Storage json does not contain correct amount of storage entries')
|
|
|
+ sys.exit(-1)
|
|
|
+
|
|
|
+ # pagination
|
|
|
+ storage_list = storage_json['results']
|
|
|
+ while storage_json['next']:
|
|
|
+ query_res = requests.get(storage_json['next'], headers={'Authorization': f'Token {token}'}, params={'parent_storage':uuid})
|
|
|
+ storage_json = query_res.json()
|
|
|
+ storage_list.extend(storage_json['results'])
|
|
|
+
|
|
|
+ return {storage['name']: storage for storage in storage_list}
|
|
|
|
|
|
def get_component_print_name(comp):
|
|
|
'''
|
|
@@ -89,25 +111,7 @@ def handle_storage_qr_code(base_url, token, uuid):
|
|
|
return None
|
|
|
row = int(row)
|
|
|
|
|
|
- # get children
|
|
|
- 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)
|
|
|
-
|
|
|
- storage_json = query_res.json()
|
|
|
- if storage_json['count'] != 24:
|
|
|
- print('Storage json does not contain correct amount of storage entries')
|
|
|
- sys.exit(-1)
|
|
|
-
|
|
|
- # pagination
|
|
|
- storage_list = storage_json['results']
|
|
|
- while storage_json['next']:
|
|
|
- query_res = requests.get(storage_json['next'], headers={'Authorization': f'Token {token}'}, params={'parent_storage':uuid})
|
|
|
- storage_json = query_res.json()
|
|
|
- storage_list.extend(storage_json['results'])
|
|
|
-
|
|
|
- storage_dict = {storage['name']: storage for storage in storage_list}
|
|
|
+ storage_dict = get_child_storages(storage_query_url, token, uuid, 24)
|
|
|
|
|
|
if side == 'b':
|
|
|
|
|
@@ -138,6 +142,47 @@ def handle_storage_qr_code(base_url, token, uuid):
|
|
|
comp['ro_manufacturer_name'])
|
|
|
|
|
|
labels.append(label)
|
|
|
+ elif storage['template'] == SMD_STRAP_PAGE_TEMPLATE:
|
|
|
+
|
|
|
+ type = input('Select type to be printed (components, storage) [c,s]:')
|
|
|
+ if type not in ['c', 's']:
|
|
|
+ print('Error - invalid type')
|
|
|
+ return None
|
|
|
+
|
|
|
+ if type == 's':
|
|
|
+ label = shimatta_label.storage_label.StorageLabelSmdStrap()
|
|
|
+ label.put_content(f'[stor_uuid]{uuid}', storage['full_path'], storage['verbose_name'])
|
|
|
+ labels.append(label)
|
|
|
+ return [label]
|
|
|
+
|
|
|
+ storage_dict = get_child_storages(storage_query_url, token, uuid, 12)
|
|
|
+
|
|
|
+ for row in range(1,13):
|
|
|
+ label = shimatta_label.component_label.StorageComponentLabelSmdBook()
|
|
|
+
|
|
|
+ if not storage_dict[f'{row}']['ro_stocks']:
|
|
|
+ print("Only printing start of column!!!")
|
|
|
+ break
|
|
|
+
|
|
|
+ storage_uuid = storage_dict[f'{row}']['id']
|
|
|
+ stock_uuild = storage_dict[f'{row}']['ro_stocks'][0]['id']
|
|
|
+ comp = storage_dict[f'{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(f'[stor_uuid]{storage_uuid}',
|
|
|
+ f'[stck_uuid]{stock_uuild}',
|
|
|
+ comp_name,
|
|
|
+ f"{param_dict['Tolerance']['value']}% {comp['package_data']['name']}",
|
|
|
+ comp['ro_manufacturer_name'])
|
|
|
+
|
|
|
+ labels.append(label)
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
else:
|
|
|
label = shimatta_label.storage_label.StorageLabel()
|
|
|
label.put_content(f'[stor_uuid]{uuid}', storage['full_path'], storage['verbose_name'])
|
|
@@ -205,14 +250,17 @@ login_token = json.loads(ans.content)['token']
|
|
|
while True:
|
|
|
qr = input('Please scan Storage or Component QR: ')
|
|
|
|
|
|
- matches = qr_re.match(qr)
|
|
|
- if matches.group('prefix') == 'stor_uuid' :
|
|
|
- labels = handle_storage_qr_code(kenkyusho_url, login_token, matches.group('uuid'))
|
|
|
- elif matches.group('prefix') == 'comp_uuid':
|
|
|
- labels = handle_component_qr_code(kenkyusho_url, login_token, matches.group('uuid'))
|
|
|
- else:
|
|
|
- print('Invalid QR code!')
|
|
|
- continue
|
|
|
+ try:
|
|
|
+ matches = qr_re.match(qr)
|
|
|
+ if matches.group('prefix') == 'stor_uuid' :
|
|
|
+ labels = handle_storage_qr_code(kenkyusho_url, login_token, matches.group('uuid'))
|
|
|
+ elif matches.group('prefix') == 'comp_uuid':
|
|
|
+ labels = handle_component_qr_code(kenkyusho_url, login_token, matches.group('uuid'))
|
|
|
+ else:
|
|
|
+ print('Invalid QR code!')
|
|
|
+ continue
|
|
|
|
|
|
- if labels:
|
|
|
- ql_wrapper.print_labels(labels)
|
|
|
+ if labels:
|
|
|
+ ql_wrapper.print_labels(labels)
|
|
|
+ except Exception as ex:
|
|
|
+ print("Something went wrong:", ex)
|