diff --git a/eeschema/plugins/python_scripts/bom_csv_grouped_by_value.py b/eeschema/plugins/python_scripts/bom_csv_grouped_by_value.py index 7ce2d98cc0..8a3729ada2 100644 --- a/eeschema/plugins/python_scripts/bom_csv_grouped_by_value.py +++ b/eeschema/plugins/python_scripts/bom_csv_grouped_by_value.py @@ -25,11 +25,14 @@ import csv import sys # A helper function to convert a UTF8/Unicode/locale string read in netlist -# for python2 or python3 +# for python2 or python3 (Windows/unix) def fromNetlistText( aText ): - try: - return aText.encode('utf-8').decode('cp1252') - except UnicodeDecodeError: + if sys.platform.startswith('win32'): + try: + return aText.encode('utf-8').decode('cp1252') + except UnicodeDecodeError: + return aText + else: return aText def myEqu(self, other): diff --git a/eeschema/plugins/python_scripts/bom_csv_grouped_by_value_with_fp.py b/eeschema/plugins/python_scripts/bom_csv_grouped_by_value_with_fp.py index ab5bae7156..edfd624b67 100644 --- a/eeschema/plugins/python_scripts/bom_csv_grouped_by_value_with_fp.py +++ b/eeschema/plugins/python_scripts/bom_csv_grouped_by_value_with_fp.py @@ -23,9 +23,12 @@ import sys # A helper function to convert a UTF8/Unicode/locale string read in netlist # for python2 or python3 def fromNetlistText( aText ): - try: - return aText.encode('utf-8').decode('cp1252') - except UnicodeDecodeError: + if sys.platform.startswith('win32'): + try: + return aText.encode('utf-8').decode('cp1252') + except UnicodeDecodeError: + return aText + else: return aText # Generate an instance of a generic netlist, and load the netlist tree from diff --git a/eeschema/plugins/python_scripts/bom_csv_sorted_by_ref.py b/eeschema/plugins/python_scripts/bom_csv_sorted_by_ref.py index 05f0eb328b..7e6ff19486 100644 --- a/eeschema/plugins/python_scripts/bom_csv_sorted_by_ref.py +++ b/eeschema/plugins/python_scripts/bom_csv_sorted_by_ref.py @@ -25,9 +25,12 @@ import sys # A helper function to convert a UTF8/Unicode/locale string read in netlist # for python2 or python3 def fromNetlistText( aText ): - try: - return aText.encode('utf-8').decode('cp1252') - except UnicodeDecodeError: + if sys.platform.startswith('win32'): + try: + return aText.encode('utf-8').decode('cp1252') + except UnicodeDecodeError: + return aText + else: return aText # Generate an instance of a generic netlist, and load the netlist tree from diff --git a/eeschema/plugins/python_scripts/bom_html_grouped_by_value.py b/eeschema/plugins/python_scripts/bom_html_grouped_by_value.py index d83e8ebdb6..533b4cdaf3 100644 --- a/eeschema/plugins/python_scripts/bom_html_grouped_by_value.py +++ b/eeschema/plugins/python_scripts/bom_html_grouped_by_value.py @@ -21,6 +21,17 @@ from __future__ import print_function import kicad_netlist_reader import sys +# A helper function to convert a UTF8/Unicode/locale string read in netlist +# for python2 or python3 +def fromNetlistText( aText ): + if sys.platform.startswith('win32'): + try: + return aText.encode('utf-8').decode('cp1252') + except UnicodeDecodeError: + return aText + else: + return aText + # Start with a basic html template html = """ ', row + "") # Print the formatted html to the file -try: - print(html.encode('utf-8').decode('cp1252'), file=f) -except: - print(html, file=f) +print(fromNetlistText(html), file=f) diff --git a/eeschema/plugins/python_scripts/bom_html_with_advanced_grouping.py b/eeschema/plugins/python_scripts/bom_html_with_advanced_grouping.py index 653c72733e..4dadf1f18f 100644 --- a/eeschema/plugins/python_scripts/bom_html_with_advanced_grouping.py +++ b/eeschema/plugins/python_scripts/bom_html_with_advanced_grouping.py @@ -21,6 +21,17 @@ from __future__ import print_function import kicad_netlist_reader import sys +# A helper function to convert a UTF8/Unicode/locale string read in netlist +# for python2 or python3 +def fromNetlistText( aText ): + if sys.platform.startswith('win32'): + try: + return aText.encode('utf-8').decode('cp1252') + except UnicodeDecodeError: + return aText + else: + return aText + # Start with a basic html template html = """ ', row + "") # Print the formatted html to output file -try: - print(html.encode('utf-8').decode('cp1252'), file=f) -except: - print(html, file=f) +print(fromNetlistText(html), file=f) diff --git a/eeschema/plugins/python_scripts/bom_txt_sorted_by_ref.py b/eeschema/plugins/python_scripts/bom_txt_sorted_by_ref.py index bbf08cb9db..b14cdb2c76 100644 --- a/eeschema/plugins/python_scripts/bom_txt_sorted_by_ref.py +++ b/eeschema/plugins/python_scripts/bom_txt_sorted_by_ref.py @@ -20,6 +20,17 @@ import kicad_netlist_reader import csv import sys +# A helper function to convert a UTF8/Unicode/locale string read in netlist +# for python2 or python3 (Windows/unix) +def fromNetlistText( aText ): + if sys.platform.startswith('win32'): + try: + return aText.encode('utf-8').decode('cp1252') + except UnicodeDecodeError: + return aText + else: + return aText + # Generate an instance of a generic netlist, and load the netlist tree from # the command line option. If the file doesn't exist, execution will stop net = kicad_netlist_reader.netlist(sys.argv[1]) @@ -42,7 +53,7 @@ def writerow( acsvwriter, columns ): utf8row = [] for col in columns: txt=str(col); - utf8row.append( txt ) + utf8row.append( fromNetlistText(txt) ) acsvwriter.writerow( utf8row ) components = net.getInterestingComponents()