mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-09 11:12:06 +00:00
[Component] Refactor to remove hasattr usage
Functions are defined in the class now https://github.com/deluge-torrent/deluge/pull/221#discussion_r228275050
This commit is contained in:
parent
e90f6c7eef
commit
0745c0eff8
@ -59,7 +59,7 @@ class Component:
|
|||||||
Deluge core.
|
Deluge core.
|
||||||
|
|
||||||
**update()** - This method is called every 1 second by default while the
|
**update()** - This method is called every 1 second by default while the
|
||||||
Componented is in a *Started* state. The interval can be
|
Component is in a *Started* state. The interval can be
|
||||||
specified during instantiation. The update() timer can be
|
specified during instantiation. The update() timer can be
|
||||||
paused by instructing the :class:`ComponentRegistry` to pause
|
paused by instructing the :class:`ComponentRegistry` to pause
|
||||||
this Component.
|
this Component.
|
||||||
@ -83,7 +83,7 @@ class Component:
|
|||||||
**Stopping** - The Component has had it's stop method called, but it hasn't
|
**Stopping** - The Component has had it's stop method called, but it hasn't
|
||||||
fully stopped yet.
|
fully stopped yet.
|
||||||
|
|
||||||
**Paused** - The Component has had it's update timer stopped, but will
|
**Paused** - The Component has had its update timer stopped, but will
|
||||||
still be considered in a Started state.
|
still be considered in a Started state.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -111,9 +111,8 @@ class Component:
|
|||||||
_ComponentRegistry.deregister(self)
|
_ComponentRegistry.deregister(self)
|
||||||
|
|
||||||
def _component_start_timer(self):
|
def _component_start_timer(self):
|
||||||
if hasattr(self, 'update'):
|
self._component_timer = LoopingCall(self.update)
|
||||||
self._component_timer = LoopingCall(self.update)
|
self._component_timer.start(self._component_interval)
|
||||||
self._component_timer.start(self._component_interval)
|
|
||||||
|
|
||||||
def _component_start(self):
|
def _component_start(self):
|
||||||
def on_start(result):
|
def on_start(result):
|
||||||
@ -129,13 +128,10 @@ class Component:
|
|||||||
return fail(result)
|
return fail(result)
|
||||||
|
|
||||||
if self._component_state == 'Stopped':
|
if self._component_state == 'Stopped':
|
||||||
if hasattr(self, 'start'):
|
self._component_state = 'Starting'
|
||||||
self._component_state = 'Starting'
|
d = deferLater(reactor, 0, self.start)
|
||||||
d = deferLater(reactor, 0, self.start)
|
d.addCallbacks(on_start, on_start_fail)
|
||||||
d.addCallbacks(on_start, on_start_fail)
|
self._component_starting_deferred = d
|
||||||
self._component_starting_deferred = d
|
|
||||||
else:
|
|
||||||
d = maybeDeferred(on_start, None)
|
|
||||||
elif self._component_state == 'Starting':
|
elif self._component_state == 'Starting':
|
||||||
return self._component_starting_deferred
|
return self._component_starting_deferred
|
||||||
elif self._component_state == 'Started':
|
elif self._component_state == 'Started':
|
||||||
@ -165,14 +161,11 @@ class Component:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
if self._component_state != 'Stopped' and self._component_state != 'Stopping':
|
if self._component_state != 'Stopped' and self._component_state != 'Stopping':
|
||||||
if hasattr(self, 'stop'):
|
self._component_state = 'Stopping'
|
||||||
self._component_state = 'Stopping'
|
d = maybeDeferred(self.stop)
|
||||||
d = maybeDeferred(self.stop)
|
d.addCallback(on_stop)
|
||||||
d.addCallback(on_stop)
|
d.addErrback(on_stop_fail)
|
||||||
d.addErrback(on_stop_fail)
|
self._component_stopping_deferred = d
|
||||||
self._component_stopping_deferred = d
|
|
||||||
else:
|
|
||||||
d = maybeDeferred(on_stop, None)
|
|
||||||
|
|
||||||
if self._component_state == 'Stopping':
|
if self._component_state == 'Stopping':
|
||||||
return self._component_stopping_deferred
|
return self._component_stopping_deferred
|
||||||
@ -222,9 +215,7 @@ class Component:
|
|||||||
|
|
||||||
def _component_shutdown(self):
|
def _component_shutdown(self):
|
||||||
def on_stop(result):
|
def on_stop(result):
|
||||||
if hasattr(self, 'shutdown'):
|
return maybeDeferred(self.shutdown)
|
||||||
return maybeDeferred(self.shutdown)
|
|
||||||
return succeed(None)
|
|
||||||
|
|
||||||
d = self._component_stop()
|
d = self._component_stop()
|
||||||
d.addCallback(on_stop)
|
d.addCallback(on_stop)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user