Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
ORS Hardware
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yoji Takeuchi
ORS Hardware
Commits
17fc22a9
Commit
17fc22a9
authored
Mar 29, 2023
by
Thomas Gambier
🚴🏼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: add compare_BOM.py
parent
fe3a9293
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
tools/compare_BOM.py
tools/compare_BOM.py
+65
-0
No files found.
tools/compare_BOM.py
0 → 100644
View file @
17fc22a9
#! /usr/bin/env python3
import
argparse
import
pprint
import
pandas
parser
=
argparse
.
ArgumentParser
(
description
=
"Compare 2 BOMs in ODF format (dumped by Altium in Excel and then converted to ods)"
)
parser
.
add_argument
(
'ref_BOM'
)
parser
.
add_argument
(
'new_BOM'
)
args
=
parser
.
parse_args
()
pp
=
pprint
.
PrettyPrinter
(
indent
=
4
)
def
read_line_eof
(
f
):
l
=
f
.
readline
()
if
len
(
l
)
==
0
:
raise
EOFError
return
l
.
strip
()
def
read_BOM
(
f
):
c
=
{}
bom
=
pandas
.
read_excel
(
f
,
engine
=
"odf"
)
#print(bom)
for
index
,
row
in
bom
.
iterrows
():
infos
=
{
'value'
:
row
[
"Value"
],
'infos'
:
row
[
"Infos"
]
}
for
comp
in
row
[
"Designator"
].
split
(
','
):
c
[
comp
]
=
infos
return
c
def
dict_compare
(
d1
,
d2
):
d1_keys
=
set
(
d1
.
keys
())
d2_keys
=
set
(
d2
.
keys
())
shared_keys
=
d1_keys
.
intersection
(
d2_keys
)
added
=
d2_keys
-
d1_keys
removed
=
d1_keys
-
d2_keys
modified
=
{
o
:
(
d1
[
o
],
d2
[
o
])
for
o
in
shared_keys
if
d1
[
o
]
!=
d2
[
o
]}
same
=
set
(
o
for
o
in
shared_keys
if
d1
[
o
]
==
d2
[
o
])
return
added
,
removed
,
modified
,
same
def
pprint
(
o
):
if
len
(
o
)
>
0
:
pp
.
pprint
(
o
)
else
:
print
(
None
)
def
compare_netlist
(
BOM_ref
,
BOM_new
):
comp_added
,
comp_removed
,
comp_modified
,
comp_same
=
dict_compare
(
BOM_ref
,
BOM_new
)
print
(
"******************************************************"
)
print
(
"******************************************************"
)
print
(
"Added in BOM:"
)
pprint
(
comp_added
)
print
(
"Removed in BOM:"
)
pprint
(
comp_removed
)
print
(
"Modified in BOM:"
)
pprint
(
comp_modified
)
compare_netlist
(
read_BOM
(
args
.
ref_BOM
),
read_BOM
(
args
.
new_BOM
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment