Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
1e8430d5
Commit
1e8430d5
authored
Sep 19, 2013
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lorenzo's help enabled a fix to UTF8 support in csv.writer in python bom generators.
parent
c7531d6c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
28 deletions
+49
-28
bom_csv_by_ref.py
scripts/bom-in-python/bom_csv_by_ref.py
+13
-6
bom_csv_by_ref_v2.py
scripts/bom-in-python/bom_csv_by_ref_v2.py
+13
-6
bom_csv_grouped_by_value.py
scripts/bom-in-python/bom_csv_grouped_by_value.py
+23
-16
No files found.
scripts/bom-in-python/bom_csv_by_ref.py
View file @
1e8430d5
...
...
@@ -27,16 +27,23 @@ except IOError:
# are created a tab delimited list instead!
out
=
csv
.
writer
(
f
,
lineterminator
=
'
\n
'
,
delimiter
=
'
\t
'
,
quoting
=
csv
.
QUOTE_NONE
)
# override csv.writer's writerow() to support utf8 encoding:
def
writerow
(
acsvwriter
,
columns
):
utf8row
=
[]
for
col
in
columns
:
utf8row
.
append
(
str
(
col
)
.
encode
(
'utf8'
)
)
acsvwriter
.
writerow
(
utf8row
)
# Output a field delimited header line
out
.
writerow
([
'Source:'
,
net
.
getSource
()]
)
out
.
writerow
([
'Date:'
,
net
.
getDate
()]
)
out
.
writerow
([
'Tool:'
,
net
.
getTool
()]
)
out
.
writerow
([
'Component Count:'
,
len
(
net
.
components
)]
)
out
.
writerow
([
'Ref'
,
'Value'
,
'Part'
,
'Documentation'
,
'Description'
,
'Vendor'
]
)
writerow
(
out
,
[
'Source:'
,
net
.
getSource
()]
)
writerow
(
out
,
[
'Date:'
,
net
.
getDate
()]
)
writerow
(
out
,
[
'Tool:'
,
net
.
getTool
()]
)
writerow
(
out
,
[
'Component Count:'
,
len
(
net
.
components
)]
)
writerow
(
out
,
[
'Ref'
,
'Value'
,
'Part'
,
'Documentation'
,
'Description'
,
'Vendor'
]
)
components
=
net
.
getInterestingComponents
()
# Output all of the component information
for
c
in
components
:
out
.
writerow
(
[
c
.
getRef
(),
c
.
getValue
(),
c
.
getLibName
()
+
":"
+
c
.
getPartName
(),
writerow
(
out
,
[
c
.
getRef
(),
c
.
getValue
(),
c
.
getLibName
()
+
":"
+
c
.
getPartName
(),
c
.
getDatasheet
(),
c
.
getDescription
(),
c
.
getField
(
"Vendor"
)])
scripts/bom-in-python/bom_csv_by_ref_v2.py
View file @
1e8430d5
...
...
@@ -26,17 +26,24 @@ except IOError:
# Create a new csv writer object to use as the output formatter
out
=
csv
.
writer
(
f
,
lineterminator
=
'
\n
'
,
delimiter
=
','
,
quotechar
=
"
\"
"
,
quoting
=
csv
.
QUOTE_ALL
)
# override csv.writer's writerow() to support utf8 encoding:
def
writerow
(
acsvwriter
,
columns
):
utf8row
=
[]
for
col
in
columns
:
utf8row
.
append
(
str
(
col
)
.
encode
(
'utf8'
)
)
acsvwriter
.
writerow
(
utf8row
)
# Output a field delimited header line
out
.
writerow
([
'Source:'
,
net
.
getSource
()]
)
out
.
writerow
([
'Date:'
,
net
.
getDate
()]
)
out
.
writerow
([
'Tool:'
,
net
.
getTool
()]
)
out
.
writerow
([
'Component Count:'
,
len
(
net
.
components
)]
)
out
.
writerow
([
'Ref'
,
'Value'
,
'Footprint'
,
'Datasheet'
,
'Manufacturer'
,
'Vendor'
]
)
writerow
(
out
,
[
'Source:'
,
net
.
getSource
()]
)
writerow
(
out
,
[
'Date:'
,
net
.
getDate
()]
)
writerow
(
out
,
[
'Tool:'
,
net
.
getTool
()]
)
writerow
(
out
,
[
'Component Count:'
,
len
(
net
.
components
)]
)
writerow
(
out
,
[
'Ref'
,
'Value'
,
'Footprint'
,
'Datasheet'
,
'Manufacturer'
,
'Vendor'
]
)
components
=
net
.
getInterestingComponents
()
# Output all of the component information (One component per row)
for
c
in
components
:
out
.
writerow
(
[
c
.
getRef
(),
c
.
getValue
(),
c
.
getFootprint
(),
c
.
getDatasheet
(),
writerow
(
out
,
[
c
.
getRef
(),
c
.
getValue
(),
c
.
getFootprint
(),
c
.
getDatasheet
(),
c
.
getField
(
"Manufacturer"
),
c
.
getField
(
"Vendor"
)])
scripts/bom-in-python/bom_csv_grouped_by_value.py
View file @
1e8430d5
...
...
@@ -47,15 +47,22 @@ columns = ['Item', 'Qty', 'Reference(s)', 'Value', 'LibPart', 'Footprint', 'Data
# Create a new csv writer object to use as the output formatter
out
=
csv
.
writer
(
f
,
lineterminator
=
'
\n
'
,
delimiter
=
','
,
quotechar
=
'
\"
'
,
quoting
=
csv
.
QUOTE_MINIMAL
)
# override csv.writer's writerow() to support utf8 encoding:
def
writerow
(
acsvwriter
,
columns
):
utf8row
=
[]
for
col
in
columns
:
utf8row
.
append
(
str
(
col
)
.
encode
(
'utf8'
)
)
acsvwriter
.
writerow
(
utf8row
)
# Output a set of rows as a header providing general information
out
.
writerow
([
'Source:'
,
net
.
getSource
()]
)
out
.
writerow
([
'Date:'
,
net
.
getDate
()]
)
out
.
writerow
([
'Tool:'
,
net
.
getTool
()]
)
out
.
writerow
([
'Component Count:'
,
len
(
components
)]
)
out
.
writerow
([]
)
out
.
writerow
([
'Individual Components:'
]
)
out
.
writerow
([]
)
# blank line
out
.
writerow
(
columns
)
writerow
(
out
,
[
'Source:'
,
net
.
getSource
()]
)
writerow
(
out
,
[
'Date:'
,
net
.
getDate
()]
)
writerow
(
out
,
[
'Tool:'
,
net
.
getTool
()]
)
writerow
(
out
,
[
'Component Count:'
,
len
(
components
)]
)
writerow
(
out
,
[]
)
writerow
(
out
,
[
'Individual Components:'
]
)
writerow
(
out
,
[]
)
# blank line
writerow
(
out
,
columns
)
# Output all the interesting components individually first:
row
=
[]
...
...
@@ -74,16 +81,16 @@ for c in components:
for
field
in
columns
[
7
:]:
row
.
append
(
c
.
getField
(
field
)
);
out
.
writerow
(
row
)
writerow
(
out
,
row
)
out
.
writerow
([]
)
# blank line
out
.
writerow
([]
)
# blank line
out
.
writerow
([]
)
# blank line
writerow
(
out
,
[]
)
# blank line
writerow
(
out
,
[]
)
# blank line
writerow
(
out
,
[]
)
# blank line
out
.
writerow
([
'Collated Components:'
]
)
out
.
writerow
([]
)
# blank line
out
.
writerow
(
columns
)
# reuse same columns
writerow
(
out
,
[
'Collated Components:'
]
)
writerow
(
out
,
[]
)
# blank line
writerow
(
out
,
columns
)
# reuse same columns
...
...
@@ -121,6 +128,6 @@ for group in grouped:
for
field
in
columns
[
7
:]:
row
.
append
(
net
.
getGroupField
(
group
,
field
)
);
out
.
writerow
(
row
)
writerow
(
out
,
row
)
f
.
close
()
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