home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- from logging import getLogger
- log = getLogger('updatemixin')
- info = log.info
- from Protocol import StateMixin
- from util import RepeatTimer
- from util.primitives.funcs import get, Delegate
-
- nothing = lambda *a, **k: pass
-
- class UpdateMixin(StateMixin):
- updatefreq = 300
- update_mixin_timer = True
-
- def __init__(self, updatefreq = None, *a, **k):
- StateMixin.__init__(self, *a, **k)
- if updatefreq is not None:
-
- try:
- updatefreq = int(updatefreq)
- except ValueError:
- pass
-
- if updatefreq < 1:
- updatefreq = 60
-
- self.updatefreq = max(updatefreq, 15)
-
- self.on_connect = Delegate()
- self.on_disable = Delegate()
-
-
- def disconnect(self):
- if self.update_mixin_timer:
- self.timer.stop()
-
-
-
- def update_now(self):
- raise NotImplementedError
-
-
- def get_options(self):
- options = (dict,)((lambda .0: for a in .0:
- (a, getattr(self, a)))(('enabled', 'updatefreq')))
- if self.alias is not None:
- options['alias'] = self.alias
-
- return options
-
-
- def get_enabled(self):
- return get(self, '_enabled', False)
-
-
- def set_enabled(self, value):
- has_been_set = hasattr(self, '_enabled')
- if not has_been_set:
- self.change_reason(self.Reasons.NONE)
- if self.update_mixin_timer:
- info('%s creating a timer with update frequency %s', self, self.updatefreq)
- self.timer = RepeatTimer(int(self.updatefreq), self.update_now)
- self.timer.start()
- self.timer.stop()
- if get(self, 'on_connect', None) is not None and self.update_now not in self.on_connect:
- self.on_connect += self.update_now
-
-
-
- self._enabled = value
- if value:
- info('enabling timer for %s', self)
- if self.OFFLINE and getattr(self, '_needs_connect', True):
- self._needs_connect = False
- get(self, 'Connect', nothing)()
-
- if self.update_mixin_timer:
- self.timer.reset(int(self.updatefreq))
-
- elif has_been_set:
- if not self.OFFLINE:
- get(self, 'Disconnect', nothing)()
-
- self._needs_connect = True
- if self.update_mixin_timer:
- info('stopping timer for %s', self)
- self.timer.stop()
-
- get(self, 'on_disable', nothing)()
-
-
- enabled = property(get_enabled, set_enabled)
-
- def pause_timer(self):
- self.timer._cv.__enter__()
-
- try:
- if not self.timer.paused:
- self.timer.pause()
- finally:
- pass
-
-
-
- def start_timer(self):
- self.timer._cv.__enter__()
-
- try:
- if self.timer.paused:
- self.timer.start()
- finally:
- pass
-
-
-
-