1# -*- coding: utf-8 -*- 2# 3# Copyright (C) 2008-2009 Ido Abramovich <ido.deluge@gmail.com> 4# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> 5# 6# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with 7# the additional special exception to link portions of this program with the OpenSSL library. 8# See LICENSE for more details. 9# 10 11from __future__ import unicode_literals 12 13import deluge.component as component 14from deluge.ui.client import client 15 16from . import BaseCommand 17 18 19class Command(BaseCommand): 20 """Shutdown the deluge server.""" 21 22 def handle(self, options): 23 self.console = component.get('ConsoleUI') 24 25 def on_shutdown(result): 26 self.console.write('{!success!}Daemon was shutdown') 27 28 def on_shutdown_fail(reason): 29 self.console.write('{!error!}Unable to shutdown daemon: %s' % reason) 30 31 return ( 32 client.daemon.shutdown() 33 .addCallback(on_shutdown) 34 .addErrback(on_shutdown_fail) 35 ) 36