Skip to content

Commit 8e8cd28

Browse files
committed
Fix annoying default kwarg logic in to_file
Previously, the S2MarcBatch.to_file method used logic in the method signature, which is not good practice. I thought it was causing some odd results involving filenames reusing old timestamps, but the problem turned out to be something else. Still, I moved the logic into the method itself, where it should be, just to rule out that as a possible problem.
1 parent 28abedd commit 8e8cd28

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

django/sierra/export/sierra2marc.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'''
1+
"""
22
sierra2marc.py defines a class (S2MarcBatch) for parsing the Sierra
33
models out into MARC21 using Pymarc.
4-
'''
4+
"""
55
import re
66
import codecs
77
import sys
@@ -23,10 +23,10 @@ def __str__(self):
2323

2424

2525
class S2MarcBatch(object):
26-
'''
26+
"""
2727
Sierra to MARC21 Batch converter: instantiate this class to
2828
generate MARC21 records from a queryset of BibRecords.
29-
'''
29+
"""
3030

3131
cn_type_subfield_mapping = {
3232
'lc': 'c',
@@ -45,13 +45,13 @@ def __init__(self, records):
4545
self.success_count = 0
4646

4747
def _one_to_marc(self, r):
48-
'''
48+
"""
4949
Converts one record to a pymarc.record.Record object. Returns
5050
the object. Note that the III record number is stored in 907$a
5151
and the database ID is stored in 907$b. Other metadata fields
5252
are stored in 9XXs as needed, to ease conversion from MARC to
5353
Solr.
54-
'''
54+
"""
5555
marc_record = pymarc.record.Record(force_utf8=True)
5656
try:
5757
control_fields = r.record_metadata.controlfield_set.all()
@@ -150,10 +150,10 @@ def _one_to_marc(self, r):
150150
return marc_record
151151

152152
def to_marc(self):
153-
'''
153+
"""
154154
Converts all self.records to pymarc record objects and
155155
returns an array of them. Stores errors in self.errors.
156-
'''
156+
"""
157157
marc_records = []
158158
for r in self.records:
159159
try:
@@ -179,11 +179,12 @@ def _write_records(self, records, file_handle):
179179
success_count += 1
180180
return success_count
181181

182-
def to_file(self, marc_records, filename='{}.mrc'.format(timestamp()),
183-
filepath='{}'.format(settings.MEDIA_ROOT), append=True):
184-
'''
182+
def to_file(self, marc_records, filename=None, filepath=None, append=True):
183+
"""
185184
Writes MARC21 file to disk.
186-
'''
185+
"""
186+
filename = filename or '{}.mrc'.format(timestamp())
187+
filepath = filepath or '{}'.format(settings.MEDIA_ROOT)
187188
self.success_count = 0
188189
# If the file exists and append is True, we want to open the
189190
# file up, read in the MARC records, then append our

0 commit comments

Comments
 (0)