From a5953fd68d0fb1cb28bb442024488bce1440b5dc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 19 May 2017 10:11:19 +0530 Subject: [PATCH] DRYer --- src/calibre/srv/standalone.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/calibre/srv/standalone.py b/src/calibre/srv/standalone.py index 3376bbd767..0bd2eb32de 100644 --- a/src/calibre/srv/standalone.py +++ b/src/calibre/srv/standalone.py @@ -280,8 +280,20 @@ libraries that the main calibre program knows about will be used. option_parser = create_option_parser +def ensure_single_instance(): + if b'CALIBRE_NO_SI_DANGER_DANGER' not in os.environ and not singleinstance('db'): + ext = '.exe' if iswindows else '' + raise SystemExit(_( + 'Another calibre program such as another instance of {} or the main' + ' calibre program is running. Having multiple programs that can make' + ' changes to a calibre library running at the same time is not supported.' + ).format('calibre-server' + ext) + ) + + def main(args=sys.argv): opts, args=create_option_parser().parse_args(args) + ensure_single_instance() if opts.manage_users: try: manage_users(opts.userdb) @@ -299,15 +311,6 @@ def main(args=sys.argv): raise SystemExit(_('You must specify at least one calibre library')) libraries=[prefs['library_path']] - if b'CALIBRE_NO_SI_DANGER_DANGER' not in os.environ and not singleinstance('db'): - ext = '.exe' if iswindows else '' - raise SystemExit(_( - 'Another calibre program such as another instance of {} or the main' - ' calibre program is running. Having multiple programs that can make' - ' changes to a calibre library running at the same time is not supported.' - ).format('calibre-server' + ext) - ) - if opts.auto_reload: if opts.daemonize: raise SystemExit('Cannot specify --auto-reload and --daemonize at the same time')