Commits

Adrian Sampson  committed 5c311e3

merge none_rec_action logic with quiet logic (#77)

This refactoring helps alleviate some of my own copypasta where we handle quiet
mode and its fallback. It has the added benefit of making none_rec_action work
for singletons as well as albums.

  • Participants
  • Parent commits 7cf9fd9

Comments (0)

Files changed (1)

File beets/ui/commands.py

 
     print_('(Similarity: %s)' % dist_string(match.distance))
 
-def _quiet_fall_back():
-    """Show the user that the default action is being taken because
-    we're in quiet mode and the recommendation is not strong.
+def _summary_judment(rec):
+    """Determines whether a decision should be made without even asking
+    the user. This occurs in quiet mode and when an action is chosen for
+    NONE recommendations. Return an action or None if the user should be
+    queried. May also print to the console if a summary judgment is
+    made.
     """
-    fallback = config['import']['quiet_fallback'].as_choice(['skip', 'asis'])
-    if fallback == 'skip':
+    if config['import']['quiet']:
+        if rec == autotag.RECOMMEND_STRONG:
+            return importer.action.APPLY
+        else:
+            action = config['import']['quiet_fallback'].as_choice({
+                'skip': importer.action.SKIP,
+                'asis': importer.action.ASIS,
+            })
+
+    elif rec == autotag.RECOMMEND_NONE:
+        action = config['import']['quiet_fallback'].as_choice({
+            'skip': importer.action.SKIP,
+            'asis': importer.action.ASIS,
+            'ask': None,
+        })
+
+    else:
+        return None
+
+    if action == importer.action.SKIP:
         print_('Skipping.')
-        return importer.action.SKIP
-    else:
+    elif action == importer.action.ASIS:
         print_('Importing as-is.')
-        return importer.action.ASIS
+    return action
 
 def choose_candidate(candidates, singleton, rec, cur_artist=None,
                      cur_album=None, item=None, itemcount=None):
         match = candidates[0]
         bypass_candidates = True
 
-    # Just make a decision when there's no recommendation?
-    elif config['import']['none_rec_action'].get() == 'skip':
-        print_('Skipping.')
-        return importer.action.SKIP
-    elif config['import']['none_rec_action'].get() == 'asis':
-        print_('Importing as-is.')
-        return importer.action.ASIS
-
     while True:
         # Display and choose from candidates.
         require = rec in (autotag.RECOMMEND_NONE, autotag.RECOMMEND_LOW)
         print_()
         print_(task.path)
 
-        if config['import']['quiet']:
-            # No input; just make a decision.
-            if task.rec == autotag.RECOMMEND_STRONG:
-                match = task.candidates[0]
-                show_change(task.cur_artist, task.cur_album, match)
-                return match
-            else:
-                return _quiet_fall_back()
+        # Take immediate action if appropriate.
+        action = _summary_judment(task.rec)
+        if action == importer.action.APPLY:
+            match = task.candidates[0]
+            show_change(task.cur_artist, task.cur_album, match)
+            return match
+        elif action is not None:
+            return action
 
         # Loop until we have a choice.
         candidates, rec = task.candidates, task.rec
         print_(task.item.path)
         candidates, rec = task.candidates, task.rec
 
-        if config['import']['quiet']:
-            # Quiet mode; make a decision.
-            if rec == autotag.RECOMMEND_STRONG:
-                match = candidates[0]
-                show_item_change(task.item, match)
-                return match
-            else:
-                return _quiet_fall_back()
+        # Take immediate action if appropriate.
+        action = _summary_judment(task.rec)
+        if action == importer.action.APPLY:
+            match = candidates[0]
+            show_item_change(task.item, match)
+            return match
+        elif action is not None:
+            return action
 
         while True:
             # Ask for a choice.