More pylint improvements

This commit is contained in:
Nick Hall 2016-05-28 00:28:50 +01:00
parent 3c7e357bd1
commit 3255904acc

View File

@ -35,23 +35,7 @@ import time
import copy import copy
import subprocess import subprocess
from urllib.parse import urlparse from urllib.parse import urlparse
#-------------------------------------------------------------------------
#
# set up logging
#
#-------------------------------------------------------------------------
import logging import logging
LOG = logging.getLogger(".DbManager")
from gramps.gen.constfunc import win
if win():
_RCS_FOUND = os.system("rcs -V >nul 2>nul") == 0
if _RCS_FOUND and "TZ" not in os.environ:
# RCS requires the "TZ" variable be set.
os.environ["TZ"] = str(time.timezone)
else:
_RCS_FOUND = os.system("rcs -V >/dev/null 2>/dev/null") == 0
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -68,8 +52,6 @@ from gi.repository import Pango
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.plug import BasePluginManager
_ = glocale.translation.gettext
from gramps.gui.display import display_help from gramps.gui.display import display_help
from gramps.gen.const import URL_WIKISTRING, URL_MANUAL_PAGE from gramps.gen.const import URL_WIKISTRING, URL_MANUAL_PAGE
from .user import User from .user import User
@ -83,32 +65,49 @@ from .glade import Glade
from gramps.gen.db.exceptions import DbException from gramps.gen.db.exceptions import DbException
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gui.listmodel import ListModel from gramps.gui.listmodel import ListModel
from gramps.gen.constfunc import win
from gramps.gen.plug import BasePluginManager
_ = glocale.translation.gettext
_RETURN = Gdk.keyval_from_name("Return") #-------------------------------------------------------------------------
_KP_ENTER = Gdk.keyval_from_name("KP_Enter") #
# set up logging
#
#-------------------------------------------------------------------------
LOG = logging.getLogger(".DbManager")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# constants # constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
if win():
_RCS_FOUND = os.system("rcs -V >nul 2>nul") == 0
if _RCS_FOUND and "TZ" not in os.environ:
# RCS requires the "TZ" variable be set.
os.environ["TZ"] = str(time.timezone)
else:
_RCS_FOUND = os.system("rcs -V >/dev/null 2>/dev/null") == 0
_RETURN = Gdk.keyval_from_name("Return")
_KP_ENTER = Gdk.keyval_from_name("KP_Enter")
WIKI_HELP_PAGE = _('%s_-_Manage_Family_Trees') % URL_MANUAL_PAGE WIKI_HELP_PAGE = _('%s_-_Manage_Family_Trees') % URL_MANUAL_PAGE
WIKI_HELP_SEC = _('Family_Trees_manager_window') WIKI_HELP_SEC = _('Family_Trees_manager_window')
ARCHIVE = "rev.gramps" ARCHIVE = "rev.gramps"
ARCHIVE_V = "rev.gramps,v" ARCHIVE_V = "rev.gramps,v"
NAME_COL = 0 NAME_COL = 0
PATH_COL = 1 PATH_COL = 1
FILE_COL = 2 FILE_COL = 2
DATE_COL = 3 DATE_COL = 3
DSORT_COL = 4 DSORT_COL = 4
OPEN_COL = 5 OPEN_COL = 5
ICON_COL = 6 ICON_COL = 6
BACKEND_COL = 7 BACKEND_COL = 7
RCS_BUTTON = { True : _('_Extract'), False : _('_Archive') } RCS_BUTTON = {True : _('_Extract'), False : _('_Archive')}
class Information(ManagedWindow): class Information(ManagedWindow):
def __init__(self, uistate, data, parent): def __init__(self, uistate, data, parent):
@ -122,8 +121,8 @@ class Information(ManagedWindow):
self.window.set_default_size(600, 400) self.window.set_default_size(600, 400)
s = Gtk.ScrolledWindow() s = Gtk.ScrolledWindow()
titles = [ titles = [
(_('Setting'),0,150), (_('Setting'), 0, 150),
(_('Value'),1,400) (_('Value'), 1, 400)
] ]
treeview = Gtk.TreeView() treeview = Gtk.TreeView()
model = ListModel(treeview, titles) model = ListModel(treeview, titles)
@ -147,11 +146,11 @@ class DbManager(CLIDbManager):
create, rename, delete and open databases. create, rename, delete and open databases.
""" """
ICON_MAP = { ICON_MAP = {
CLIDbManager.ICON_NONE : None, CLIDbManager.ICON_NONE : None,
CLIDbManager.ICON_RECOVERY : 'dialog-error', CLIDbManager.ICON_RECOVERY : 'dialog-error',
CLIDbManager.ICON_LOCK : 'gramps-lock', CLIDbManager.ICON_LOCK : 'gramps-lock',
CLIDbManager.ICON_OPEN : 'document-open', CLIDbManager.ICON_OPEN : 'document-open',
} }
ERROR = ErrorDialog ERROR = ErrorDialog
@ -174,7 +173,7 @@ class DbManager(CLIDbManager):
setattr(self, attr, self.glade.get_object(attr)) setattr(self, attr, self.glade.get_object(attr))
self.model = None self.model = None
self.column = None self.column = None
self.lock_file = None self.lock_file = None
self.data_to_delete = None self.data_to_delete = None
@ -227,15 +226,14 @@ class DbManager(CLIDbManager):
self.top.connect('drag_data_received', self.__drag_data_received) self.top.connect('drag_data_received', self.__drag_data_received)
self.top.connect('drag_motion', drag_motion) self.top.connect('drag_motion', drag_motion)
self.top.connect('drag_drop', drop_cb) self.top.connect('drag_drop', drop_cb)
self.define_help_button(self.glade.get_object('help'), self.define_help_button(
WIKI_HELP_PAGE, WIKI_HELP_SEC) self.glade.get_object('help'), WIKI_HELP_PAGE, WIKI_HELP_SEC)
if _RCS_FOUND: if _RCS_FOUND:
self.rcs.connect('clicked', self.__rcs) self.rcs.connect('clicked', self.__rcs)
def define_help_button(self, button, webpage='', section=''): def define_help_button(self, button, webpage='', section=''):
button.connect('clicked', lambda x: display_help(webpage, button.connect('clicked', lambda x: display_help(webpage, section))
section))
def __button_press(self, obj, event): def __button_press(self, obj, event):
""" """
@ -307,7 +305,7 @@ class DbManager(CLIDbManager):
self.close.set_sensitive(False) self.close.set_sensitive(False)
backend_name = self.get_backend_name_from_dbid("bsddb") backend_name = self.get_backend_name_from_dbid("bsddb")
if (store.get_value(node, ICON_COL) in [None, ""] and if (store.get_value(node, ICON_COL) in [None, ""] and
store.get_value(node, BACKEND_COL).startswith(backend_name)): store.get_value(node, BACKEND_COL).startswith(backend_name)):
self.convert.set_sensitive(True) self.convert.set_sensitive(True)
else: else:
self.convert.set_sensitive(False) self.convert.set_sensitive(False)
@ -433,7 +431,7 @@ class DbManager(CLIDbManager):
If skippath given, the name of skippath is not considered If skippath given, the name of skippath is not considered
""" """
iter = self.model.get_iter_first() iter = self.model.get_iter_first()
while (iter): while iter:
path = self.model.get_path(iter) path = self.model.get_path(iter)
if path == skippath: if path == skippath:
pass pass
@ -548,7 +546,7 @@ class DbManager(CLIDbManager):
self.before_change = old_text self.before_change = old_text
self.after_change = new_text self.after_change = new_text
if not old_text.strip() == new_text.strip(): if not old_text.strip() == new_text.strip():
if len(path.get_indices()) > 1 : if len(path.get_indices()) > 1:
self.__rename_revision(path, new_text) self.__rename_revision(path, new_text)
else: else:
self.__rename_database(path, new_text) self.__rename_database(path, new_text)
@ -569,9 +567,9 @@ class DbManager(CLIDbManager):
rev = self.model.get_value(node, PATH_COL) rev = self.model.get_value(node, PATH_COL)
archive = os.path.join(db_dir, ARCHIVE_V) archive = os.path.join(db_dir, ARCHIVE_V)
cmd = [ "rcs", "-x,v", "-m%s:%s" % (rev, new_text), archive ] cmd = ["rcs", "-x,v", "-m%s:%s" % (rev, new_text), archive]
proc = subprocess.Popen(cmd, stderr = subprocess.PIPE) proc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
status = proc.wait() status = proc.wait()
message = "\n".join(proc.stderr.readlines()) message = "\n".join(proc.stderr.readlines())
proc.stderr.close() proc.stderr.close()
@ -598,11 +596,12 @@ class DbManager(CLIDbManager):
node = self.model.get_iter(path) node = self.model.get_iter(path)
filename = self.model.get_value(node, FILE_COL) filename = self.model.get_value(node, FILE_COL)
if self.existing_name(new_text, skippath=path): if self.existing_name(new_text, skippath=path):
DbManager.ERROR(_("Could not rename the Family Tree."), DbManager.ERROR(
_("Family Tree already exists, choose a unique name.")) _("Could not rename the Family Tree."),
_("Family Tree already exists, choose a unique name."))
return return
old_text, new_text = self.rename_database(filename, new_text) old_text, new_text = self.rename_database(filename, new_text)
if not (old_text is None): if old_text is not None:
rename_filename(old_text, new_text) rename_filename(old_text, new_text)
self.model.set_value(node, NAME_COL, new_text) self.model.set_value(node, NAME_COL, new_text)
#scroll to new position #scroll to new position
@ -698,7 +697,7 @@ class DbManager(CLIDbManager):
filename = self.model.get_value(node, FILE_COL) filename = self.model.get_value(node, FILE_COL)
try: try:
with open(filename, "r") as name_file: with open(filename, "r") as name_file:
file_name_to_delete=name_file.read() file_name_to_delete = name_file.read()
remove_filename(file_name_to_delete) remove_filename(file_name_to_delete)
directory = self.data_to_delete[1] directory = self.data_to_delete[1]
for (top, dirs, files) in os.walk(directory): for (top, dirs, files) in os.walk(directory):
@ -722,9 +721,9 @@ class DbManager(CLIDbManager):
rev = self.data_to_delete[PATH_COL] rev = self.data_to_delete[PATH_COL]
archive = os.path.join(db_dir, ARCHIVE_V) archive = os.path.join(db_dir, ARCHIVE_V)
cmd = [ "rcs", "-x,v", "-o%s" % rev, "-q", archive ] cmd = ["rcs", "-x,v", "-o%s" % rev, "-q", archive]
proc = subprocess.Popen(cmd, stderr = subprocess.PIPE) proc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
status = proc.wait() status = proc.wait()
message = "\n".join(proc.stderr.readlines()) message = "\n".join(proc.stderr.readlines())
proc.stderr.close() proc.stderr.close()
@ -858,8 +857,7 @@ class DbManager(CLIDbManager):
#First ask user if he is really sure :-) #First ask user if he is really sure :-)
yes_no = QuestionDialog2( yes_no = QuestionDialog2(
_("Repair Family Tree?"), _("Repair Family Tree?"),
_( _("If you click %(bold_start)sProceed%(bold_end)s, Gramps will "
"If you click %(bold_start)sProceed%(bold_end)s, Gramps will "
"attempt to recover your Family Tree from the last good " "attempt to recover your Family Tree from the last good "
"backup. There are several ways this can cause unwanted " "backup. There are several ways this can cause unwanted "
"effects, so %(bold_start)sbackup%(bold_end)s the " "effects, so %(bold_start)sbackup%(bold_end)s the "
@ -884,12 +882,12 @@ class DbManager(CLIDbManager):
"If this is the case, you can disable the repair button " "If this is the case, you can disable the repair button "
"by removing the file %(recover_file)s in the " "by removing the file %(recover_file)s in the "
"Family Tree directory." "Family Tree directory."
) % { 'bold_start' : '<b>' , ) % {'bold_start': '<b>',
'bold_end' : '</b>' , 'bold_end': '</b>',
'recover_file' : '<i>need_recover</i>' , 'recover_file': '<i>need_recover</i>',
'gramps_wiki_recover_url' : 'gramps_wiki_recover_url':
URL_WIKISTRING + 'Recover_corrupted_family_tree', URL_WIKISTRING + 'Recover_corrupted_family_tree',
'dirname' : dirname }, 'dirname': dirname},
_("Proceed, I have taken a backup"), _("Proceed, I have taken a backup"),
_("Stop")) _("Stop"))
prompt = yes_no.run() prompt = yes_no.run()
@ -934,7 +932,7 @@ class DbManager(CLIDbManager):
""" """
self.msg.set_label(msg) self.msg.set_label(msg)
self.top.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) self.top.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
while (Gtk.events_pending()): while Gtk.events_pending():
Gtk.main_iteration() Gtk.main_iteration()
def __end_cursor(self): def __end_cursor(self):
@ -1023,15 +1021,15 @@ def find_revisions(name):
""" """
import re import re
rev = re.compile("\s*revision\s+([\d\.]+)") rev = re.compile("\s*revision\s+([\d\.]+)")
date = re.compile("date:\s+(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)[-+]\d\d;") date = re.compile("date:\s+(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)[-+]\d\d;")
if not os.path.isfile(name) or not _RCS_FOUND: if not os.path.isfile(name) or not _RCS_FOUND:
return [] return []
rlog = [ "rlog", "-x,v", "-zLT" , name ] rlog = ["rlog", "-x,v", "-zLT", name]
proc = subprocess.Popen(rlog, stdout = subprocess.PIPE) proc = subprocess.Popen(rlog, stdout=subprocess.PIPE)
proc.wait() proc.wait()
revlist = [] revlist = []
@ -1051,9 +1049,9 @@ def find_revisions(name):
continue continue
match = date.match(line) match = date.match(line)
if match: if match:
date_str = time.strftime('%x %X', date_str = time.strftime(
time.strptime(match.groups()[0], '%Y-%m-%d %H:%M:%S')) '%x %X', time.strptime(match.groups()[0],
'%Y-%m-%d %H:%M:%S'))
get_next = True get_next = True
continue continue
if get_next: if get_next:
@ -1071,10 +1069,10 @@ def check_out(dbase, rev, path, user):
Checks out the revision from rcs, and loads the resulting XML file Checks out the revision from rcs, and loads the resulting XML file
into the database. into the database.
""" """
co_cmd = [ "co", "-x,v", "-q%s" % rev] + [ os.path.join(path, ARCHIVE), co_cmd = ["co", "-x,v", "-q%s" % rev] + [os.path.join(path, ARCHIVE),
os.path.join(path, ARCHIVE_V)] os.path.join(path, ARCHIVE_V)]
proc = subprocess.Popen(co_cmd, stderr = subprocess.PIPE) proc = subprocess.Popen(co_cmd, stderr=subprocess.PIPE)
status = proc.wait() status = proc.wait()
message = "\n".join(proc.stderr.readlines()) message = "\n".join(proc.stderr.readlines())
proc.stderr.close() proc.stderr.close()
@ -1097,12 +1095,12 @@ def check_out(dbase, rev, path, user):
rdr(dbase, xml_file, user) rdr(dbase, xml_file, user)
os.unlink(xml_file) os.unlink(xml_file)
def check_in(dbase, filename, user, cursor_func = None): def check_in(dbase, filename, user, cursor_func=None):
""" """
Checks in the specified file into RCS Checks in the specified file into RCS
""" """
init = [ "rcs", '-x,v', '-i', '-U', '-q', '-t-"Gramps database"' ] init = ["rcs", '-x,v', '-i', '-U', '-q', '-t-"Gramps database"']
ci_cmd = [ "ci", '-x,v', "-q", "-f" ] ci_cmd = ["ci", '-x,v', "-q", "-f"]
archive_name = filename + ",v" archive_name = filename + ",v"
glade = Glade(toplevel='comment') glade = Glade(toplevel='comment')
@ -1114,8 +1112,7 @@ def check_in(dbase, filename, user, cursor_func = None):
if not os.path.isfile(archive_name): if not os.path.isfile(archive_name):
cmd = init + [archive_name] cmd = init + [archive_name]
proc = subprocess.Popen(cmd, proc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
stderr = subprocess.PIPE)
status = proc.wait() status = proc.wait()
message = "\n".join(proc.stderr.readlines()) message = "\n".join(proc.stderr.readlines())
proc.stderr.close() proc.stderr.close()
@ -1140,9 +1137,8 @@ def check_in(dbase, filename, user, cursor_func = None):
if cursor_func: if cursor_func:
cursor_func(_("Saving archive...")) cursor_func(_("Saving archive..."))
cmd = ci_cmd + ['-m%s' % comment, filename, archive_name ] cmd = ci_cmd + ['-m%s' % comment, filename, archive_name]
proc = subprocess.Popen(cmd, proc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
stderr = subprocess.PIPE)
status = proc.wait() status = proc.wait()
message = "\n".join(proc.stderr.readlines()) message = "\n".join(proc.stderr.readlines())