Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customization of maximum rip attempts value #455

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions whipper/command/cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


SILENT = 0
MAX_TRIES = 5
DEFAULT_MAX_RETRIES = 5

DEFAULT_TRACK_TEMPLATE = '%r/%A - %d/%t. %a - %n'
DEFAULT_DISC_TEMPLATE = '%r/%A - %d/%A - %d'
Expand Down Expand Up @@ -299,6 +299,13 @@ def add_arguments(self):
"complete option values respectively",
choices=['file', 'embed', 'complete'],
default=None)
self.parser.add_argument('r', '--max-retries',
action="store", dest="max_retries",
help="number of rip attempts before giving "
"up if can't rip a track. This defaults to "
"{}; 0 means "
"infinity.".format(DEFAULT_MAX_RETRIES),
default=DEFAULT_MAX_RETRIES)

def handle_arguments(self):
self.options.output_directory = os.path.expanduser(
Expand Down Expand Up @@ -329,6 +336,15 @@ def handle_arguments(self):
logger.critical(msg)
raise ValueError(msg)

try:
self.options.max_retries = int(self.options.max_retries)
except ValueError:
raise ValueError("max retries' value must be of integer type")
if self.options.max_retries == 0:
self.options.max_retries = float("inf")
elif self.options.max_retries < 0:
raise ValueError("number of max retries must be positive")

def doCommand(self):
self.program.setWorkingDirectory(self.options.working_directory)
self.program.outdir = self.options.output_directory
Expand Down Expand Up @@ -415,7 +431,7 @@ def _ripIfNotRipped(number):
trackResult.copyduration = 0.0
extra = ""
tries = 1
while tries <= MAX_TRIES:
while tries <= self.options.max_retries:
if tries > 1:
extra = " (try %d)" % tries
logger.info('ripping track %d of %d%s: %s',
Expand All @@ -441,13 +457,13 @@ def _ripIfNotRipped(number):
logger.debug('got exception %r on try %d', e, tries)
tries += 1

if tries > MAX_TRIES:
if tries > self.options.max_retries:
tries -= 1
logger.critical('giving up on track %d after %d times',
number, tries)
raise RuntimeError(
"track can't be ripped. "
"Rip attempts number is equal to 'MAX_TRIES'")
raise RuntimeError("track can't be ripped. "
"Rip attempts number is equal to %d",
self.options.max_retries)
if trackResult.testcrc == trackResult.copycrc:
logger.info('CRCs match for track %d', number)
else:
Expand Down