increase pylint score

This commit is contained in:
Paul Franklin
2016-08-06 16:13:30 -07:00
parent 94f0c9ee90
commit 2e3a4fd55f

View File

@@ -65,7 +65,7 @@ _ = glocale.translation.sgettext
from gramps.cli.grampscli import CLIManager from gramps.cli.grampscli import CLIManager
from .user import User from .user import User
from .plug import tool from .plug import tool
from gramps.gen.plug import (START, END) from gramps.gen.plug import START
from gramps.gen.plug import REPORT from gramps.gen.plug import REPORT
from gramps.gen.plug.report._constants import standalone_categories from gramps.gen.plug.report._constants import standalone_categories
from .plug import (PluginWindows, ReportPluginDialog, ToolPluginDialog) from .plug import (PluginWindows, ReportPluginDialog, ToolPluginDialog)
@@ -87,7 +87,6 @@ from gramps.gen.utils.file import media_path_full
from .dbloader import DbLoader from .dbloader import DbLoader
from .display import display_help, display_url from .display import display_help, display_url
from .configure import GrampsPreferences from .configure import GrampsPreferences
from gramps.gen.db.exceptions import DbException
from .aboutdialog import GrampsAboutDialog from .aboutdialog import GrampsAboutDialog
from .navigator import Navigator from .navigator import Navigator
from .views.tags import Tags from .views.tags import Tags
@@ -320,9 +319,9 @@ class ViewManager(CLIManager):
howoften = config.get("behavior.check-for-updates") howoften = config.get("behavior.check-for-updates")
update = False update = False
if howoften != 0: # update never if zero if howoften != 0: # update never if zero
y,m,d = list(map(int, year, mon, day = list(map(
config.get("behavior.last-check-for-updates").split("/"))) int, config.get("behavior.last-check-for-updates").split("/")))
days = (datetime.date.today() - datetime.date(y, m, d)).days days = (datetime.date.today() - datetime.date(year, mon, day)).days
if howoften == 1 and days >= 30: # once a month if howoften == 1 and days >= 30: # once a month
update = True update = True
elif howoften == 2 and days >= 7: # once a week elif howoften == 2 and days >= 7: # once a week
@@ -524,16 +523,26 @@ class ViewManager(CLIManager):
('F8', None, 'F9', "F8", None, self.__keypress), ('F8', None, 'F9', "F8", None, self.__keypress),
('F9', None, 'F9', "F9", None, self.__keypress), ('F9', None, 'F9', "F9", None, self.__keypress),
('F11', None, 'F11', "F11", None, self.__keypress), ('F11', None, 'F11', "F11", None, self.__keypress),
('<PRIMARY>1', None, '<PRIMARY>1', "<PRIMARY>1", None, self.__gocat), ('<PRIMARY>1', None, '<PRIMARY>1', "<PRIMARY>1", None,
('<PRIMARY>2', None, '<PRIMARY>2', "<PRIMARY>2", None, self.__gocat), self.__gocat),
('<PRIMARY>3', None, '<PRIMARY>3', "<PRIMARY>3", None, self.__gocat), ('<PRIMARY>2', None, '<PRIMARY>2', "<PRIMARY>2", None,
('<PRIMARY>4', None, '<PRIMARY>4', "<PRIMARY>4", None, self.__gocat), self.__gocat),
('<PRIMARY>5', None, '<PRIMARY>5', "<PRIMARY>5", None, self.__gocat), ('<PRIMARY>3', None, '<PRIMARY>3', "<PRIMARY>3", None,
('<PRIMARY>6', None, '<PRIMARY>6', "<PRIMARY>6", None, self.__gocat), self.__gocat),
('<PRIMARY>7', None, '<PRIMARY>7', "<PRIMARY>7", None, self.__gocat), ('<PRIMARY>4', None, '<PRIMARY>4', "<PRIMARY>4", None,
('<PRIMARY>8', None, '<PRIMARY>8', "<PRIMARY>8", None, self.__gocat), self.__gocat),
('<PRIMARY>9', None, '<PRIMARY>9', "<PRIMARY>9", None, self.__gocat), ('<PRIMARY>5', None, '<PRIMARY>5', "<PRIMARY>5", None,
('<PRIMARY>0', None, '<PRIMARY>0', "<PRIMARY>0", None, self.__gocat), self.__gocat),
('<PRIMARY>6', None, '<PRIMARY>6', "<PRIMARY>6", None,
self.__gocat),
('<PRIMARY>7', None, '<PRIMARY>7', "<PRIMARY>7", None,
self.__gocat),
('<PRIMARY>8', None, '<PRIMARY>8', "<PRIMARY>8", None,
self.__gocat),
('<PRIMARY>9', None, '<PRIMARY>9', "<PRIMARY>9", None,
self.__gocat),
('<PRIMARY>0', None, '<PRIMARY>0', "<PRIMARY>0", None,
self.__gocat),
# NOTE: CTRL+ALT+NUMBER is set in src/plugins/sidebar/cat...py # NOTE: CTRL+ALT+NUMBER is set in src/plugins/sidebar/cat...py
('<PRIMARY>BackSpace', None, '<PRIMARY>BackSpace', ('<PRIMARY>BackSpace', None, '<PRIMARY>BackSpace',
"<PRIMARY>BackSpace", None, self.__keypress), "<PRIMARY>BackSpace", None, self.__keypress),
@@ -626,8 +635,8 @@ class ViewManager(CLIManager):
def __next_view(self, action): def __next_view(self, action):
""" """
Callback that is called when the next category action is selected. Callback that is called when the next category action is selected. It
It selects the next category as the active category. If we reach the end, selects the next category as the active category. If we reach the end,
we wrap around to the first. we wrap around to the first.
""" """
curpage = self.notebook.get_current_page() curpage = self.notebook.get_current_page()
@@ -645,8 +654,8 @@ class ViewManager(CLIManager):
def __prev_view(self, action): def __prev_view(self, action):
""" """
Callback that is called when the previous category action is selected. Callback that is called when the previous category action is selected.
It selects the previous category as the active category. If we reach the It selects the previous category as the active category. If we reach
beginning of the list, we wrap around to the last. the beginning of the list, we wrap around to the last.
""" """
curpage = self.notebook.get_current_page() curpage = self.notebook.get_current_page()
#find cat and view of the current page #find cat and view of the current page
@@ -832,12 +841,16 @@ class ViewManager(CLIManager):
self.uimanager.ensure_update() self.uimanager.ensure_update()
def __attach_menubar(self, vbox): def __attach_menubar(self, vbox):
"""
Attach the menubar
"""
vbox.pack_start(self.menubar, False, True, 0) vbox.pack_start(self.menubar, False, True, 0)
if _GTKOSXAPPLICATION: if _GTKOSXAPPLICATION:
self.menubar.hide() self.menubar.hide()
quit_item = self.uimanager.get_widget("/MenuBar/FileMenu/Quit") quit_item = self.uimanager.get_widget("/MenuBar/FileMenu/Quit")
about_item = self.uimanager.get_widget("/MenuBar/HelpMenu/About") about_item = self.uimanager.get_widget("/MenuBar/HelpMenu/About")
prefs_item = self.uimanager.get_widget("/MenuBar/EditMenu/Preferences") prefs_item = self.uimanager.get_widget(
"/MenuBar/EditMenu/Preferences")
self.macapp.set_menu_bar(self.menubar) self.macapp.set_menu_bar(self.menubar)
self.macapp.insert_app_menu_item(about_item, 0) self.macapp.insert_app_menu_item(about_item, 0)
self.macapp.insert_app_menu_item(prefs_item, 1) self.macapp.insert_app_menu_item(prefs_item, 1)
@@ -943,6 +956,7 @@ class ViewManager(CLIManager):
return None return None
def __create_dummy_page(self, pdata, error): def __create_dummy_page(self, pdata, error):
""" Create a dummy page """
from .views.pageview import DummyPage from .views.pageview import DummyPage
return DummyPage(pdata.name, pdata, self.dbstate, self.uistate, return DummyPage(pdata.name, pdata, self.dbstate, self.uistate,
_("View failed to load. Check error output."), error) _("View failed to load. Check error output."), error)
@@ -955,7 +969,7 @@ class ViewManager(CLIManager):
page = page_def(pdata, self.dbstate, self.uistate) page = page_def(pdata, self.dbstate, self.uistate)
except: except:
import traceback import traceback
LOG.warning("View '%s' failed to load." % pdata.id) LOG.warning("View '%s' failed to load.", pdata.id)
traceback.print_exc() traceback.print_exc()
page = self.__create_dummy_page(pdata, traceback.format_exc()) page = self.__create_dummy_page(pdata, traceback.format_exc())
@@ -1122,12 +1136,13 @@ class ViewManager(CLIManager):
delim = old_title.find(' - ') delim = old_title.find(' - ')
tit1 = old_title[:delim] tit1 = old_title[:delim]
tit2 = old_title[delim:] tit2 = old_title[delim:]
new_title = dialog.after_change
if '<=' in tit2: if '<=' in tit2:
delim2 = tit2.find('<=') + 3 ## delim2 = tit2.find('<=') + 3
tit3 = tit2[delim2:-1] ## tit3 = tit2[delim2:-1]
new_title = dialog.after_change + tit2.replace(']', '') + ' => ' + tit1 + ']' new_title += tit2.replace(']', '') + ' => ' + tit1 + ']'
else: else:
new_title = dialog.after_change + tit2 + ' <= [' + tit1 + ']' new_title += tit2 + ' <= [' + tit1 + ']'
self.uistate.window.set_title(new_title) self.uistate.window.set_title(new_title)
def __post_load(self): def __post_load(self):
@@ -1292,7 +1307,8 @@ class ViewManager(CLIManager):
file_entry = Gtk.Entry() file_entry = Gtk.Entry()
button = Gtk.Button() button = Gtk.Button()
button.connect("clicked", button.connect("clicked",
lambda widget: self.select_backup_path(widget, path_entry)) lambda widget:
self.select_backup_path(widget, path_entry))
image = Gtk.Image() image = Gtk.Image()
image.set_from_icon_name('document-open', Gtk.IconSize.BUTTON) image.set_from_icon_name('document-open', Gtk.IconSize.BUTTON)
image.show() image.show()
@@ -1306,30 +1322,30 @@ class ViewManager(CLIManager):
label.set_halign(Gtk.Align.START) label.set_halign(Gtk.Align.START)
hbox.pack_start(label, False, True, 0) hbox.pack_start(label, False, True, 0)
struct_time = time.localtime() struct_time = time.localtime()
file_entry.set_text(config.get('paths.quick-backup-filename') % file_entry.set_text(
{"filename": self.dbstate.db.get_dbname(), config.get('paths.quick-backup-filename'
) % {"filename": self.dbstate.db.get_dbname(),
"year": struct_time.tm_year, "year": struct_time.tm_year,
"month": struct_time.tm_mon, "month": struct_time.tm_mon,
"day": struct_time.tm_mday, "day": struct_time.tm_mday,
"hour": struct_time.tm_hour, "hour": struct_time.tm_hour,
"minutes": struct_time.tm_min, "minutes": struct_time.tm_min,
"seconds": struct_time.tm_sec, "seconds": struct_time.tm_sec,
"extension": "gpkg", "extension": "gpkg"})
})
hbox.pack_end(file_entry, True, True, 0) hbox.pack_end(file_entry, True, True, 0)
vbox.pack_start(hbox, False, True, 0) vbox.pack_start(hbox, False, True, 0)
hbox = Gtk.Box() hbox = Gtk.Box()
bytes = 0 fbytes = 0
mbytes = "0" mbytes = "0"
for media in self.dbstate.db.iter_media(): for media in self.dbstate.db.iter_media():
fullname = media_path_full(self.dbstate.db, media.get_path()) fullname = media_path_full(self.dbstate.db, media.get_path())
try: try:
bytes += posixpath.getsize(fullname) fbytes += posixpath.getsize(fullname)
length = len(str(bytes)) length = len(str(fbytes))
if bytes <= 999999: if fbytes <= 999999:
mbytes = "< 1" mbytes = "< 1"
else: else:
mbytes = str(bytes)[:(length-6)] mbytes = str(fbytes)[:(length-6)]
except OSError: except OSError:
pass pass
label = Gtk.Label(label=_("Media:")) label = Gtk.Label(label=_("Media:"))
@@ -1340,15 +1356,17 @@ class ViewManager(CLIManager):
include = Gtk.RadioButton.new_with_mnemonic_from_widget( include = Gtk.RadioButton.new_with_mnemonic_from_widget(
None, "%s (%s %s)" % (_("Include"), None, "%s (%s %s)" % (_("Include"),
mbytes, _("Megabyte|MB"))) mbytes, _("Megabyte|MB")))
exclude = Gtk.RadioButton.new_with_mnemonic_from_widget(include, _("Exclude")) exclude = Gtk.RadioButton.new_with_mnemonic_from_widget(include,
include.connect("toggled", lambda widget: self.media_toggle(widget, file_entry)) _("Exclude"))
include.connect("toggled", lambda widget: self.media_toggle(widget,
file_entry))
hbox.pack_start(include, False, True, 0) hbox.pack_start(include, False, True, 0)
hbox.pack_end(exclude, False, True, 0) hbox.pack_end(exclude, False, True, 0)
vbox.pack_start(hbox, False, True, 0) vbox.pack_start(hbox, False, True, 0)
window.show_all() window.show_all()
d = window.run() dbackup = window.run()
window.hide() window.hide()
if d == Gtk.ResponseType.APPLY: if dbackup == Gtk.ResponseType.APPLY:
# if file exists, ask if overwrite; else abort # if file exists, ask if overwrite; else abort
basefile = file_entry.get_text() basefile = file_entry.get_text()
basefile = basefile.replace("/", r"-") basefile = basefile.replace("/", r"-")
@@ -1378,7 +1396,8 @@ class ViewManager(CLIManager):
writer.write(filename) writer.write(filename)
self.uistate.set_busy_cursor(False) self.uistate.set_busy_cursor(False)
self.uistate.progress.hide() self.uistate.progress.hide()
self.uistate.push_message(self.dbstate, _("Backup saved to '%s'") % filename) self.uistate.push_message(self.dbstate,
_("Backup saved to '%s'") % filename)
config.set('paths.quick-backup-directory', path_entry.get_text()) config.set('paths.quick-backup-directory', path_entry.get_text())
else: else:
self.uistate.push_message(self.dbstate, _("Backup aborted")) self.uistate.push_message(self.dbstate, _("Backup aborted"))
@@ -1389,7 +1408,7 @@ class ViewManager(CLIManager):
Choose a backup folder. Make sure there is one highlighted in Choose a backup folder. Make sure there is one highlighted in
right pane, otherwise FileChooserDialog will hang. right pane, otherwise FileChooserDialog will hang.
""" """
f = Gtk.FileChooserDialog( fdialog = Gtk.FileChooserDialog(
title=_("Select backup directory"), title=_("Select backup directory"),
parent=self.window, parent=self.window,
action=Gtk.FileChooserAction.SELECT_FOLDER, action=Gtk.FileChooserAction.SELECT_FOLDER,
@@ -1400,14 +1419,14 @@ class ViewManager(CLIManager):
mpath = path_entry.get_text() mpath = path_entry.get_text()
if not mpath: if not mpath:
mpath = HOME_DIR mpath = HOME_DIR
f.set_current_folder(os.path.dirname(mpath)) fdialog.set_current_folder(os.path.dirname(mpath))
f.set_filename(os.path.join(mpath, ".")) fdialog.set_filename(os.path.join(mpath, "."))
status = f.run() status = fdialog.run()
if status == Gtk.ResponseType.OK: if status == Gtk.ResponseType.OK:
filename = f.get_filename() filename = fdialog.get_filename()
if filename: if filename:
path_entry.set_text(filename) path_entry.set_text(filename)
f.destroy() fdialog.destroy()
return True return True
def media_toggle(self, widget, file_entry): def media_toggle(self, widget, file_entry):
@@ -1525,11 +1544,11 @@ class ViewManager(CLIManager):
self.uistate.uimanager.remove_action_group(self.reportactions) self.uistate.uimanager.remove_action_group(self.reportactions)
self.uistate.uimanager.remove_ui(self.report_menu_ui_id) self.uistate.uimanager.remove_ui(self.report_menu_ui_id)
self.reportactions = Gtk.ActionGroup(name='ReportWindow') self.reportactions = Gtk.ActionGroup(name='ReportWindow')
(uidef, actions) = self.build_plugin_menu( (udef, actions) = self.build_plugin_menu(
'ReportsMenu', report_menu_list, standalone_categories, 'ReportsMenu', report_menu_list, standalone_categories,
make_plugin_callback) make_plugin_callback)
self.reportactions.add_actions(actions) self.reportactions.add_actions(actions)
self.report_menu_ui_id = self.uistate.uimanager.add_ui_from_string(uidef) self.report_menu_ui_id = self.uistate.uimanager.add_ui_from_string(udef)
self.uimanager.insert_action_group(self.reportactions, 1) self.uimanager.insert_action_group(self.reportactions, 1)
self.uistate.uimanager.ensure_update() self.uistate.uimanager.ensure_update()
@@ -1554,8 +1573,7 @@ class ViewManager(CLIManager):
hash_data[category].append(pdata) hash_data[category].append(pdata)
# Sort categories, skipping the unsupported # Sort categories, skipping the unsupported
catlist = sorted(item for item in hash_data catlist = sorted(item for item in hash_data if item != _UNSUPPORTED)
if item != _UNSUPPORTED)
for key in catlist: for key in catlist:
new_key = key[0].replace(' ', '-') new_key = key[0].replace(' ', '-')
@@ -1716,11 +1734,11 @@ def run_plugin(pdata, dbstate, uistate):
'the plugin author (%(firstauthoremail)s).\n\n' 'the plugin author (%(firstauthoremail)s).\n\n'
'If you do not want Gramps to try and load this plugin again, ' 'If you do not want Gramps to try and load this plugin again, '
'you can hide it by using the Plugin Manager on the ' 'you can hide it by using the Plugin Manager on the '
'Help menu.') % { 'Help menu.') % {'name' : pdata.name,
'name': pdata.name,
'gramps_bugtracker_url' : URL_BUGHOME, 'gramps_bugtracker_url' : URL_BUGHOME,
'firstauthoremail': pdata.authors_email[0] if 'firstauthoremail' : pdata.authors_email[0]
pdata.authors_email else '...', if pdata.authors_email
else '...',
'error_msg' : error_msg}, 'error_msg' : error_msg},
parent=uistate.window) parent=uistate.window)
return return
@@ -1730,8 +1748,7 @@ def run_plugin(pdata, dbstate, uistate):
getattr(mod, pdata.reportclass), getattr(mod, pdata.reportclass),
getattr(mod, pdata.optionclass), getattr(mod, pdata.optionclass),
pdata.name, pdata.id, pdata.name, pdata.id,
pdata.category, pdata.require_active, pdata.category, pdata.require_active)
)
else: else:
tool.gui_tool(dbstate=dbstate, user=User(uistate=uistate), tool.gui_tool(dbstate=dbstate, user=User(uistate=uistate),
tool_class=getattr(mod, pdata.toolclass), tool_class=getattr(mod, pdata.toolclass),