Mercurial > libervia-backend
diff sat/core/sat_main.py @ 2643:189e38fb11ff
core: style improvments (90 chars limit)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 Jul 2018 18:44:27 +0200 |
parents | 56f94936df1e |
children | f2cf1daa42cb |
line wrap: on
line diff
--- a/sat/core/sat_main.py Sun Jul 08 18:38:32 2018 +0200 +++ b/sat/core/sat_main.py Sun Jul 29 18:44:27 2018 +0200 @@ -55,7 +55,8 @@ self._menus = ( OrderedDict() ) # dynamic menus. key: callback_id, value: menu data (dictionnary) - self._menus_paths = {} # path to id. key: (menu_type, lower case tuple of path), value: menu id + self._menus_paths = {} # path to id. key: (menu_type, lower case tuple of path), + # value: menu id self.initialised = defer.Deferred() self.profiles = {} self.plugins = {} @@ -153,7 +154,10 @@ @property def full_version(self): - """Return the full version of SàT (with release name and extra data when in development mode)""" + """Return the full version of SàT + + In developement mode, release name and extra data are returned too + """ version = self.version if version[-1] == "D": # we are in debug version, we add extra data @@ -201,8 +205,9 @@ # FIXME: module imported but cancelled should be deleted # TODO: make this more generic and reusable in tools.common # FIXME: should use imp - # TODO: do not import all plugins if no needed: component plugins are not needed if we - # just use a client, and plugin blacklisting should be possible in sat.conf + # TODO: do not import all plugins if no needed: component plugins are not needed + # if we just use a client, and plugin blacklisting should be possible in + # sat.conf plugins_path = os.path.dirname(sat.plugins.__file__) plugin_glob = "plugin*." + C.PLUGIN_EXT plug_lst = [ @@ -219,7 +224,8 @@ except exceptions.MissingModule as e: self._unimport_plugin(plugin_path) log.warning( - u"Can't import plugin [{path}] because of an unavailale third party module:\n{msg}".format( + u"Can't import plugin [{path}] because of an unavailale third party " + u"module:\n{msg}".format( path=plugin_path, msg=e ) ) @@ -265,7 +271,8 @@ if import_name in plugins_to_import: log.error( _( - u"Name conflict for import name [{import_name}], can't import plugin [{name}]" + u"Name conflict for import name [{import_name}], can't import " + u"plugin [{name}]" ).format(**plugin_info) ) continue @@ -283,9 +290,12 @@ ): """Recursively import and their dependencies in the right order - @param plugins_to_import(dict): key=import_name and values=(plugin_path, module, plugin_info) - @param import_name(unicode, None): name of the plugin to import as found in PLUGIN_INFO['import_name'] - @param optional(bool): if False and plugin is not found, an ImportError exception is raised + @param plugins_to_import(dict): key=import_name and values=(plugin_path, module, + plugin_info) + @param import_name(unicode, None): name of the plugin to import as found in + PLUGIN_INFO['import_name'] + @param optional(bool): if False and plugin is not found, an ImportError exception + is raised """ if import_name in self.plugins: log.debug(u"Plugin {} already imported, passing".format(import_name)) @@ -417,7 +427,8 @@ Return list of activated plugins and plugin specific data @param profile_key: %(doc_profile_key)s - C.PROF_KEY_NONE can be used to have general plugins data (i.e. not profile dependent) + C.PROF_KEY_NONE can be used to have general plugins data (i.e. not profile + dependent) @return (dict)[Deferred]: features data where: - key is plugin import name, present only for activated plugins - value is a an other dict, when meaning is specific to each plugin. @@ -534,8 +545,9 @@ raise exceptions.NotFound(profile_key) def getClients(self, profile_key): - """Convenient method to get list of clients from profile key (manage list through profile_key like C.PROF_KEY_ALL) + """Convenient method to get list of clients from profile key + Manage list through profile_key like C.PROF_KEY_ALL @param profile_key: %(doc_profile_key)s @return: list of clients """ @@ -599,8 +611,8 @@ @param *extra_path: extra path element(s) to use @return (unicode): path """ - # FIXME: component and profile are parsed with **kwargs because of python 2 limitations - # once moved to python 3, this can be fixed + # FIXME: component and profile are parsed with **kwargs because of python 2 + # limitations. Once moved to python 3, this can be fixed component = kwargs.pop("component", False) profile = kwargs.pop("profile", True) assert not kwargs @@ -639,18 +651,12 @@ ## XMPP methods ## - def _messageSend( - self, - to_jid_s, - message, - subject=None, - mess_type="auto", - extra=None, - profile_key=C.PROF_KEY_NONE, - ): + def _messageSend(self, to_jid_s, message, subject=None, mess_type="auto", extra=None, + profile_key=C.PROF_KEY_NONE,): client = self.getClient(profile_key) to_jid = jid.JID(to_jid_s) - # XXX: we need to use the dictionary comprehension because D-Bus return its own types, and pickle can't manage them. TODO: Need to find a better way + # XXX: we need to use the dictionary comprehension because D-Bus return its own + # types, and pickle can't manage them. TODO: Need to find a better way return client.sendMessage( to_jid, message, @@ -674,7 +680,8 @@ self.memory.getParamA("Priority", "Connection", profile_key=profile) ) self.profiles[profile].presence.available(to_jid, show, statuses, priority) - # XXX: FIXME: temporary fix to work around openfire 3.7.0 bug (presence is not broadcasted to generating resource) + # XXX: FIXME: temporary fix to work around openfire 3.7.0 bug (presence is not + # broadcasted to generating resource) if "" in statuses: statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop("") self.bridge.presenceUpdate( @@ -709,7 +716,8 @@ """Add a contact in roster list""" profile = self.memory.getProfileName(profile_key) assert profile - # presence is sufficient, as a roster push will be sent according to RFC 6121 §3.1.2 + # presence is sufficient, as a roster push will be sent according to + # RFC 6121 §3.1.2 self.profiles[profile].presence.subscribe(to_jid) def _updateContact(self, to_jid_s, name, groups, profile_key): @@ -801,16 +809,18 @@ """retrieve all services or contacts managing a set a features @param namespaces(list[unicode]): features which must be handled - @param identities(list[tuple[unicode,unicode]], None): if not None or empty, only keep those identities - tuple must by (category, type) + @param identities(list[tuple[unicode,unicode]], None): if not None or empty, + only keep those identities tuple must by (category, type) @param bare_jids(bool): retrieve only bare_jids if True if False, retrieve full jid of connected devices @param service(bool): if True return service from our roster @param roster(bool): if True, return entities in roster full jid of all matching resources available will be returned @param own_jid(bool): if True, return profile's jid resources - @param local_device(bool): if True, return profile's jid local resource (i.e. client.jid) - @return (tuple(dict[jid.JID(), tuple[unicode, unicode, unicode]]*3)): found entities in a tuple with: + @param local_device(bool): if True, return profile's jid local resource + (i.e. client.jid) + @return (tuple(dict[jid.JID(), tuple[unicode, unicode, unicode]]*3)): found + entities in a tuple with: - service entities - own entities - roster entities @@ -896,9 +906,9 @@ @param action_data(dict): action data (see bridge documentation) @param security_limit: %(doc_security_limit)s - @param keep_id(None, unicode): if not None, used to keep action for differed retrieval - must be set to the callback_id - action will be deleted after 30 min. + @param keep_id(None, unicode): if not None, used to keep action for differed + retrieval. Must be set to the callback_id. + Action will be deleted after 30 min. @param profile: %(doc_profile)s """ id_ = unicode(uuid.uuid4()) @@ -948,7 +958,8 @@ @return (dict): data with the following keys: 'position' (int): current possition 'size' (int): end_position - if id doesn't exists (may be a finished progression), and empty dict is returned + if id doesn't exists (may be a finished progression), and empty dict is + returned """ client = self.getClient(profile) try: @@ -969,7 +980,8 @@ """Return all progress metadata at once @param profile_key: %(doc_profile)s - if C.PROF_KEY_ALL is used, all progress metadata from all profiles are returned + if C.PROF_KEY_ALL is used, all progress metadata from all profiles are + returned @return (dict[dict[dict]]): a dict which map profile to progress_dict progress_dict map progress_id to progress_data progress_metadata is the same dict as sent by [progressStarted] @@ -1012,7 +1024,8 @@ @param callback(callable): method to call @param kwargs: can contain: with_data(bool): True if the callback use the optional data dict - force_id(unicode): id to avoid generated id. Can lead to name conflict, avoid if possible + force_id(unicode): id to avoid generated id. Can lead to name conflict, avoid + if possible one_shot(bool): True to delete callback once it have been called @return: id of the registered callback """ @@ -1050,7 +1063,8 @@ @profile_key: %(doc_profile_key)s @return: a deferred which fire a dict where key can be: - xmlui: a XMLUI need to be displayed - - validated: if present, can be used to launch a callback, it can have the values + - validated: if present, can be used to launch a callback, it can have the + values - C.BOOL_TRUE - C.BOOL_FALSE """ @@ -1117,25 +1131,33 @@ ): """register a new menu for frontends - @param path(iterable[unicode]): path to go to the menu (category/subcategory/.../item) (e.g.: ("File", "Open")) + @param path(iterable[unicode]): path to go to the menu + (category/subcategory/.../item) (e.g.: ("File", "Open")) /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open"))) - untranslated/lower case path can be used to identity a menu, for this reason it must be unique independently of case. - @param callback(callable): method to be called when menuitem is selected, callable or a callback id (string) as returned by [registerCallback] + untranslated/lower case path can be used to identity a menu, for this reason + it must be unique independently of case. + @param callback(callable): method to be called when menuitem is selected, callable + or a callback id (string) as returned by [registerCallback] @param security_limit(int): %(doc_security_limit)s /!\ security_limit MUST be added to data in launchCallback if used #TODO - @param help_string(unicode): string used to indicate what the menu do (can be show as a tooltip). + @param help_string(unicode): string used to indicate what the menu do (can be + show as a tooltip). /!\ use D_() instead of _() for translations @param type(unicode): one of: - - C.MENU_GLOBAL: classical menu, can be shown in a menubar on top (e.g. something like File/Open) + - C.MENU_GLOBAL: classical menu, can be shown in a menubar on top (e.g. + something like File/Open) - C.MENU_ROOM: like a global menu, but only shown in multi-user chat menu_data must contain a "room_jid" data - C.MENU_SINGLE: like a global menu, but only shown in one2one chat menu_data must contain a "jid" data - - C.MENU_JID_CONTEXT: contextual menu, used with any jid (e.g.: ad hoc commands, jid is already filled) + - C.MENU_JID_CONTEXT: contextual menu, used with any jid (e.g.: ad hoc + commands, jid is already filled) menu_data must contain a "jid" data - - C.MENU_ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in roster. + - C.MENU_ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in + roster. menu_data must contain a "room_jid" data - - C.MENU_ROSTER_GROUP_CONTEXT: contextual menu, used with group (e.g.: publish microblog, group is already filled) + - C.MENU_ROSTER_GROUP_CONTEXT: contextual menu, used with group (e.g.: publish + microblog, group is already filled) menu_data must contain a "group" data @return (unicode): menu_id (same as callback_id) """