<!-- 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 <tbkizle@gmail.com>
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
|
|
17 | 17 | # |
18 | 18 | # You should have received a copy of the GNU General Public License |
19 | 19 | # 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. |
23 | 23 | # |
24 | 24 | # In addition, as a special exception, the copyright holders give |
25 | 25 | # permission to link the code of portions of this program with the OpenSSL |
… |
… |
|
33 | 33 | # |
34 | 34 | import os |
35 | 35 | import logging |
36 | | from twisted.internet import reactor |
| 36 | from twisted.internet.interfaces import IReactorCore |
37 | 37 | |
38 | 38 | import deluge.component as component |
39 | 39 | from deluge.configmanager import get_config_dir |
… |
… |
|
50 | 50 | |
51 | 51 | |
52 | 52 | def 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 """ |
54 | 54 | if os.path.isfile(pid_file): |
55 | 55 | # Get the PID and the port of the supposedly running daemon |
56 | 56 | with open(pid_file) as _file: |
… |
… |
def check_running_daemon(pid_file):
|
61 | 61 | pid, port = None, None |
62 | 62 | |
63 | 63 | def process_running(pid): |
| 64 | """check for running process""" |
64 | 65 | if windows_check(): |
65 | 66 | from win32process import EnumProcesses |
66 | 67 | return pid in EnumProcesses() |
67 | 68 | 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 |
69 | 71 | try: |
70 | 72 | os.kill(pid, 0) |
71 | 73 | except OSError: |
… |
… |
def process_running(pid):
|
74 | 76 | return True |
75 | 77 | |
76 | 78 | 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. |
78 | 81 | import socket |
79 | 82 | _socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
80 | 83 | try: |
… |
… |
def process_running(pid):
|
85 | 88 | else: |
86 | 89 | # This is a deluged! |
87 | 90 | _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!") |
89 | 93 | |
90 | 94 | |
91 | 95 | class Daemon(object): |
| 96 | """start daemon class""" |
92 | 97 | def __init__(self, options=None, args=None, classic=False): |
93 | 98 | log.info("Deluge daemon %s", get_version()) |
94 | 99 | log.debug("options: %s", options) |
… |
… |
def __init__(self, options=None, args=None, classic=False):
|
97 | 102 | pid_file = get_config_dir("deluged.pid") |
98 | 103 | check_running_daemon(pid_file) |
99 | 104 | |
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) |
102 | 108 | |
103 | 109 | # Catch some Windows specific signals |
104 | 110 | if windows_check(): |
105 | 111 | def win_handler(ctrl_type): |
| 112 | """windows checks""" |
106 | 113 | 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: |
108 | 116 | self._shutdown() |
109 | 117 | return 1 |
110 | 118 | SetConsoleCtrlHandler(win_handler) |
111 | 119 | |
112 | 120 | 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): |
114 | 123 | listen_interface = options.listen_interface |
115 | 124 | |
116 | 125 | # Start the core as a thread and join it until it's done |
… |
… |
def win_handler(ctrl_type):
|
141 | 150 | if not classic: |
142 | 151 | log.info("Deluge daemon starting...") |
143 | 152 | |
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. |
145 | 155 | pid = os.getpid() |
146 | 156 | log.debug("Storing pid %s & port %s in: %s", pid, port, pid_file) |
147 | 157 | with open(pid_file, "wb") as _file: |
… |
… |
def win_handler(ctrl_type):
|
150 | 160 | component.start() |
151 | 161 | |
152 | 162 | try: |
153 | | reactor.run() |
| 163 | IReactorCore.run() |
154 | 164 | finally: |
155 | 165 | log.debug("Remove pid file: %s", pid_file) |
156 | 166 | os.remove(pid_file) |
157 | 167 | log.info("Deluge daemon shutdown successfully") |
158 | 168 | |
159 | 169 | @export() |
160 | | def shutdown(self, *args, **kwargs): |
| 170 | def shutdown(self): |
| 171 | """shutdown requested""" |
161 | 172 | log.debug("Deluge daemon shutdown requested...") |
162 | | reactor.callLater(0, reactor.stop) |
| 173 | IReactorCore.stop() |
163 | 174 | |
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...") |
166 | 179 | return component.shutdown() |
167 | 180 | |
168 | 181 | @export() |