increase pylint score by 2.11
This commit is contained in:
parent
b6d8223192
commit
c6d4eee407
@ -19,6 +19,8 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
""" This contains the main class corresponding to a running gramps process """
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Python modules
|
# Python modules
|
||||||
@ -36,7 +38,7 @@ LOG = logging.getLogger(".grampsgui")
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gramps.gen.config import config
|
from gramps.gen.config import config
|
||||||
from gramps.gen.const import DATA_DIR, IMAGE_DIR, GTK_GETTEXT_DOMAIN
|
from gramps.gen.const import DATA_DIR, IMAGE_DIR, GTK_GETTEXT_DOMAIN
|
||||||
from gramps.gen.constfunc import has_display, win, lin
|
from gramps.gen.constfunc import has_display, lin
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
_ = glocale.translation.gettext
|
_ = glocale.translation.gettext
|
||||||
|
|
||||||
@ -53,30 +55,30 @@ MIN_GTK_VERSION = (3, 10)
|
|||||||
try:
|
try:
|
||||||
#import gnome introspection, part of pygobject
|
#import gnome introspection, part of pygobject
|
||||||
import gi
|
import gi
|
||||||
giversion = gi.require_version
|
GIVERSION = gi.require_version
|
||||||
except:
|
except:
|
||||||
print(_("Your version of gi (gnome-introspection) seems to be too old. "
|
print(_("Your version of gi (gnome-introspection) seems to be too old. "
|
||||||
"You need a version which has the function 'require_version' "
|
"You need a version which has the function 'require_version' "
|
||||||
"to start Gramps"))
|
"to start Gramps"))
|
||||||
sys.exit(0)
|
sys.exit(1)
|
||||||
|
|
||||||
if not PYGOBJ_ERR:
|
if not PYGOBJ_ERR:
|
||||||
try:
|
try:
|
||||||
from gi.repository import GObject, GLib
|
from gi.repository import GObject, GLib
|
||||||
if not GObject.pygobject_version >= MIN_PYGOBJECT_VERSION :
|
if not GObject.pygobject_version >= MIN_PYGOBJECT_VERSION:
|
||||||
PYGOBJ_ERR = True
|
PYGOBJ_ERR = True
|
||||||
except:
|
except:
|
||||||
PYGOBJ_ERR = True
|
PYGOBJ_ERR = True
|
||||||
|
|
||||||
if PYGOBJ_ERR:
|
if PYGOBJ_ERR:
|
||||||
print((_("Your pygobject version does not meet the requirements.\n"
|
print(_("Your pygobject version does not meet the requirements.\n"
|
||||||
"At least pygobject %(major)d.%(feature)d.%(minor)d "
|
"At least pygobject %(major)d.%(feature)d.%(minor)d "
|
||||||
"is needed to start Gramps with a GUI.\n\n"
|
"is needed to start Gramps with a GUI.\n\n"
|
||||||
"Gramps will terminate now.") %
|
"Gramps will terminate now."
|
||||||
{'major':MIN_PYGOBJECT_VERSION[0],
|
) % {'major' : MIN_PYGOBJECT_VERSION[0],
|
||||||
'feature':MIN_PYGOBJECT_VERSION[1],
|
'feature' : MIN_PYGOBJECT_VERSION[1],
|
||||||
'minor':MIN_PYGOBJECT_VERSION[2]}))
|
'minor' : MIN_PYGOBJECT_VERSION[2]})
|
||||||
sys.exit(0)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
gi.require_version('Pango', '1.0')
|
gi.require_version('Pango', '1.0')
|
||||||
@ -93,26 +95,26 @@ except (ImportError, ValueError):
|
|||||||
"Then install introspection data for Gdk, Gtk, Pango and "
|
"Then install introspection data for Gdk, Gtk, Pango and "
|
||||||
"PangoCairo\n\n"
|
"PangoCairo\n\n"
|
||||||
"Gramps will terminate now.")))
|
"Gramps will terminate now.")))
|
||||||
sys.exit(0)
|
sys.exit(1)
|
||||||
|
|
||||||
gtk_major = Gtk.get_major_version()
|
GTK_MAJOR = Gtk.get_major_version()
|
||||||
gtk_minor = Gtk.get_minor_version()
|
GTK_MINOR = Gtk.get_minor_version()
|
||||||
if (gtk_major, gtk_minor) < MIN_GTK_VERSION:
|
if (GTK_MAJOR, GTK_MINOR) < MIN_GTK_VERSION:
|
||||||
print(_("Your Gtk version does not meet the requirements.\n"
|
print(_("Your Gtk version does not meet the requirements.\n"
|
||||||
"At least %(major)d.%(minor)d "
|
"At least %(major)d.%(minor)d "
|
||||||
"is needed to start Gramps with a GUI.\n\n"
|
"is needed to start Gramps with a GUI.\n\n"
|
||||||
"Gramps will terminate now.") %
|
"Gramps will terminate now."
|
||||||
{ 'major' : MIN_GTK_VERSION[0],
|
) % {'major' : MIN_GTK_VERSION[0],
|
||||||
'minor' : MIN_GTK_VERSION[1] } )
|
'minor' : MIN_GTK_VERSION[1]})
|
||||||
sys.exit(0)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import cairo
|
import cairo
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print((_("\ncairo python support not installed. Install cairo for your "
|
print((_("\ncairo python support not installed. "
|
||||||
"version of python\n\n"
|
"Install cairo for your version of python\n\n"
|
||||||
"Gramps will terminate now.")))
|
"Gramps will terminate now.")))
|
||||||
sys.exit(0)
|
sys.exit(1)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -143,13 +145,12 @@ def _display_welcome_message(parent=None):
|
|||||||
"%(bold_start)sBACKUP%(bold_end)s "
|
"%(bold_start)sBACKUP%(bold_end)s "
|
||||||
"your existing databases before opening "
|
"your existing databases before opening "
|
||||||
"them with this version, and make sure to export your "
|
"them with this version, and make sure to export your "
|
||||||
"data to XML every now and then.")
|
"data to XML every now and then."
|
||||||
% { 'bold_start' : '<b>',
|
) % {'bold_start' : '<b>',
|
||||||
'bold_end' : '</b>' },
|
'bold_end' : '</b>'},
|
||||||
parent=parent)
|
parent=parent)
|
||||||
config.set('behavior.autoload', False)
|
config.set('behavior.autoload', False)
|
||||||
config.set('behavior.betawarn', True)
|
config.set('behavior.betawarn', True)
|
||||||
config.set('behavior.betawarn', config.get('behavior.betawarn'))
|
|
||||||
|
|
||||||
def _display_gtk_gettext_message(parent=None):
|
def _display_gtk_gettext_message(parent=None):
|
||||||
"""
|
"""
|
||||||
@ -195,7 +196,6 @@ class Gramps:
|
|||||||
from .viewmanager import ViewManager
|
from .viewmanager import ViewManager
|
||||||
from gramps.cli.arghandler import ArgHandler
|
from gramps.cli.arghandler import ArgHandler
|
||||||
from .tipofday import TipOfDay
|
from .tipofday import TipOfDay
|
||||||
from .dialog import WarningDialog
|
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
# Append image directory to the theme search path
|
# Append image directory to the theme search path
|
||||||
@ -203,50 +203,50 @@ class Gramps:
|
|||||||
theme.append_search_path(IMAGE_DIR)
|
theme.append_search_path(IMAGE_DIR)
|
||||||
|
|
||||||
dbstate = DbState()
|
dbstate = DbState()
|
||||||
self.vm = ViewManager(dbstate,
|
self._vm = ViewManager(dbstate,
|
||||||
config.get("interface.view-categories"))
|
config.get("interface.view-categories"))
|
||||||
|
|
||||||
if (lin()
|
if (lin()
|
||||||
and glocale.lang != 'C'
|
and glocale.lang != 'C'
|
||||||
and not gettext.find(GTK_GETTEXT_DOMAIN)):
|
and not gettext.find(GTK_GETTEXT_DOMAIN)):
|
||||||
_display_gtk_gettext_message(parent=self.vm.window)
|
_display_gtk_gettext_message(parent=self._vm.window)
|
||||||
|
|
||||||
_display_welcome_message(parent=self.vm.window)
|
_display_welcome_message(parent=self._vm.window)
|
||||||
|
|
||||||
self.vm.init_interface()
|
self._vm.init_interface()
|
||||||
|
|
||||||
#act based on the given arguments
|
#act based on the given arguments
|
||||||
ah = ArgHandler(dbstate, argparser, self.vm, self.argerrorfunc,
|
arg_h = ArgHandler(dbstate, argparser, self._vm, self.argerrorfunc,
|
||||||
gui=True)
|
gui=True)
|
||||||
ah.handle_args_gui()
|
arg_h.handle_args_gui()
|
||||||
if ah.open or ah.imp_db_path:
|
if arg_h.open or arg_h.imp_db_path:
|
||||||
# if we opened or imported something, only show the interface
|
# if we opened or imported something, only show the interface
|
||||||
self.vm.post_init_interface(show_manager=False)
|
self._vm.post_init_interface(show_manager=False)
|
||||||
elif config.get('paths.recent-file') and config.get('behavior.autoload'):
|
elif (config.get('paths.recent-file')
|
||||||
|
and config.get('behavior.autoload')):
|
||||||
# if we need to autoload last seen file, do so
|
# if we need to autoload last seen file, do so
|
||||||
filename = config.get('paths.recent-file')
|
filename = config.get('paths.recent-file')
|
||||||
if os.path.isdir(filename) and \
|
if (os.path.isdir(filename)
|
||||||
os.path.isfile(os.path.join(filename, "name.txt")) and \
|
and os.path.isfile(os.path.join(filename, "name.txt"))
|
||||||
ah.check_db(filename):
|
and arg_h.check_db(filename)):
|
||||||
self.vm.post_init_interface(show_manager=False)
|
self._vm.post_init_interface(show_manager=False)
|
||||||
self.vm.open_activate(filename)
|
self._vm.open_activate(filename)
|
||||||
else:
|
else:
|
||||||
self.vm.post_init_interface()
|
self._vm.post_init_interface()
|
||||||
else:
|
else:
|
||||||
# open without fam tree loaded
|
# open without fam tree loaded
|
||||||
self.vm.post_init_interface()
|
self._vm.post_init_interface()
|
||||||
|
|
||||||
if config.get('behavior.use-tips'):
|
if config.get('behavior.use-tips'):
|
||||||
TipOfDay(self.vm.uistate)
|
TipOfDay(self._vm.uistate)
|
||||||
|
|
||||||
def argerrorfunc(self, string):
|
def argerrorfunc(self, string):
|
||||||
""" Show basic errors in argument handling in GUI fashion"""
|
""" Show basic errors in argument handling in GUI fashion"""
|
||||||
from .dialog import ErrorDialog
|
from .dialog import ErrorDialog
|
||||||
parent = None
|
parent = None
|
||||||
if hasattr(self, 'vm'):
|
if hasattr(self, '_vm'):
|
||||||
if hasattr(self.vm, 'uistate'):
|
if hasattr(self._vm, 'window'):
|
||||||
if hasattr(self.vm.uistate, 'window'):
|
parent = self._vm.window
|
||||||
parent = self.vm.uistate.window
|
|
||||||
ErrorDialog(_("Error parsing arguments"), string, parent=parent)
|
ErrorDialog(_("Error parsing arguments"), string, parent=parent)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -277,31 +277,34 @@ def __startgramps(errors, argparser):
|
|||||||
|
|
||||||
# add gui logger
|
# add gui logger
|
||||||
from .logger import RotateHandler, GtkHandler
|
from .logger import RotateHandler, GtkHandler
|
||||||
form = logging.Formatter(fmt="%(relativeCreated)d: %(levelname)s: "
|
form = logging.Formatter(
|
||||||
"%(filename)s: line %(lineno)d: %(message)s")
|
fmt="%(relativeCreated)d: %(levelname)s: "
|
||||||
|
"%(filename)s: line %(lineno)d: %(message)s")
|
||||||
# Create the log handlers
|
# Create the log handlers
|
||||||
rh = RotateHandler(capacity=20)
|
rot_h = RotateHandler(capacity=20)
|
||||||
rh.setFormatter(form)
|
rot_h.setFormatter(form)
|
||||||
# Only error and critical log records should
|
# Only error and critical log records should
|
||||||
# trigger the GUI handler.
|
# trigger the GUI handler.
|
||||||
gtkh = GtkHandler(rotate_handler=rh)
|
gtkh = GtkHandler(rotate_handler=rot_h)
|
||||||
gtkh.setFormatter(form)
|
gtkh.setFormatter(form)
|
||||||
gtkh.setLevel(logging.ERROR)
|
gtkh.setLevel(logging.ERROR)
|
||||||
l = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
l.addHandler(rh)
|
logger.addHandler(rot_h)
|
||||||
l.addHandler(gtkh)
|
logger.addHandler(gtkh)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
#make sure there is a clean exit if there is an error in above steps
|
#make sure there is a clean exit if there is an error in above steps
|
||||||
quit_now = True
|
quit_now = True
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
LOG.error(_(
|
LOG.error(_("\nGramps failed to start. "
|
||||||
"\nGramps failed to start. Please report a bug about this.\n"
|
"Please report a bug about this.\n"
|
||||||
"This could be because of an error in a (third party) View on startup.\n"
|
"This could be because of an error "
|
||||||
"To use another view, don't load a Family Tree, change view, and then load"
|
"in a (third party) View on startup.\n"
|
||||||
" your Family Tree.\n"
|
"To use another view, don't load a Family Tree, "
|
||||||
"You can also change manually the startup view in the gramps.ini file \n"
|
"change view, and then load your Family Tree.\n"
|
||||||
"by changing the last-view parameter.\n"
|
"You can also change manually "
|
||||||
|
"the startup view in the gramps.ini file \n"
|
||||||
|
"by changing the last-view parameter.\n"
|
||||||
), exc_info=True)
|
), exc_info=True)
|
||||||
|
|
||||||
# start Gramps, errors stop the gtk loop
|
# start Gramps, errors stop the gtk loop
|
||||||
@ -314,32 +317,34 @@ def __startgramps(errors, argparser):
|
|||||||
print("Gramps terminated because of no DISPLAY")
|
print("Gramps terminated because of no DISPLAY")
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
|
||||||
except SystemExit as e:
|
except SystemExit as err:
|
||||||
quit_now = True
|
quit_now = True
|
||||||
if e.code:
|
if err.code:
|
||||||
exit_code = e.code
|
exit_code = err.code
|
||||||
LOG.error("Gramps terminated with exit code: %d." \
|
LOG.error("Gramps terminated with exit code: %d.", err.code,
|
||||||
% e.code, exc_info=True)
|
exc_info=True)
|
||||||
except OSError as e:
|
except OSError as err:
|
||||||
quit_now = True
|
quit_now = True
|
||||||
exit_code = e.errno or 1
|
exit_code = err.errno or 1
|
||||||
try:
|
try:
|
||||||
fn = e.filename
|
fname = err.filename
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
fn = ""
|
fname = ""
|
||||||
LOG.error("Gramps terminated because of OS Error\n" +
|
LOG.error("Gramps terminated because of OS Error\n" +
|
||||||
"Error details: %s %s" % (repr(e), fn), exc_info=True)
|
"Error details: %s %s", repr(err), fname, exc_info=True)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
quit_now = True
|
quit_now = True
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
LOG.error(_(
|
LOG.error(_("\nGramps failed to start. "
|
||||||
"\nGramps failed to start. Please report a bug about this.\n"
|
"Please report a bug about this.\n"
|
||||||
"This could be because of an error in a (third party) View on startup.\n"
|
"This could be because of an error "
|
||||||
"To use another view, don't load a Family Tree, change view, and then load"
|
"in a (third party) View on startup.\n"
|
||||||
" your Family Tree.\n"
|
"To use another view, don't load a Family Tree, "
|
||||||
"You can also change manually the startup view in the gramps.ini file \n"
|
"change view, and then load your Family Tree.\n"
|
||||||
"by changing the last-view parameter.\n"
|
"You can also change manually "
|
||||||
|
"the startup view in the gramps.ini file \n"
|
||||||
|
"by changing the last-view parameter.\n"
|
||||||
), exc_info=True)
|
), exc_info=True)
|
||||||
|
|
||||||
if quit_now:
|
if quit_now:
|
||||||
@ -351,7 +356,8 @@ def __startgramps(errors, argparser):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def startgtkloop(errors, argparser):
|
def startgtkloop(errors, argparser):
|
||||||
""" We start the gtk loop and run the function to start up Gramps
|
"""
|
||||||
|
We start the gtk loop and run the function to start up Gramps
|
||||||
"""
|
"""
|
||||||
GLib.timeout_add(100, __startgramps, errors, argparser, priority=100)
|
GLib.timeout_add(100, __startgramps, errors, argparser, priority=100)
|
||||||
if os.path.exists(os.path.join(DATA_DIR, "gramps.accel")):
|
if os.path.exists(os.path.join(DATA_DIR, "gramps.accel")):
|
||||||
|
Loading…
Reference in New Issue
Block a user