From 78892b0b94926306d65605778bc0b83af0390c77 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Sun, 9 Nov 2008 12:02:50 -0800 Subject: [PATCH] Use else clauses in exception handlers The else clause in an exception handler helps to define what should happen during normal running, when an exception doesn't happen. Use them to make the code clearer. Signed-off-by: Ira W. Snyder --- PAR2Set/Base.py | 5 +++-- rarslave.py | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/PAR2Set/Base.py b/PAR2Set/Base.py index 599827e..5ef2665 100644 --- a/PAR2Set/Base.py +++ b/PAR2Set/Base.py @@ -185,10 +185,11 @@ class Base(object): # Delete the file try: os.remove(fullname) - print 'rm', fullname - logging.debug('Deleting: %s' % fullname) except OSError: logging.error('Failed to delete: %s' % fullname) + else: + print 'rm', fullname + logging.debug('Deleting: %s' % fullname) ############################################################################ diff --git a/rarslave.py b/rarslave.py index edd34ce..1a7e4bc 100755 --- a/rarslave.py +++ b/rarslave.py @@ -252,13 +252,14 @@ def findUniqueSets(directory, files): try: c = PAR2Set.CompareSet(directory, f) - - if c not in s: - s.append(c) except: # We just ignore any errors that happen, such as # parsing the PAR file pass + else: + # Ok, we got a valid set, add it to s + if c not in s: + s.append(c) return s @@ -283,21 +284,22 @@ def runEachType(cs, options): for t in types: try: instance = t(cs, options) - detected = True - logging.debug('%s detected for %s' % (t.__name__, cs.parityFile)) except TypeError: logging.debug('%s not detected for %s' % (t.__name__, cs.parityFile)) continue + else: + detected = True + logging.debug('%s detected for %s' % (t.__name__, cs.parityFile)) # We detected something, try to run it try: instance.run() - logging.info('Success: %s' % instance) - - # Leave early, we're done - return except (OSError, CalledProcessError): logging.critical('Failure: %s' % instance) + else: + # Leave early, we're done + logging.info('Success: %s' % instance) + return # Check that at least one detection worked if not detected: -- 2.25.1