Fix pyflakes/pycodestyle errors

This commit is contained in:
Philipp Hörist 2018-09-05 00:14:27 +02:00 committed by Philipp Hörist
parent 4d53bd9064
commit dd267359be
1 changed files with 143 additions and 106 deletions

View File

@ -1,50 +1,44 @@
# -*- coding:utf-8 -*- # Copyright (C) 2003-2017 Yann Leboulanger <asterix AT lagaule.org>
## src/gajim.py # Copyright (C) 2004-2005 Vincent Hanquez <tab AT snarc.org>
## # Copyright (C) 2005 Alex Podaras <bigpod AT gmail.com>
## Copyright (C) 2003-2017 Yann Leboulanger <asterix AT lagaule.org> # Norman Rasmussen <norman AT rasmussen.co.za>
## Copyright (C) 2004-2005 Vincent Hanquez <tab AT snarc.org> # Stéphan Kochen <stephan AT kochen.nl>
## Copyright (C) 2005 Alex Podaras <bigpod AT gmail.com> # Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com>
## Norman Rasmussen <norman AT rasmussen.co.za> # Alex Mauer <hawke AT hawkesnest.net>
## Stéphan Kochen <stephan AT kochen.nl> # Copyright (C) 2005-2007 Travis Shirk <travis AT pobox.com>
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com> # Nikos Kouremenos <kourem AT gmail.com>
## Alex Mauer <hawke AT hawkesnest.net> # Copyright (C) 2006 Junglecow J <junglecow AT gmail.com>
## Copyright (C) 2005-2007 Travis Shirk <travis AT pobox.com> # Stefan Bethge <stefan AT lanpartei.de>
## Nikos Kouremenos <kourem AT gmail.com> # Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
## Copyright (C) 2006 Junglecow J <junglecow AT gmail.com> # Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net>
## Stefan Bethge <stefan AT lanpartei.de> # James Newton <redshodan AT gmail.com>
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org> # Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
## Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net> # Julien Pivotto <roidelapluie AT gmail.com>
## James Newton <redshodan AT gmail.com> # Stephan Erb <steve-e AT h3c.de>
## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com> # Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
## Julien Pivotto <roidelapluie AT gmail.com> # Copyright (C) 2016-2017 Emmanuel Gil Peyrot <linkmauve AT linkmauve.fr>
## Stephan Erb <steve-e AT h3c.de> # Philipp Hörist <philipp AT hoerist.com>
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org> #
## Copyright (C) 2016-2017 Emmanuel Gil Peyrot <linkmauve AT linkmauve.fr> # This file is part of Gajim.
## Philipp Hörist <philipp AT hoerist.com> #
## # Gajim is free software; you can redistribute it and/or modify
## This file is part of Gajim. # it under the terms of the GNU General Public License as published
## # by the Free Software Foundation; version 3 only.
## Gajim is free software; you can redistribute it and/or modify #
## it under the terms of the GNU General Public License as published # Gajim is distributed in the hope that it will be useful,
## by the Free Software Foundation; version 3 only. # but WITHOUT ANY WARRANTY; without even the implied warranty of
## # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## Gajim is distributed in the hope that it will be useful, # GNU General Public License for more details.
## but WITHOUT ANY WARRANTY; without even the implied warranty of #
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # You should have received a copy of the GNU General Public License
## GNU General Public License for more details. # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
## You should have received a copy of the GNU General Public License
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
import sys import sys
import os
from urllib.parse import unquote from urllib.parse import unquote
from gi.repository import GLib, Gio, Gtk from gi.repository import GLib, Gio, Gtk
from gajim.common import app from gajim.common import app
from gajim.common import i18n
from gajim.common import configpaths from gajim.common import configpaths
from gajim.common import logging_helpers from gajim.common import logging_helpers
from gajim.common import exceptions from gajim.common import exceptions
@ -56,47 +50,91 @@ class GajimApplication(Gtk.Application):
'''Main class handling activation and command line.''' '''Main class handling activation and command line.'''
def __init__(self): def __init__(self):
Gtk.Application.__init__(self, application_id='org.gajim.Gajim', flags = (Gio.ApplicationFlags.HANDLES_COMMAND_LINE |
flags=( Gio.ApplicationFlags.HANDLES_OPEN)
Gio.ApplicationFlags.HANDLES_COMMAND_LINE | Gtk.Application.__init__(self,
Gio.ApplicationFlags.HANDLES_OPEN)) application_id='org.gajim.Gajim',
flags=flags)
self.add_main_option('version', ord('V'), GLib.OptionFlags.NONE, self.add_main_option(
GLib.OptionArg.NONE, 'version',
_('Show the application\'s version')) ord('V'),
self.add_main_option('quiet', ord('q'), GLib.OptionFlags.NONE, GLib.OptionFlags.NONE,
GLib.OptionArg.NONE, GLib.OptionArg.NONE,
_('Show only critical errors')) _('Show the application\'s version'))
self.add_main_option('separate', ord('s'), GLib.OptionFlags.NONE,
GLib.OptionArg.NONE, self.add_main_option(
_('Separate profile files completely (even ' 'quiet',
'history database and plugins)')) ord('q'),
self.add_main_option('verbose', ord('v'), GLib.OptionFlags.NONE, GLib.OptionFlags.NONE,
GLib.OptionArg.NONE, GLib.OptionArg.NONE,
_('Print XML stanzas and other debug ' _('Show only critical errors'))
'information'))
self.add_main_option('profile', ord('p'), GLib.OptionFlags.NONE, self.add_main_option(
GLib.OptionArg.STRING, 'separate',
_('Use defined profile in configuration ' ord('s'),
'directory'), 'NAME') GLib.OptionFlags.NONE,
self.add_main_option('config-path', ord('c'), GLib.OptionFlags.NONE, GLib.OptionArg.NONE,
GLib.OptionArg.STRING, _('Separate profile files completely '
_('Set configuration directory'), 'PATH') '(even history database and plugins)'))
self.add_main_option('loglevel', ord('l'), GLib.OptionFlags.NONE,
GLib.OptionArg.STRING, self.add_main_option(
_('Configure logging system'), 'LEVEL') 'verbose',
self.add_main_option('warnings', ord('w'), GLib.OptionFlags.NONE, ord('v'),
GLib.OptionArg.NONE, GLib.OptionFlags.NONE,
_('Show all warnings')) GLib.OptionArg.NONE,
self.add_main_option('ipython', ord('i'), GLib.OptionFlags.NONE, _('Print XML stanzas and other debug information'))
GLib.OptionArg.NONE,
_('Open IPython shell')) self.add_main_option(
self.add_main_option('show-next-pending-event', 0, GLib.OptionFlags.NONE, 'profile',
GLib.OptionArg.NONE, ord('p'),
_('Pops up a window with the next pending event')) GLib.OptionFlags.NONE,
self.add_main_option('start-chat', 0, GLib.OptionFlags.NONE, GLib.OptionArg.STRING,
GLib.OptionArg.NONE, _('Use defined profile in configuration directory'),
_('Start a new chat')) 'NAME')
self.add_main_option(
'config-path',
ord('c'),
GLib.OptionFlags.NONE,
GLib.OptionArg.STRING,
_('Set configuration directory'),
'PATH')
self.add_main_option(
'loglevel',
ord('l'),
GLib.OptionFlags.NONE,
GLib.OptionArg.STRING,
_('Configure logging system'),
'LEVEL')
self.add_main_option(
'warnings',
ord('w'),
GLib.OptionFlags.NONE,
GLib.OptionArg.NONE,
_('Show all warnings'))
self.add_main_option(
'ipython',
ord('i'),
GLib.OptionFlags.NONE,
GLib.OptionArg.NONE,
_('Open IPython shell'))
self.add_main_option(
'show-next-pending-event',
0,
GLib.OptionFlags.NONE,
GLib.OptionArg.NONE,
_('Pops up a window with the next pending event'))
self.add_main_option(
'start-chat', 0,
GLib.OptionFlags.NONE,
GLib.OptionArg.NONE,
_('Start a new chat'))
self.add_main_option_entries(self._get_remaining_entry()) self.add_main_option_entries(self._get_remaining_entry())
@ -186,11 +224,12 @@ class GajimApplication(Gtk.Application):
attributes = cmd.split(';') attributes = cmd.split(';')
message = None message = None
for key in attributes: for key in attributes:
if key.startswith('body'): if not key.startswith('body'):
try: continue
message = unquote(key.split('=')[1]) try:
except Exception: message = unquote(key.split('=')[1])
app.log('uri_handler').error('Invalid URI: %s', cmd) except Exception:
app.log('uri_handler').error('Invalid URI: %s', cmd)
accounts = list(app.connections.keys()) accounts = list(app.connections.keys())
if not accounts: if not accounts:
continue continue
@ -339,33 +378,31 @@ class GajimApplication(Gtk.Application):
self.add_account_actions(accounts_list[0]) self.add_account_actions(accounts_list[0])
def _get_account_actions(self, account): def _get_account_actions(self, account):
from gajim import app_actions from gajim import app_actions as a
if account == 'Local': if account == 'Local':
return [ return [
('-xml-console', app_actions.on_xml_console, 'always', 's') ('-xml-console', a.on_xml_console, 'always', 's')
] ]
return [ return [
('-start-single-chat', app_actions.on_single_message, 'online', 's'), ('-start-single-chat', a.on_single_message, 'online', 's'),
('-join-groupchat', app_actions.on_join_gc, 'online', 's'), ('-join-groupchat', a.on_join_gc, 'online', 's'),
('-add-contact', app_actions.on_add_contact, 'online', 's'), ('-add-contact', a.on_add_contact, 'online', 's'),
('-services', app_actions.on_service_disco, 'online', 's'), ('-services', a.on_service_disco, 'online', 's'),
('-profile', app_actions.on_profile, 'feature', 's'), ('-profile', a.on_profile, 'feature', 's'),
('-xml-console', app_actions.on_xml_console, 'always', 's'), ('-xml-console', a.on_xml_console, 'always', 's'),
('-server-info', app_actions.on_server_info, 'online', 's'), ('-server-info', a.on_server_info, 'online', 's'),
('-archive', app_actions.on_mam_preferences, 'feature', 's'), ('-archive', a.on_mam_preferences, 'feature', 's'),
('-sync-history', app_actions.on_history_sync, 'online', 's'), ('-sync-history', a.on_history_sync, 'online', 's'),
('-privacylists', app_actions.on_privacy_lists, 'feature', 's'), ('-privacylists', a.on_privacy_lists, 'feature', 's'),
('-send-server-message', ('-send-server-message', a.on_send_server_message, 'online', 's'),
app_actions.on_send_server_message, 'online', 's'), ('-set-motd', a.on_set_motd, 'online', 's'),
('-set-motd', app_actions.on_set_motd, 'online', 's'), ('-update-motd', a.on_update_motd, 'online', 's'),
('-update-motd', app_actions.on_update_motd, 'online', 's'), ('-delete-motd', a.on_delete_motd, 'online', 's'),
('-delete-motd', app_actions.on_delete_motd, 'online', 's'), ('-activate-bookmark', a.on_activate_bookmark, 'online', 'a{sv}'),
('-activate-bookmark', ('-open-event', a.on_open_event, 'always', 'a{sv}'),
app_actions.on_activate_bookmark, 'online', 'a{sv}'), ('-import-contacts', a.on_import_contacts, 'online', 's'),
('-open-event', app_actions.on_open_event, 'always', 'a{sv}'),
('-import-contacts', app_actions.on_import_contacts, 'online', 's'),
] ]
def add_account_actions(self, account): def add_account_actions(self, account):