Skip to content

Commit

Permalink
Convert remaining text.py entries from % to .format()
Browse files Browse the repository at this point in the history
  • Loading branch information
tuffy committed Nov 21, 2015
1 parent fb97199 commit 0a0bc9e
Show file tree
Hide file tree
Showing 36 changed files with 871 additions and 960 deletions.
66 changes: 33 additions & 33 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -7519,65 +7519,65 @@
than from elsewhere.

See: [[https://docs.python.org/3/library/string.html#formatstrings][Format String Syntax]] for more info.
*** TODO Update audiotools.text entries
*** DONE Update audiotools.text entries
*** DONE Update setup.py
*** TODO Update utilities
- [ ] audiotools-config
- [ ] cdda2track
- [ ] cddainfo
- [X] audiotools-config
- [X] cdda2track
- [X] cddainfo
- [X] cddaplay
- [ ] coverdump
- [ ] covertag
- [ ] coverview
- [ ] dvda2track
- [X] covertag
- [X] coverview
- [X] dvda2track
- [X] dvdainfo
- [ ] track2cdda
- [ ] track2track
- [ ] trackcat
- [ ] trackcmp
- [ ] trackinfo
- [ ] tracklength
- [ ] tracklint
- [ ] trackplay
- [ ] trackrename
- [ ] tracksplit
- [ ] tracktag
- [ ] trackverify
- [X] track2cdda
- [X] track2track
- [X] trackcat
- [X] trackcmp
- [X] trackinfo
- [X] tracklength
- [X] tracklint
- [X] trackplay
- [X] trackrename
- [X] tracksplit
- [X] tracktag
- [X] trackverify
*** TODO Update modules
- [ ] __init__.py
- [X] accuraterip.py
- [X] aiff.py
- [ ] ape.py
- [ ] au.py
- [X] ape.py
- [X] au.py
- [X] cdtoc.py
- [X] coverartarchive.py
- [ ] flac.py
- [X] flac.py
- [X] freedb.py
- [ ] id3.py
- [ ] id3v1.py
- [X] id3.py
- [X] id3v1.py
- [X] image.py
- [X] m4a.py
- [ ] m4a_atoms.py
- [X] m4a_atoms.py
- [X] mp3.py
- [X] mpc.py
- [X] musicbrainz.py
- [X] ogg.py
- [X] opus.py
- [X] player.py
- [X] tta.py
- [ ] ui.py
- [X] ui.py
- [X] vorbis.py
- [ ] vorbiscomment.py
- [X] vorbiscomment.py
- [X] wav.py
- [X] wavpack.py
**** TODO cue
**** DONE cue
- [X] __init__.py
- [X] tokrules.py
- [X] yaccrules.py
**** DONE toc
- [X] __init__.py
- [X] tokrules.py
- [ ] yaccrules.py
**** TODO toc
- [ ] __init__.py
- [ ] tokrules.py
- [ ] yaccrules.py
- [X] yaccrules.py
*** TODO Update unit tests
- [X] test.py
- [X] test_core.py
Expand Down
23 changes: 13 additions & 10 deletions audiotools-config
Original file line number Diff line number Diff line change
Expand Up @@ -1193,11 +1193,12 @@ if (__name__ == '__main__'):
configfile = open(configpath, 'w')
audiotools.config.write(configfile)
configfile.close()
msg.info(_.LAB_AT_CONFIG_FILE_WRITTEN %
(audiotools.Filename(configpath),))
msg.info(_.LAB_AT_CONFIG_FILE_WRITTEN.format(
audiotools.Filename(configpath)))
except IOError as err:
msg.error(_.ERR_OPEN_IOERROR %
(audiotools.Filename(configpath),))
msg.error(
_.ERR_OPEN_IOERROR.format(
audiotools.Filename(configpath)))
sys.exit(1)
else:
sys.exit(0)
Expand Down Expand Up @@ -1233,9 +1234,9 @@ if (__name__ == '__main__'):
sys.exit(0)
elif ((options.quality is not None) and
(options.quality not in AudioType.COMPRESSION_MODES)):
msg.error(_.ERR_UNSUPPORTED_COMPRESSION_MODE %
{"quality": options.quality,
"type": AudioType.NAME})
msg.error(
_.ERR_UNSUPPORTED_COMPRESSION_MODE.format(
quality=options.quality, type=AudioType.NAME))
sys.exit(1)

# verify --joint is positive, if present
Expand All @@ -1252,8 +1253,10 @@ if (__name__ == '__main__'):
configfile = open(configpath, 'w')
audiotools.config.write(configfile)
configfile.close()
msg.info(_.LAB_AT_CONFIG_FILE_WRITTEN %
(audiotools.Filename(configpath),))
msg.info(_.LAB_AT_CONFIG_FILE_WRITTEN.format(
audiotools.Filename(configpath)))
except IOError as err:
msg.error(_.ERR_OPEN_IOERROR % (audiotools.Filename(configpath),))
msg.error(
_.ERR_OPEN_IOERROR.format(
audiotools.Filename(configpath)))
sys.exit(1)
41 changes: 21 additions & 20 deletions audiotools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,9 +1551,9 @@ def __init__(self, filename, mask):

EncodingError.__init__(
self,
ERR_UNSUPPORTED_CHANNEL_MASK %
{"target_filename": Filename(filename),
"assignment": ChannelMask(mask)})
ERR_UNSUPPORTED_CHANNEL_MASK.format(
target_filename=Filename(filename),
assignment=ChannelMask(mask)))
self.filename = filename
self.mask = mask

Expand All @@ -1569,9 +1569,9 @@ def __init__(self, filename, count):

EncodingError.__init__(
self,
ERR_UNSUPPORTED_CHANNEL_COUNT %
{"target_filename": Filename(filename),
"channels": count})
ERR_UNSUPPORTED_CHANNEL_COUNT.format(
target_filename=Filename(filename),
channels=count))
self.filename = filename
self.count = count

Expand All @@ -1587,9 +1587,9 @@ def __init__(self, filename, bits_per_sample):

EncodingError.__init__(
self,
ERR_UNSUPPORTED_BITS_PER_SAMPLE %
{"target_filename": Filename(filename),
"bps": bits_per_sample})
ERR_UNSUPPORTED_BITS_PER_SAMPLE.format(
target_filename=Filename(filename),
bps=bits_per_sample))
self.filename = filename
self.bits_per_sample = bits_per_sample

Expand Down Expand Up @@ -1792,7 +1792,7 @@ def __init__(self, filename):
"""filename is a Filename object"""

from audiotools.text import ERR_DUPLICATE_FILE
Exception.__init__(self, ERR_DUPLICATE_FILE % (filename,))
Exception.__init__(self, ERR_DUPLICATE_FILE.format(filename))
self.filename = filename


Expand All @@ -1803,7 +1803,7 @@ def __init__(self, filename):
"""filename is a Filename object"""

from audiotools.text import ERR_DUPLICATE_OUTPUT_FILE
Exception.__init__(self, ERR_DUPLICATE_OUTPUT_FILE % (filename,))
Exception.__init__(self, ERR_DUPLICATE_OUTPUT_FILE.format(filename))
self.filename = filename


Expand All @@ -1814,7 +1814,7 @@ def __init__(self, filename):
"""filename is a Filename object"""

from audiotools.text import ERR_OUTPUT_IS_INPUT
Exception.__init__(self, ERR_OUTPUT_IS_INPUT % (filename,))
Exception.__init__(self, ERR_OUTPUT_IS_INPUT.format(filename))
self.filename = filename


Expand Down Expand Up @@ -1964,7 +1964,7 @@ def open_files(filename_list, sorted=True, messenger=None,
if no_duplicates:
raise DuplicateFile(filename)
elif warn_duplicates and (messenger is not None):
messenger.warning(ERR_DUPLICATE_FILE % (filename,))
messenger.warning(ERR_DUPLICATE_FILE.format(filename))

try:
with __open__(str(filename), "rb") as f:
Expand All @@ -1977,7 +1977,7 @@ def open_files(filename_list, sorted=True, messenger=None,
pass
except IOError as err:
if messenger is not None:
messenger.warning(ERR_OPEN_IOERROR % (filename,))
messenger.warning(ERR_OPEN_IOERROR.format(filename))
except InvalidFile as err:
if messenger is not None:
messenger.error(str(err))
Expand Down Expand Up @@ -2039,7 +2039,7 @@ def __init__(self, suffix):
def error_msg(self, messenger):
from audiotools.text import ERR_UNSUPPORTED_AUDIO_TYPE

messenger.error(ERR_UNSUPPORTED_AUDIO_TYPE % (self.suffix,))
messenger.error(ERR_UNSUPPORTED_AUDIO_TYPE.format(self.suffix))


class AmbiguousAudioType(UnknownAudioType):
Expand All @@ -2053,10 +2053,11 @@ def error_msg(self, messenger):
from audiotools.text import (ERR_AMBIGUOUS_AUDIO_TYPE,
LAB_T_OPTIONS)

messenger.error(ERR_AMBIGUOUS_AUDIO_TYPE % (self.suffix,))
messenger.info(LAB_T_OPTIONS %
(u" or ".join([u"\"{}\"".format(t.NAME.decode('ascii'))
for t in self.type_list])))
messenger.error(ERR_AMBIGUOUS_AUDIO_TYPE.format(self.suffix))
messenger.info(
LAB_T_OPTIONS.format(
(u" or ".join([u"\"{}\"".format(t.NAME.decode('ascii'))
for t in self.type_list]))))


def filename_to_type(path):
Expand Down Expand Up @@ -3809,7 +3810,7 @@ def error_msg(self, messenger):
from audiotools.text import (ERR_UNKNOWN_FIELD,
LAB_SUPPORTED_FIELDS)

messenger.error(ERR_UNKNOWN_FIELD % (self.field,))
messenger.error(ERR_UNKNOWN_FIELD.format(self.field))
messenger.info(LAB_SUPPORTED_FIELDS)
for field in sorted(MetaData.FIELDS +
("album_track_number", "suffix")):
Expand Down
18 changes: 8 additions & 10 deletions audiotools/ape.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,7 @@ def clean(self):
for tag in self.tags:
if tag.key.upper() in used_tags:
fixes_performed.append(
CLEAN_REMOVE_DUPLICATE_TAG %
{"field": tag.key.decode('ascii')})
CLEAN_REMOVE_DUPLICATE_TAG.format(tag.key.decode('ascii')))
elif tag.type == 0:
used_tags.add(tag.key.upper())
text = tag.__unicode__()
Expand All @@ -666,15 +665,15 @@ def clean(self):
fix1 = text.rstrip()
if fix1 != text:
fixes_performed.append(
CLEAN_REMOVE_TRAILING_WHITESPACE %
{"field": tag.key.decode('ascii')})
CLEAN_REMOVE_TRAILING_WHITESPACE.format(
tag.key.decode('ascii')))

# check leading whitespace
fix2 = fix1.lstrip()
if fix2 != fix1:
fixes_performed.append(
CLEAN_REMOVE_LEADING_WHITESPACE %
{"field": tag.key.decode('ascii')})
CLEAN_REMOVE_LEADING_WHITESPACE.format(
tag.key.decode('ascii')))

if tag.key in self.INTEGER_ITEMS:
if u"/" in fix2:
Expand Down Expand Up @@ -713,17 +712,16 @@ def clean(self):

if fix3 != fix2:
fixes_performed.append(
CLEAN_FIX_TAG_FORMATTING %
{"field": tag.key.decode('ascii')})
CLEAN_FIX_TAG_FORMATTING.format(
tag.key.decode('ascii')))
else:
fix3 = fix2

if len(fix3) > 0:
tag_items.append(ApeTagItem.string(tag.key, fix3))
else:
fixes_performed.append(
CLEAN_REMOVE_EMPTY_TAG %
{"field": tag.key.decode('ascii')})
CLEAN_REMOVE_EMPTY_TAG.format(tag.key.decode('ascii')))
else:
used_tags.add(tag.key.upper())
tag_items.append(tag)
Expand Down
6 changes: 1 addition & 5 deletions audiotools/au.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,8 @@ def from_pcm(cls, filename, pcmreader,
if pcmreader.bits_per_sample not in (8, 16, 24):
from audiotools import Filename
from audiotools import UnsupportedBitsPerSample
from audiotools.text import ERR_UNSUPPORTED_BITS_PER_SAMPLE
pcmreader.close()
raise UnsupportedBitsPerSample(
ERR_UNSUPPORTED_BITS_PER_SAMPLE %
{"target_filename": Filename(filename),
"bps": pcmreader.bits_per_sample})
raise UnsupportedBitsPerSample(filename, pcmreader.bits_per_sample)

try:
header = au_header(pcmreader.sample_rate,
Expand Down
2 changes: 1 addition & 1 deletion audiotools/cue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def __init__(self, number, timestamp):
self.__timestamp__ = timestamp

def __repr__(self):
return "Index(number=%s, timestamp=%s)".format(
return "Index(number={!r},timestamp={!r})".format(
self.__number__, self.__timestamp__)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion audiotools/cue/yaccrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,4 @@ def p_flag(t):
def p_error(t):
from audiotools.text import ERR_CUE_SYNTAX_ERROR

raise ValueError(ERR_CUE_SYNTAX_ERROR % (t.lexer.lineno))
raise ValueError(ERR_CUE_SYNTAX_ERROR.format(t.lexer.lineno))
8 changes: 4 additions & 4 deletions audiotools/flac.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def parse(cls, reader):
Flac_PICTURE.parse(reader))
elif (block_type >= 7) and (block_type <= 126):
from audiotools.text import ERR_FLAC_RESERVED_BLOCK
raise ValueError(ERR_FLAC_RESERVED_BLOCK % (block_type))
raise ValueError(ERR_FLAC_RESERVED_BLOCK.format(block_type))
else:
from audiotools.text import ERR_FLAC_INVALID_BLOCK
raise ValueError(ERR_FLAC_INVALID_BLOCK)
Expand Down Expand Up @@ -2208,8 +2208,8 @@ def from_wave(cls, filename, header, pcmreader, footer, compression=None):
# transfer only "data" chunk header to APPLICATION block
if header_len != 0:
from audiotools.text import ERR_WAV_HEADER_EXTRA_DATA
raise EncodingError(ERR_WAV_HEADER_EXTRA_DATA %
(header_len))
raise EncodingError(
ERR_WAV_HEADER_EXTRA_DATA.format(header_len))
elif not fmt_found:
from audiotools.text import ERR_WAV_NO_FMT_CHUNK
raise EncodingError(ERR_WAV_NO_FMT_CHUNK)
Expand Down Expand Up @@ -2979,7 +2979,7 @@ def parse(cls, packetreader):
block_list.append(Flac_PICTURE.parse(packet))
elif (block_type >= 7) and (block_type <= 126):
from audiotools.text import ERR_FLAC_RESERVED_BLOCK
raise ValueError(ERR_FLAC_RESERVED_BLOCK % (block_type))
raise ValueError(ERR_FLAC_RESERVED_BLOCK.format(block_type))
elif block_type == 127:
from audiotools.text import ERR_FLAC_INVALID_BLOCK
raise ValueError(ERR_FLAC_INVALID_BLOCK)
Expand Down
Loading

0 comments on commit 0a0bc9e

Please sign in to comment.