def _sub(self, *args): if self.request.method == "SUBSCRIBE": timeout = self.request.headers["Timeout"] timeout = timeout[len("Second-"):] try: timeout = int(timeout) except ValueError: timeout = 1800 self.response.headers["Date"] = formatdate(usegmt=True) self.response.headers["Server"] = SERVER_HELLO self.response.headers["Timeout"] = "Second-" + str(timeout) if "SID" in self.request.headers: # renewal sid = self.request.headers["SID"] self.response.headers["SID"] = sid self.fire(Event.create("upnp_subs_renewal", timeout), UPnPSubscription.sid2chan(sid)) return "" callbacks = [] for cb in self.request.headers["CALLBACK"].split("<")[1:]: callbacks.append(cb[:cb.rindex(">")]) subs = UPnPSubscription(callbacks, timeout, self.request.protocol).register(self) self.response.headers["SID"] = subs.sid return "" elif self.request.method == "UNSUBSCRIBE": sid = self.request.headers["SID"] self.fire(Event.create("upnp_subs_end"), UPnPSubscription.sid2chan(sid)) return ""
def SetNextAVTransportURI(self, **kwargs): self.fire(log(logging.DEBUG, 'Next AV Transport URI set to ' + kwargs["NextURI"]), "logger") self.fire(Event.create("prepare_next", kwargs["NextURI"], kwargs["NextURIMetaData"]), self.parent.provider.channel) return []
def SetVolume(self, **kwargs): self.fire(log(logging.DEBUG, 'SetVolume to ' + kwargs["DesiredVolume"]), "logger") self.fire(Event.create("set_volume", int(kwargs["DesiredVolume"]) / 100.0), self.parent.provider.channel) return []
def __init__(self, *args): ConfigurableComponent.__init__(self, "IRCBOT", *args) if self.config.get('password', None) is None: self.config.password = std_uuid() self.config.save() self.channel = 'ircbot' self.fireEvent(cli_register_event('test_irc_send', cli_test_irc_send), "isomer-web") self.log("Started") self.host = self.config.host self.port = self.config.port self.hostname = gethostname() self.nick = self.config.nick self.irc_channels = self.config.channels # Mapping of IRC Channel -> Set of Nicks self.channel_map = defaultdict(set) # Mapping of Nick -> Set of IRC Channels self.nick_map = defaultdict(set) # Add TCPClient and IRC to the system. self.transport = TCPClient(channel=self.channel).register(self) self.protocol = IRC(channel=self.channel).register(self) # Keep-Alive Timer Timer(60, Event.create("keepalive"), persist=True).register(self)
def flushChanges(self): if self._updates_locked or len(self._changes) == 0: return self._updates_locked = True self.fire(Notification({"LastChange": self.LastChange()}), self.notification_channel) self._changes.clear() Timer(0.2, Event.create("UnlockUpdates"), self).register(self)
def SetVolume(self, **kwargs): self.fire( Log(logging.DEBUG, 'SetVolume to ' + kwargs["DesiredVolume"]), "logger") self.fire( Event.create("SetVolume", int(kwargs["DesiredVolume"]) / 100.0), self.parent.provider.channel) return []
def SetNextAVTransportURI(self, **kwargs): self.fire( Log(logging.DEBUG, 'Next AV Transport URI set to ' + kwargs["NextURI"]), "logger") self.fire( Event.create("PrepareNext", kwargs["NextURI"], kwargs["NextURIMetaData"]), self.parent.provider.channel) return []
def SetAVTransportURI(self, **kwargs): self.fire( log(logging.DEBUG, 'AV Transport URI set to ' + kwargs["CurrentURI"]), "logger") self.fire( Event.create("load", kwargs["CurrentURI"], kwargs["CurrentURIMetaData"]), self.parent.provider.channel) return []
def _on_off_changed(self, value, session=None, **kwargs): if value and self._timer is None: evt = Event.create("time_over", session) evt.channels = (self.channel,) self._timer = Timer(1, evt, persist=True).register(self) locales = kwargs.get("locales", []) self.fire(portal_message \ (session, self.translation(locales) \ .ugettext("TimeUpdateOn")), self._portal_channel) if not value and self._timer is not None: self._timer.unregister() self._timer = None
def _on_off_changed(self, value, session=None, **kwargs): if value and self._timer is None: evt = Event.create("time_over", session) evt.channels = (self.channel, ) self._timer = Timer(1, evt, persist=True).register(self) locales = kwargs.get("locales", []) self.fire(portal_message \ (session, self.translation(locales) \ .ugettext("TimeUpdateOn")), self._portal_channel) if not value and self._timer is not None: self._timer.unregister() self._timer = None
def __init__(self, callbacks, timeout, protocol): self._uuid = str(uuid4()) super(UPnPSubscription, self).__init__(channel="subs:" + self._uuid) self._callbacks = callbacks self._used_callback = 0 self._client = Client(self._callbacks[self._used_callback], self.channel).register(self) self._protocol = protocol self._seq = 0 if timeout > 0: self._expiry_timer = Timer \ (timeout, Event.create("upnp_subs_end"), self).register(self)
def Seek(self, **kwargs): if not (self._transport_state == "PLAYING" or self._transport_state == "STOPPED"): raise UPnPServiceError(701) unit = kwargs["Unit"] if unit != "REL_TIME": self.fire(Log(logging.DEBUG, "Seek called"), "logger") raise UPnPServiceError(710) target = kwargs["Target"] self.fire(Log(logging.DEBUG, "Seek to " + target + " called"), "logger") target = target.split(":") target = int(target[0]) * 3600 + int(target[1]) * 60 + int(target[2]) self.fire(Event.create("Seek", target), self.parent.provider.channel) return []
def Seek(self, **kwargs): if not (self._transport_state == "PLAYING" or self._transport_state == "STOPPED"): raise UPnPServiceError(701) unit = kwargs["Unit"] if unit != "REL_TIME" and unit != "ABS_TIME": self.fire(log(logging.DEBUG, "Seek called"), "logger") raise UPnPServiceError(710) target = kwargs["Target"] self.fire(log(logging.DEBUG, "Seek to " + target + " called"), "logger") target = duration_to_secs(target) self.fire(Event.create("seek", target), self.parent.provider.channel) return []
def __init__(self, *args): super(MemoryLogger, self).__init__("MEM", *args) if self.context.params['debug'] is True: self.log('Debug flag set, decreasing memory logger measurement ' 'interval to 20 seconds') self.interval = 20 else: self.interval = self.config.interval self.size = 0 self.snapshot_diffs = deque(maxlen=self.config.snapshot_diffs) self.size_diffs = deque(maxlen=self.config.size_diffs) if hpy is not None: # noinspection PyCallingNonCallable self.heapy = hpy() else: self.log("Cannot use heapy. guppy package missing?", lvl=warn) if objgraph is None: self.log("Cannot use objgraph.", lvl=warn) try: self.fireEvent(cli_register_event("mem_growth", cli_mem_growth)) self.fireEvent(cli_register_event("mem_hogs", cli_mem_hogs)) self.fireEvent(cli_register_event("mem_heap", cli_mem_heap)) self.fireEvent(cli_register_event("mem_summary", cli_mem_summary)) self.fireEvent(cli_register_event("mem_diff", cli_mem_diff)) self.fireEvent(cli_register_event("mem_chart", cli_mem_chart)) except AttributeError: pass # We're running in a test environment and root is not yet running try: self.tracker = tracker.SummaryTracker() self.tracking_timer = Timer( self.interval, Event.create("memlog-timer"), persist=True ).register(self) except AttributeError: self.tracking_timer = None self.log("No pympler library for memory analysis installed.", lvl=warn) self.log("Started. Notification users: ", self.config.notificationusers)
def Stop(self, **kwargs): self.fire(Log(logging.DEBUG, "Stop called"), "logger") self.fire(Event.create("Stop"), self.parent.provider.channel) return []
def Pause(self, **kwargs): self.fire(Log(logging.DEBUG, "Pause called"), "logger") self.fire(Event.create("Pause"), self.parent.provider.channel) return []
def SetAVTransportURI(self, **kwargs): self.fire(Log(logging.DEBUG, "AV Transport URI set to " + kwargs["CurrentURI"]), "logger") self.fire( Event.create("Load", kwargs["CurrentURI"], kwargs["CurrentURIMetaData"]), self.parent.provider.channel ) return []
def Play(self, **kwargs): self.fire(log(logging.DEBUG, "Play called"), "logger") self.fire(Event.create("play"), self.parent.provider.channel) return []