Skip to content

Commit

Permalink
Fixed issue #11 (blank lines in CSV were skipped).
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Vandenbout committed May 24, 2017
1 parent 0fdd201 commit 4d92b24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Expand Up @@ -3,6 +3,12 @@
History
-------

0.1.27 (2017-05-24)
______________________

* Fixed issue #11 (blank lines in CSV file were skipped and multiple parts ran together).


0.1.26 (2017-05-21)
______________________

Expand Down
2 changes: 1 addition & 1 deletion kipart/__init__.py
Expand Up @@ -2,4 +2,4 @@

__author__ = 'XESS Corp.'
__email__ = 'info@xess.com'
__version__ = '0.1.26'
__version__ = '0.1.27'
18 changes: 13 additions & 5 deletions kipart/generic_reader.py
Expand Up @@ -70,20 +70,28 @@ def generic_reader(csv_file):
# Get the column header row for the part's pin data.
headers = clean_headers(get_nonblank_row(csv_reader))

# Now create a DictReader for grabbing the pin data in each row.
dict_reader = csv.DictReader(csv_file, headers, skipinitialspace=True)
for index, row in enumerate(dict_reader):
# Scan through the file line-by-line.
for index, row in enumerate(csv_file):

# A blank line signals the end of the pin data.
if num_row_elements(list(row.values())) == 0:
# (A csv.DictReader would completely skip a blank line.)
if len(row.strip()) == 0:
break

# Now use a DictReader to assign the fields in the row to the header labels.
dictreader = csv.DictReader([row], headers, skipinitialspace=True)
row_dict = next(dictreader)

# A line with no data also signals the end of the pin data.
if num_row_elements(list(row_dict.values())) == 0:
break

# Get the pin attributes from the cells of the row of data.
pin = copy.copy(DEFAULT_PIN) # Start off with default values for the pin.
pin.index = index
for c, a in list(COLUMN_NAMES.items()):
try:
setattr(pin, a, fix_pin_data(row[c], part_num))
setattr(pin, a, fix_pin_data(row_dict[c], part_num))
except KeyError:
# If a column doesn't exist, KeyError is raised and
# the default pin value will remain instead.
Expand Down

0 comments on commit 4d92b24

Please sign in to comment.