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