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
Hide 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:
...
@@ -27,16 +27,23 @@ except IOError:
# are created a tab delimited list instead!
# are created a tab delimited list instead!
out
=
csv
.
writer
(
f
,
lineterminator
=
'
\n
'
,
delimiter
=
'
\t
'
,
quoting
=
csv
.
QUOTE_NONE
)
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
# Output a field delimited header line
out
.
writerow
([
'Source:'
,
net
.
getSource
()]
)
writerow
(
out
,
[
'Source:'
,
net
.
getSource
()]
)
out
.
writerow
([
'Date:'
,
net
.
getDate
()]
)
writerow
(
out
,
[
'Date:'
,
net
.
getDate
()]
)
out
.
writerow
([
'Tool:'
,
net
.
getTool
()]
)
writerow
(
out
,
[
'Tool:'
,
net
.
getTool
()]
)
out
.
writerow
([
'Component Count:'
,
len
(
net
.
components
)]
)
writerow
(
out
,
[
'Component Count:'
,
len
(
net
.
components
)]
)
out
.
writerow
([
'Ref'
,
'Value'
,
'Part'
,
'Documentation'
,
'Description'
,
'Vendor'
]
)
writerow
(
out
,
[
'Ref'
,
'Value'
,
'Part'
,
'Documentation'
,
'Description'
,
'Vendor'
]
)
components
=
net
.
getInterestingComponents
()
components
=
net
.
getInterestingComponents
()
# Output all of the component information
# Output all of the component information
for
c
in
components
:
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"
)])
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:
...
@@ -26,17 +26,24 @@ except IOError:
# Create a new csv writer object to use as the output formatter
# Create a new csv writer object to use as the output formatter
out
=
csv
.
writer
(
f
,
lineterminator
=
'
\n
'
,
delimiter
=
','
,
quotechar
=
"
\"
"
,
quoting
=
csv
.
QUOTE_ALL
)
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
# Output a field delimited header line
out
.
writerow
([
'Source:'
,
net
.
getSource
()]
)
writerow
(
out
,
[
'Source:'
,
net
.
getSource
()]
)
out
.
writerow
([
'Date:'
,
net
.
getDate
()]
)
writerow
(
out
,
[
'Date:'
,
net
.
getDate
()]
)
out
.
writerow
([
'Tool:'
,
net
.
getTool
()]
)
writerow
(
out
,
[
'Tool:'
,
net
.
getTool
()]
)
out
.
writerow
([
'Component Count:'
,
len
(
net
.
components
)]
)
writerow
(
out
,
[
'Component Count:'
,
len
(
net
.
components
)]
)
out
.
writerow
([
'Ref'
,
'Value'
,
'Footprint'
,
'Datasheet'
,
'Manufacturer'
,
'Vendor'
]
)
writerow
(
out
,
[
'Ref'
,
'Value'
,
'Footprint'
,
'Datasheet'
,
'Manufacturer'
,
'Vendor'
]
)
components
=
net
.
getInterestingComponents
()
components
=
net
.
getInterestingComponents
()
# Output all of the component information (One component per row)
# Output all of the component information (One component per row)
for
c
in
components
:
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"
)])
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
...
@@ -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
# Create a new csv writer object to use as the output formatter
out
=
csv
.
writer
(
f
,
lineterminator
=
'
\n
'
,
delimiter
=
','
,
quotechar
=
'
\"
'
,
quoting
=
csv
.
QUOTE_MINIMAL
)
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
# Output a set of rows as a header providing general information
out
.
writerow
([
'Source:'
,
net
.
getSource
()]
)
writerow
(
out
,
[
'Source:'
,
net
.
getSource
()]
)
out
.
writerow
([
'Date:'
,
net
.
getDate
()]
)
writerow
(
out
,
[
'Date:'
,
net
.
getDate
()]
)
out
.
writerow
([
'Tool:'
,
net
.
getTool
()]
)
writerow
(
out
,
[
'Tool:'
,
net
.
getTool
()]
)
out
.
writerow
([
'Component Count:'
,
len
(
components
)]
)
writerow
(
out
,
[
'Component Count:'
,
len
(
components
)]
)
out
.
writerow
([]
)
writerow
(
out
,
[]
)
out
.
writerow
([
'Individual Components:'
]
)
writerow
(
out
,
[
'Individual Components:'
]
)
out
.
writerow
([]
)
# blank line
writerow
(
out
,
[]
)
# blank line
out
.
writerow
(
columns
)
writerow
(
out
,
columns
)
# Output all the interesting components individually first:
# Output all the interesting components individually first:
row
=
[]
row
=
[]
...
@@ -74,16 +81,16 @@ for c in components:
...
@@ -74,16 +81,16 @@ for c in components:
for
field
in
columns
[
7
:]:
for
field
in
columns
[
7
:]:
row
.
append
(
c
.
getField
(
field
)
);
row
.
append
(
c
.
getField
(
field
)
);
out
.
writerow
(
row
)
writerow
(
out
,
row
)
out
.
writerow
([]
)
# blank line
writerow
(
out
,
[]
)
# blank line
out
.
writerow
([]
)
# blank line
writerow
(
out
,
[]
)
# blank line
out
.
writerow
([]
)
# blank line
writerow
(
out
,
[]
)
# blank line
out
.
writerow
([
'Collated Components:'
]
)
writerow
(
out
,
[
'Collated Components:'
]
)
out
.
writerow
([]
)
# blank line
writerow
(
out
,
[]
)
# blank line
out
.
writerow
(
columns
)
# reuse same columns
writerow
(
out
,
columns
)
# reuse same columns
...
@@ -121,6 +128,6 @@ for group in grouped:
...
@@ -121,6 +128,6 @@ for group in grouped:
for
field
in
columns
[
7
:]:
for
field
in
columns
[
7
:]:
row
.
append
(
net
.
getGroupField
(
group
,
field
)
);
row
.
append
(
net
.
getGroupField
(
group
,
field
)
);
out
.
writerow
(
row
)
writerow
(
out
,
row
)
f
.
close
()
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