mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
A spot of refactoring
This commit is contained in:
parent
bafc949526
commit
f9d964f358
@ -9,3 +9,13 @@ import importlib
|
||||
|
||||
def module_for_cmd(cmd):
|
||||
return importlib.import_module('calibre.db.cli.cmd_' + cmd)
|
||||
|
||||
|
||||
def integers_from_string(arg, include_last_inrange=False):
|
||||
for x in arg.split(','):
|
||||
y = tuple(map(int, x.split('-')))
|
||||
if len(y) > 1:
|
||||
for y in range(y[0], y[1] + int(bool(include_last_inrange))):
|
||||
yield y
|
||||
else:
|
||||
yield y[0]
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
from calibre.db.cli import integers_from_string
|
||||
from calibre.db.delete_service import delete_service
|
||||
from calibre.srv.changes import books_deleted
|
||||
|
||||
@ -46,12 +47,7 @@ def main(opts, args, dbctx):
|
||||
|
||||
ids = set()
|
||||
for arg in args:
|
||||
for x in arg.split(','):
|
||||
y = tuple(map(int, x.split('-')))
|
||||
if len(y) > 1:
|
||||
ids |= set(range(y[0], y[1]))
|
||||
else:
|
||||
ids.add(y[0])
|
||||
ids |= set(integers_from_string(arg))
|
||||
|
||||
dbctx.run('remove', ids, opts.permanent)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user