Ticket #2475: Pylint daemon.patch

File Pylint daemon.patch, 6.1 KB (added by Doadin, 10 years ago)
  • deluge/core/daemon.py

    <!-- saved from url=(0086)https://github.com/doadin/deluge/commit/21506dd5aefc1906ba8e4acad6554753874b2473.patch -->
    <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 21506dd5aefc1906ba8e4acad6554753874b2473 Mon Sep 17 00:00:00 2001
    From: Doadin &lt;tbkizle@gmail.com&gt;
    Date: Mon, 7 Jul 2014 06:50:50 -0400
    Subject: [PATCH] Pylint daemon
    
    ---
     deluge/core/daemon.py | 49 +++++++++++++++++++++++++++++++------------------
     1 file changed, 31 insertions(+), 18 deletions(-)
    
    diff --git a/deluge/core/daemon.py b/deluge/core/daemon.py
    index 93aba8b..f280d1b 100644
    a b  
    1717# 
    1818# You should have received a copy of the GNU General Public License 
    1919# along with deluge.    If not, write to: 
    20 #       The Free Software Foundation, Inc., 
    21 #       51 Franklin Street, Fifth Floor 
    22 #       Boston, MA  02110-1301, USA. 
     20#   The Free Software Foundation, Inc., 
     21#   51 Franklin Street, Fifth Floor 
     22#   Boston, MA  02110-1301, USA. 
    2323# 
    2424#    In addition, as a special exception, the copyright holders give 
    2525#    permission to link the code of portions of this program with the OpenSSL 
     
    3333# 
    3434import os 
    3535import logging 
    36 from twisted.internet import reactor 
     36from twisted.internet.interfaces import IReactorCore 
    3737 
    3838import deluge.component as component 
    3939from deluge.configmanager import get_config_dir 
     
    5050 
    5151 
    5252def check_running_daemon(pid_file): 
    53     """Check for another running instance of the daemon using the same pid file""" 
     53    """Check for another running instance """ 
    5454    if os.path.isfile(pid_file): 
    5555        # Get the PID and the port of the supposedly running daemon 
    5656        with open(pid_file) as _file: 
    def check_running_daemon(pid_file): 
    6161            pid, port = None, None 
    6262 
    6363        def process_running(pid): 
     64            """check for running process""" 
    6465            if windows_check(): 
    6566                from win32process import EnumProcesses 
    6667                return pid in EnumProcesses() 
    6768            else: 
    68                 # We can just use os.kill on UNIX to test if the process is running 
     69                # We can just use os.kill on UNIX to 
     70                # test if the process is running 
    6971                try: 
    7072                    os.kill(pid, 0) 
    7173                except OSError: 
    def process_running(pid): 
    7476                    return True 
    7577 
    7678        if pid is not None and process_running(pid): 
    77             # Ensure it's a deluged process by trying to open a socket to it's port. 
     79            # Ensure it's a deluged process by 
     80                        # trying to open a socket to it's port. 
    7881            import socket 
    7982            _socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    8083            try: 
    def process_running(pid): 
    8588            else: 
    8689                # This is a deluged! 
    8790                _socket.close() 
    88                 raise DaemonRunningError("Deluge daemon already running with this config directory!") 
     91                raise DaemonRunningError("Deluge daemon already running \ 
     92                                with this config directory!") 
    8993 
    9094 
    9195class Daemon(object): 
     96    """start daemon class""" 
    9297    def __init__(self, options=None, args=None, classic=False): 
    9398        log.info("Deluge daemon %s", get_version()) 
    9499        log.debug("options: %s", options) 
    def __init__(self, options=None, args=None, classic=False): 
    97102        pid_file = get_config_dir("deluged.pid") 
    98103        check_running_daemon(pid_file) 
    99104 
    100         # Twisted catches signals to terminate, so just have it call the shutdown method. 
    101         reactor.addSystemEventTrigger("before", "shutdown", self._shutdown) 
     105        # Twisted catches signals to terminate, 
     106                # so just have it call the shutdown method. 
     107        IReactorCore.addSystemEventTrigger("before", "shutdown", self._shutdown) 
    102108 
    103109        # Catch some Windows specific signals 
    104110        if windows_check(): 
    105111            def win_handler(ctrl_type): 
     112                """windows checks""" 
    106113                log.debug("windows handler ctrl_type: %s", ctrl_type) 
    107                 if ctrl_type == CTRL_CLOSE_EVENT or ctrl_type == CTRL_SHUTDOWN_EVENT: 
     114                if ctrl_type == CTRL_CLOSE_EVENT or \ 
     115                                ctrl_type == CTRL_SHUTDOWN_EVENT: 
    108116                    self._shutdown() 
    109117                    return 1 
    110118            SetConsoleCtrlHandler(win_handler) 
    111119 
    112120        listen_interface = None 
    113         if options and options.listen_interface and is_ip(options.listen_interface): 
     121        if options and options.listen_interface \ 
     122                and is_ip(options.listen_interface): 
    114123            listen_interface = options.listen_interface 
    115124 
    116125        # Start the core as a thread and join it until it's done 
    def win_handler(ctrl_type): 
    141150        if not classic: 
    142151            log.info("Deluge daemon starting...") 
    143152 
    144             # Create pid file to track if deluged is running, also includes the port number. 
     153            # Create pid file to track if deluged 
     154                        # is running, also includes the port number. 
    145155            pid = os.getpid() 
    146156            log.debug("Storing pid %s &amp; port %s in: %s", pid, port, pid_file) 
    147157            with open(pid_file, "wb") as _file: 
    def win_handler(ctrl_type): 
    150160            component.start() 
    151161 
    152162            try: 
    153                 reactor.run() 
     163                IReactorCore.run() 
    154164            finally: 
    155165                log.debug("Remove pid file: %s", pid_file) 
    156166                os.remove(pid_file) 
    157167                log.info("Deluge daemon shutdown successfully") 
    158168 
    159169    @export() 
    160     def shutdown(self, *args, **kwargs): 
     170    def shutdown(self): 
     171        """shutdown requested""" 
    161172        log.debug("Deluge daemon shutdown requested...") 
    162         reactor.callLater(0, reactor.stop) 
     173        IReactorCore.stop() 
    163174 
    164     def _shutdown(self, *args, **kwargs): 
    165         log.info("Deluge daemon shutting down, waiting for components to shutdown...") 
     175    def _shutdown(self): 
     176        """deluged shutdown process""" 
     177        log.info("Deluge daemon shutting down,\ 
     178                waiting for components to shutdown...") 
    166179        return component.shutdown() 
    167180 
    168181    @export()