Skip to content

Commit

Permalink
Fix category creation script and category setup
Browse files Browse the repository at this point in the history
  • Loading branch information
eeintech committed Feb 24, 2023
1 parent d52726e commit 2134569
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 117 deletions.
8 changes: 4 additions & 4 deletions kintree/config/config_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ def sync_inventree_supplier_categories(inventree_config_path: str, supplier_conf
def add_supplier_category(categories: dict, supplier_config_path: str) -> bool:
''' Add Supplier category mapping to Supplier settings file
categories = {
'Capacitors':
{ 'Tantalum': 'Tantalum Capacitors' }
}
categories = {
'Capacitors':
{ 'Tantalum': 'Tantalum Capacitors' }
}
'''
try:
supplier_categories = load_file(supplier_config_path)
Expand Down
165 changes: 70 additions & 95 deletions kintree/config/inventree/categories.yaml
Original file line number Diff line number Diff line change
@@ -1,113 +1,88 @@
# Coding
CODES:
Assemblies: PCA
Capacitors: CAP
Circuit Protections: PRO
Connectors: CON
Crystals and Oscillators: CLK
Diodes: DIO
Inductors: IND
Integrated Circuits: ICS
Mechanicals: MEC
Miscellaneous: MIS
Modules: MOD
Power Management: PWR
Printed-Circuit Boards: PCB
RF: RFC
Resistors: RES
Transistors: TRA
# Parents and Children Categories
CATEGORIES:
Assemblies:
- Printed-Circuit Board Assembly
- Product
Printed-Circuit Board Assembly: null
Product: null
Capacitors:
Aluminium: null
Ceramic:
'0603':
10V:
- X5R
- X7R
16V:
- X5R
- X7R
'0402':
10V:
- X5R
- X7R
16V:
- X5R
- X7R
Aluminium:
Tantalum:
Polymer:
Super Capacitors:
'0402': null
'0603': null
'0805': null
Polymer: null
Super Capacitors: null
Tantalum: null
Circuit Protections:
- TVS
- Fuses
- PTC
Fuses: null
PTC: null
TVS: null
Connectors:
- Battery
- Board-to-Board
- Interface
- Coaxial
- FPC
- Header
# - Wire-to-Board
# - High-Speed
# - RF
# - Power
Battery: null
Board-to-Board: null
Coaxial: null
FPC: null
Header: null
Interface: null
Crystals and Oscillators:
- Crystals
- Oscillators
Crystals: null
Oscillators: null
Diodes:
- Standard
- Schottky
- Zener
- LED
LED: null
Schottky: null
Standard: null
Zener: null
Inductors:
- Power
- Ferrite Bead
# - RF
Ferrite Bead: null
Power: null
Integrated Circuits:
- Logic
- Interface
- Microcontroller
- Memory
- Sensor
# - SoC-CPU-GPU
# - FPGA-ASIC-CPLD
# - Driver
Interface: null
Logic: null
Memory: null
Microcontroller: null
Sensor: null
Mechanicals:
- Switch
- Standoff
- Nuts
- Screws
Nuts: null
Screws: null
Standoff: null
Switch: null
Miscellaneous:
- Batteries
Batteries: null
Modules: null
Printed-Circuit Boards: null
Power Management:
- PMIC
- LDO
- Buck
- Boost
Boost: null
Buck: null
LDO: null
PMIC: null
Printed-Circuit Boards: null
RF:
- Chipset
- Antenna
- Filter
- Shield
Antenna: null
Chipset: null
Filter: null
Shield: null
Resistors:
- Surface Mount
- Through Hole
- Potentiometers
- NTC
# - Array
NTC: null
Potentiometers: null
Surface Mount: null
Through Hole: null
Transistors:
- N-Channel FET
- P-Channel FET
- NPN
- PNP
- Load Switches
# - N+N-Channel FET
# - N+P-Channel FET
Load Switches: null
N-Channel FET: null
NPN: null
P-Channel FET: null
PNP: null
CODES:
Assemblies: PCA
Capacitors: CAP
Circuit Protections: PRO
Connectors: CON
Crystals and Oscillators: CLK
Diodes: DIO
Inductors: IND
Integrated Circuits: ICS
Mechanicals: MEC
Miscellaneous: MIS
Modules: MOD
Power Management: PWR
Printed-Circuit Boards: PCB
RF: RFC
Resistors: RES
Transistors: TRA
2 changes: 1 addition & 1 deletion kintree/database/inventree_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def build_tree(tree, left_to_go, level) -> list:

if reload:
categories = inventree_api.get_categories()
category_data['CATEGORIES'] = categories
category_data.update({'CATEGORIES': categories})
config_interface.dump_file(category_data, settings.CONFIG_CATEGORIES)
else:
categories = category_data.get('CATEGORIES', {})
Expand Down
30 changes: 13 additions & 17 deletions kintree/setup_inventree.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ def setup_inventree():
SETUP_CATEGORIES = True
SETUP_PARAMETERS = True

def create_categories(parent, name, categories):
category_pk, is_category_new = inventree_api.create_category(parent=parent, name=name)
if is_category_new:
cprint(f'[TREE]\tSuccess: Category "{name}" was added to InvenTree')
else:
cprint(f'[TREE]\tWarning: Category "{name}" already exists')

if categories[name]:
for cat in categories[name]:
create_categories(parent=name, name=cat, categories=categories[name])

if SETUP_CATEGORIES or SETUP_PARAMETERS:
cprint('\n[MAIN]\tStarting InvenTree setup', silent=settings.SILENT)
# Load category configuration file
categories = config_interface.load_file(settings.CONFIG_CATEGORIES)['CATEGORIES']
# cprint(categories)

cprint('[MAIN]\tConnecting to Inventree', silent=settings.SILENT)
inventree_connect = inventree_interface.connect_to_server()
Expand All @@ -24,22 +34,8 @@ def setup_inventree():

if SETUP_CATEGORIES:
for category in categories.keys():
cprint(f'\n[MAIN]\tCreating {category.upper()}')
category_pk, is_category_new = inventree_api.create_category(parent=None, name=category)
if is_category_new:
cprint(f'[TREE]\tSuccess: Category "{category}" was added to InvenTree')
else:
cprint(f'[TREE]\tWarning: Category "{category}" already exists')

if categories[category]:
cprint('[MAIN]\tCreating Subcategories')
for subcategory in categories[category]:
sub_category_pk, is_subcategory_new = inventree_api.create_category(parent=category, name=subcategory)

if is_subcategory_new:
cprint(f'[TREE]\tSuccess: Subcategory "{category}/{subcategory}" was added to InvenTree')
else:
cprint(f'[TREE]\tWarning: Subcategory "{category}/{subcategory}" already exists')
cprint(f'\n[MAIN]\tCreating categories in {category.upper()}')
create_categories(parent=None, name=category, categories=categories)

if SETUP_PARAMETERS:
# Load parameter configuration file
Expand Down

0 comments on commit 2134569

Please sign in to comment.