A spot of refactoring

This commit is contained in:
Kovid Goyal 2017-05-01 19:46:29 +05:30
parent bafc949526
commit f9d964f358
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 6 deletions

View File

@ -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]

View File

@ -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)