Skip to content

Commit

Permalink
Refactor to make set of formats allowed for auto-adding easily re-use…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
kovidgoyal committed Jan 9, 2016
1 parent e8266be commit 517f259
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/calibre/gui2/auto_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def __init__(self):
def __contains__(self, x):
return x not in self.disallowed


def allowed_formats():
' Return an object that can be used to test if a format (lowercase) is allowed for auto-adding '
if gprefs['auto_add_everything']:
allowed = AllAllowed()
else:
allowed = AUTO_ADDED - frozenset(gprefs['blocked_auto_formats'])
return allowed

class Worker(Thread):

def __init__(self, path, callback):
Expand All @@ -37,10 +46,7 @@ def __init__(self, path, callback):
self.wake_up = Event()
self.path, self.callback = path, callback
self.staging = set()
if gprefs['auto_add_everything']:
self.allowed = AllAllowed()
else:
self.allowed = AUTO_ADDED - frozenset(gprefs['blocked_auto_formats'])
self.allowed = allowed_formats()

def run(self):
self.tdir = PersistentTemporaryDirectory('_auto_adder')
Expand Down

0 comments on commit 517f259

Please sign in to comment.