def handle_message(self, message): try: with self.__updater_lock: if message['type'] == 'ui_update': # UI updates arrived profile_start('Total') # handle content updates first, before events affect UI for update in message['content']: if update['type'] == 'update': # Property change profile_start('Handling updates') els = self.ui.root.nearest( lambda x: x.uid == update['uid'], exclude=lambda x: x.parent and not x.parent. visible, descend=False, ) if len(els) == 0: continue el = els[0] for k, v in update['properties'].iteritems(): setattr(el, k, v) profile_end('Handling updates') for update in message['content']: if update['type'] == 'event': # Element event emitted profile_start('Handling event') self.ui.dispatch_event(update['uid'], update['event'], update['params']) profile_end('Handling event') if self.ui.has_updates(): # If any updates happened due to event handlers, send these immediately self.ui.clear_updates() self.send_ui() else: # Otherwise just ACK self.send_ack() profile_end('Total') if ajenti.debug: self.send_debug() except SecurityError as e: self.send_security_error() except Exception as e: catcher.backup(e) traceback.print_exc() e.traceback = traceback.format_exc(e) self.send_crash(e)
def handle_message(self, message): try: with self.__updater_lock: if message['type'] == 'ui_update': # UI updates arrived profile_start('Total') # handle content updates first, before events affect UI for update in message['content']: if update['type'] == 'update': # Property change profile_start('Handling updates') els = self.ui.root.nearest( lambda x: x.uid == update['uid'], exclude=lambda x: x.parent and not x.parent.visible, descend=False, ) if len(els) == 0: continue el = els[0] for k, v in update['properties'].iteritems(): setattr(el, k, v) profile_end('Handling updates') for update in message['content']: if update['type'] == 'event': # Element event emitted profile_start('Handling event') self.ui.dispatch_event(update['uid'], update['event'], update['params']) profile_end('Handling event') if self.ui.has_updates(): # If any updates happened due to event handlers, send these immediately self.ui.clear_updates() self.send_ui() else: # Otherwise just ACK self.send_ack() profile_end('Total') if ajenti.debug: self.send_debug() except SecurityError as e: self.send_security_error() except Exception as e: catcher.backup(e) traceback.print_exc() e.traceback = traceback.format_exc(e) self.send_crash(e)
def init(self): self.categories = {} self.startup_crashes = [] profile_start('Starting plugins') self.is_empty = True for cls in SectionPlugin.get_classes(): try: if not hasattr(cls, 'permissionless'): permission_target = cls if hasattr(cls, 'uses_access_permission_of'): permission_target = cls.uses_access_permission_of UserManager.get().require_permission( self.context, 'section:%s' % permission_target.__name__) try: profile_start('Starting %s' % cls.__name__) cat = cls.new(self.ui) cat.clsname = cls.classname profile_end() self.append(cat) self.is_empty = False except SecurityError: pass except Exception as e: catcher.backup(e) traceback.print_exc() e.traceback = traceback.format_exc(e) self.startup_crashes.append(e) except SecurityError: pass profile_end() def category_order(x): order = 98 if x.category in self.category_order: order = self.category_order[x.category] return (order, x.order, x.title) self.children = sorted(self.children, key=category_order) if len(self.children) > 0: self.on_switch(self.children[0].uid)
def init(self): self.categories = {} self.startup_crashes = [] profile_start('Starting plugins') self.is_empty = True for cls in SectionPlugin.get_classes(): try: if not hasattr(cls, 'permissionless'): permission_target = cls if hasattr(cls, 'uses_access_permission_of'): permission_target = cls.uses_access_permission_of UserManager.get().require_permission(self.context, 'section:%s' % permission_target.__name__) try: profile_start('Starting %s' % cls.__name__) cat = cls.new(self.ui) cat.clsname = cls.classname profile_end() self.append(cat) self.is_empty = False except SecurityError: pass except Exception as e: catcher.backup(e) traceback.print_exc() e.traceback = traceback.format_exc(e) self.startup_crashes.append(e) except SecurityError: pass profile_end() def category_order(x): order = 98 if x.category in self.category_order: order = self.category_order[x.category] return (order, x.order, x.title) self.children = sorted(self.children, key=category_order) if len(self.children) > 0: self.on_switch(self.children[0].uid)
def init(self): self.categories = {} self.startup_crashes = [] profile_start('Starting plugins') for cls in SectionPlugin.get_classes(): try: UserManager.get().require_permission('section:%s' % cls.__name__) try: profile_start('Starting %s' % cls.__name__) cat = cls.new(self.ui) profile_end() self.append(cat) except SecurityError: pass except Exception, e: catcher.backup(e) traceback.print_exc() e.traceback = traceback.format_exc(e) self.startup_crashes.append(e) except SecurityError: pass profile_end() def category_order(x): order = 98 if x.category in self.category_order: order = self.category_order[x.category] return (order, x.order, x.title) self.children = sorted(self.children, key=category_order) if len(self.children) > 0: self.on_switch(self.children[0].uid)
def init(self): self.categories = {} self.startup_crashes = [] profile_start("Starting plugins") for cls in SectionPlugin.get_classes(): try: UserManager.get().require_permission("section:%s" % cls.__name__) try: profile_start("Starting %s" % cls.__name__) cat = cls.new(self.ui) profile_end() self.append(cat) except SecurityError: pass except Exception, e: catcher.backup(e) traceback.print_exc() e.traceback = traceback.format_exc(e) self.startup_crashes.append(e) except SecurityError: pass profile_end() def category_order(x): order = 98 if x.category in self.category_order: order = self.category_order[x.category] return (order, x.order, x.title) self.children = sorted(self.children, key=category_order) if len(self.children) > 0: self.on_switch(self.children[0].uid)
class MainSocket(SocketPlugin): name = '/stream' ui = None def on_connect(self): self.compression = 'zlib' self.__updater_lock = gevent.coros.RLock() # Inject into session self.request.session.endpoint = self # Inject the context methods self.context.notify = self.send_notify self.context.launch = self.launch self.context.endpoint = self if not 'ui' in self.request.session.data: # This is a newly created session ui = UI.new() self.request.session.data['ui'] = ui ui.root = MainPage.new(ui) ui.root.username = self.request.session.identity sections_root = SectionsRoot.new(ui) for e in sections_root.startup_crashes: self.send_crash(e) ui.root.append(sections_root) ui._sections = sections_root.children ui._sections_root = sections_root self.ui = self.request.session.data['ui'] self.send_init() self.send_ui() self.spawn(self.ui_watcher) def on_message(self, message): if not self.ui: return self.spawn(self.handle_message, message) def handle_message(self, message): try: with self.__updater_lock: if message['type'] == 'ui_update': # UI updates arrived profile_start('Total') # handle content updates first, before events affect UI for update in message['content']: if update['type'] == 'update': # Property change profile_start('Handling updates') els = self.ui.root.nearest( lambda x: x.uid == update['uid'], exclude=lambda x: x.parent and not x.parent. visible, descend=False, ) if len(els) == 0: continue el = els[0] for k, v in update['properties'].iteritems(): setattr(el, k, v) profile_end('Handling updates') for update in message['content']: if update['type'] == 'event': # Element event emitted profile_start('Handling event') self.ui.dispatch_event(update['uid'], update['event'], update['params']) profile_end('Handling event') if self.ui.has_updates(): # If any updates happened due to event handlers, send these immediately self.ui.clear_updates() self.send_ui() else: # Otherwise just ACK self.send_ack() profile_end('Total') if ajenti.debug: self.send_debug() except SecurityError, e: self.send_security_error() except Exception, e: catcher.backup(e) traceback.print_exc() e.traceback = traceback.format_exc(e) self.send_crash(e)
class MainSocket(SocketPlugin): name = '/stream' ui = None def on_connect(self): # Inject into session self.request.session.endpoint = self # Inject the context methods self.context.notify = self.send_notify self.context.launch = self.launch self.context.endpoint = self if not 'ui' in self.request.session.data: # This is a newly created session ui = UI.new() self.request.session.data['ui'] = ui ui.root = MainPage.new(ui) ui.root.username = self.request.session.identity sections_root = SectionsRoot.new(ui) for e in sections_root.startup_crashes: self.send_crash(e) ui.root.append(sections_root) ui._sections = sections_root.children ui._sections_root = sections_root self.ui = self.request.session.data['ui'] self.send_init() self.send_ui() self.spawn(self.ui_watcher) def on_message(self, message): if not self.ui: return self.spawn(self.handle_message, message) def handle_message(self, message): try: if message['type'] == 'ui_update': # UI updates arrived profile_start('Total') for update in message['content']: if update['type'] == 'update': # Property change profile_start('Handling updates') el = self.ui.find_uid(update['uid']) if el is None: continue for k, v in update['properties'].iteritems(): el.properties[k] = v el.properties_dirty[k] = False profile_end('Handling updates') if update['type'] == 'event': # Element event emitted profile_start('Handling event') self.ui.dispatch_event(update['uid'], update['event'], update['params']) profile_end('Handling event') if self.ui.has_updates(): # If any updates happened due to event handlers, send these immediately self.ui.clear_updates() self.send_ui() else: # Otherwise just ACK self.send_ack() profile_end('Total') if ajenti.debug: self.send_debug() except SecurityError, e: self.send_security_error() except Exception, e: catcher.backup(e) traceback.print_exc() e.traceback = traceback.format_exc(e) self.send_crash(e)