Added experimental option to accept CSV files without reference.

This commit is contained in:
Salvador E. Tropea 2022-09-15 14:05:24 -03:00
parent 5c825151b0
commit 4f54712a94
3 changed files with 22 additions and 8 deletions

View File

@ -136,6 +136,8 @@ class Globals(FiltersOptions):
""" Draw a cross for excluded components in the `Fab` layer """ """ Draw a cross for excluded components in the `Fab` layer """
self.cross_no_body = False self.cross_no_body = False
""" Cross components even when they don't have a body. Only for KiCad 6 """ """ Cross components even when they don't have a body. Only for KiCad 6 """
self.csv_accept_no_ref = False
""" Accept aggregating CSV files without references (Experimental) """
self.date_format = '%Y-%m-%d' self.date_format = '%Y-%m-%d'
""" Format used for the day we started the script. """ Format used for the day we started the script.
Is also used for the PCB/SCH date formatting when `time_reformat` is enabled (default behavior). Is also used for the PCB/SCH date formatting when `time_reformat` is enabled (default behavior).

View File

@ -103,6 +103,7 @@ class GS(object):
global_copper_thickness = None global_copper_thickness = None
global_cross_footprints_for_dnp = None global_cross_footprints_for_dnp = None
global_cross_no_body = None global_cross_no_body = None
global_csv_accept_no_ref = None
global_date_format = None global_date_format = None
global_date_time_format = None global_date_time_format = None
global_drc_exclusions_workaround = None global_drc_exclusions_workaround = None

View File

@ -706,6 +706,22 @@ class BoMOptions(BaseOptions):
(self.columns_ce, self.column_levels_ce, self.column_comments_ce, self.column_rename_ce, (self.columns_ce, self.column_levels_ce, self.column_comments_ce, self.column_rename_ce,
self.join_ce) = self.process_columns_config(self.cost_extra_columns, valid_columns, extra_columns, add_all=False) self.join_ce) = self.process_columns_config(self.cost_extra_columns, valid_columns, extra_columns, add_all=False)
def get_ref_index(self, header, fname):
ref_n = ColumnList.COL_REFERENCE_L
ref_index = None
try:
ref_index = header.index(ref_n)
except ValueError:
try:
ref_index = header.index(ref_n[:-1])
except ValueError:
msg = 'Missing `{}` in aggregated file `{}`'.format(ref_n, fname)
if GS.global_csv_accept_no_ref:
logger.warning(msg)
else:
raise KiPlotConfigurationError(msg)
return ref_index
def load_csv(self, fname, project, delimiter): def load_csv(self, fname, project, delimiter):
""" Load components from a CSV file """ """ Load components from a CSV file """
comps = [] comps = []
@ -715,14 +731,7 @@ class BoMOptions(BaseOptions):
header = [x.lower() for x in next(reader)] header = [x.lower() for x in next(reader)]
logger.debugl(1, '- CSV header {}'.format(header)) logger.debugl(1, '- CSV header {}'.format(header))
# The header must contain at least the reference and the value # The header must contain at least the reference and the value
ref_n = ColumnList.COL_REFERENCE_L ref_index = self.get_ref_index(header, fname)
try:
ref_index = header.index(ref_n)
except ValueError:
try:
ref_index = header.index(ref_n[:-1])
except ValueError:
raise KiPlotConfigurationError('Missing `{}` in aggregated file `{}`'.format(ref_n, fname))
try: try:
val_index = header.index(ColumnList.COL_VALUE_L) val_index = header.index(ColumnList.COL_VALUE_L)
except ValueError: except ValueError:
@ -749,6 +758,8 @@ class BoMOptions(BaseOptions):
c.unit = 0 c.unit = 0
c.project = project c.project = project
c.lib = '' c.lib = ''
c.ref = c.f_ref = c.ref_prefix = ''
c.ref_suffix = '?'
c.sheet_path_h = '/'+project c.sheet_path_h = '/'+project
for n, f in enumerate(r): for n, f in enumerate(r):
number = None number = None