Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 77 additions & 99 deletions pcbmode/pcbmode.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pcbmode/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# coding=utf-8
13 changes: 5 additions & 8 deletions pcbmode/utils/board.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#!/usr/bin/python
# coding=utf-8

import pcbmode.config as config
from . import messages as msg
from .module import Module
from __future__ import absolute_import

import pcbmode.config as config
from pcbmode.utils.module import Module


class Board():
class Board(object):
"""
"""

def __init__(self):

self._module_dict = config.brd
self._module_routing = config.rte
module = Module(self._module_dict,
self._module_routing)



143 changes: 65 additions & 78 deletions pcbmode/utils/bom.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/python
# coding=utf-8
from __future__ import absolute_import

#import json
import os
import re
import pcbmode.config as config

from . import utils
from . import messages as msg

import pcbmode.config as config
from pcbmode.utils import messages as msg, utils


def make_bom(quantity=None):
Expand All @@ -19,13 +18,11 @@ def natural_key(string_):
"""See http://www.codinghorror.com/blog/archives/001018.html"""
return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_)]



dnp_text = 'Do not populate'
uncateg_text = 'Uncategorised'

components_dict = config.brd['components']

bom_dict = {}

for refdef in components_dict:
Expand All @@ -50,26 +47,25 @@ def natural_key(string_):
footprint_name = components_dict[refdef]['footprint']
except:
msg.error("Cannot find a 'footprint' name for refdef %s." % refdef)

# Open footprint file
fname = os.path.join(config.cfg['base-dir'],
config.cfg['locations']['components'],
footprint_name + '.json')
footprint_dict = utils.dictFromJsonFile(fname)

info_dict = footprint_dict.get('info') or {}
try:

try:
comp_bom_dict = components_dict[refdef]['bom']
except:
comp_bom_dict = {}
try:

try:
fp_bom_dict = footprint_dict['info']
except:
fp_bom_dict = {}



# Override component BoM info on top of footprint info
for key in comp_bom_dict:
fp_bom_dict[key] = comp_bom_dict[key]
Expand All @@ -79,78 +75,75 @@ def natural_key(string_):
try:
dnp = components_dict[refdef]['bom']['dnp']
except:
dnp = False
dnp = False

if dnp == True:
description = dnp_text

if description not in bom_dict:
bom_dict[description] = fp_bom_dict
bom_dict[description]['refdefs'] = []
bom_dict[description]['refdefs'].append(refdef)


try:
bom_content = config.brd['bom']
except:
bom_content = [
{
"field": "line-item",
"text": "#"
"field": "line-item",
"text": "#"
},
{
"field": "quantity",
"text": "Qty"
"field": "quantity",
"text": "Qty"
},
{
"field": "designators",
"text": "Designators"
},
"field": "designators",
"text": "Designators"
},
{
"field": "description",
"text": "Description"
},
"field": "description",
"text": "Description"
},
{
"field": "package",
"text": "Package"
},
"field": "package",
"text": "Package"
},
{
"field": "manufacturer",
"text": "Manufacturer"
},
"field": "manufacturer",
"text": "Manufacturer"
},
{
"field": "part-number",
"text": "Part #"
"field": "part-number",
"text": "Part #"
},
{
"field": "suppliers",
"text": "Suppliers",
"suppliers":
[
{
"field": "farnell",
"text": "Farnell #",
"search-url": "http://uk.farnell.com/catalog/Search?st="
},
{
"field": "mouser",
"text": "Mouser #",
"search-url": "http://uk.mouser.com/Search/Refine.aspx?Keyword="
},
{
"field": "octopart",
"text": "Octopart",
"search-url": "https://octopart.com/search?q="
}
]
"field": "suppliers",
"text": "Suppliers",
"suppliers":
[
{
"field": "farnell",
"text": "Farnell #",
"search-url": "http://uk.farnell.com/catalog/Search?st="
},
{
"field": "mouser",
"text": "Mouser #",
"search-url": "http://uk.mouser.com/Search/Refine.aspx?Keyword="
},
{
"field": "octopart",
"text": "Octopart",
"search-url": "https://octopart.com/search?q="
}
]
},
{
"field": "notes",
"text": "Notes"
"field": "notes",
"text": "Notes"
}
]


]

# Set up the BoM file name
bom_path = os.path.join(config.cfg['base-dir'],
Expand All @@ -163,14 +156,12 @@ def natural_key(string_):
board_revision = config.brd['config'].get('rev')
base_name = "%s_rev_%s" % (board_name, board_revision)

bom_html = os.path.join(bom_path, base_name + '_%s.html'% 'bom')
bom_csv = os.path.join(bom_path, base_name + '_%s.csv'% 'bom')

bom_html = os.path.join(bom_path, base_name + '_%s.html' % 'bom')
bom_csv = os.path.join(bom_path, base_name + '_%s.csv' % 'bom')

html = []
csv = []


html.append('<html>')
html.append('<style type="text/css">')
try:
Expand All @@ -194,15 +185,15 @@ def natural_key(string_):

html.append(' <tr>')
html.append(' <th class="tg-title" colspan="%s">Bill of materials -- %s rev %s</th>' % (len(header), board_name, board_revision))
html.append(' </tr>')
html.append(' </tr>')
html.append(' <tr>')
for item in header:
if item == 'Designators':
html.append(' <th class="tg-header-des">%s</th>' % item)
else:
html.append(' <th class="tg-header">%s</th>' % item)
html.append(' </tr>')

uncateg_content = []
dnp_content = []
index = 1
Expand Down Expand Up @@ -230,7 +221,7 @@ def natural_key(string_):
units = len(bom_dict[desc]['refdefs'])
content.append("%s" % (str(units)))
if quantity != None:
content.append("%s" % (str(units*int(quantity))))
content.append("%s" % (str(units * int(quantity))))
elif item['field'] == 'designators':
# Natural/human sort the list of designators
sorted_list = sorted(bom_dict[desc]['refdefs'], key=natural_key)
Expand Down Expand Up @@ -261,23 +252,21 @@ def natural_key(string_):
else:
html.append(' <tr>')
for item in content:
html.append(' <td class="tg-item-%s">%s</td>' % (('odd','even')[index%2==0], item))
html.append(' <td class="tg-item-%s">%s</td>' % (('odd', 'even')[index % 2 == 0], item))
html.append(' </tr>')
index += 1


for content in (dnp_content, uncateg_content):
html.append(' <tr class="tg-skip">')
html.append(' </tr>')
html.append(' </tr>')
html.append(' <tr>')
if len(content) > 0:
content[0] = index
for item in content:
html.append(' <td class="tg-item-%s">%s</td>' % (('odd','even')[index%2==0], item))
html.append(' <td class="tg-item-%s">%s</td>' % (('odd', 'even')[index % 2 == 0], item))
html.append(' </tr>')
index += 1


html.append('</table>')

html.append('<p>Generated by <a href="http://pcbmode.com">PCBmodE</a>, maintained by <a href="http://boldport.com">Boldport</a>.')
Expand All @@ -286,9 +275,7 @@ def natural_key(string_):

with open(bom_html, "wb") as f:
for line in html:
f.write(line+'\n')


#print bom_dict
f.write(line + '\n')


# print bom_dict
Loading