pylint improvements

This commit is contained in:
Nick Hall
2016-05-27 23:53:08 +01:00
parent 75ffd7c41b
commit ab50490617

View File

@ -38,32 +38,33 @@ import time
from urllib.parse import urlparse from urllib.parse import urlparse
from urllib.request import urlopen, url2pathname from urllib.request import urlopen, url2pathname
import tempfile import tempfile
#-------------------------------------------------------------------------
#
# set up logging
#
#-------------------------------------------------------------------------
import logging import logging
LOG = logging.getLogger(".clidbman")
from gramps.gen.db.dbconst import DBLOGNAME
_LOG = logging.getLogger(DBLOGNAME)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from gramps.gen.plug import BasePluginManager from gramps.gen.plug import BasePluginManager
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.constfunc import win from gramps.gen.constfunc import win
from gramps.gen.db.dbconst import DBLOGNAME
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
#-------------------------------------------------------------------------
#
# set up logging
#
#-------------------------------------------------------------------------
LOG = logging.getLogger(".clidbman")
_LOG = logging.getLogger(DBLOGNAME)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# constants # constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
DEFAULT_TITLE = _("Family Tree") DEFAULT_TITLE = _("Family Tree")
NAME_FILE = "name.txt" NAME_FILE = "name.txt"
META_NAME = "meta_data.db" META_NAME = "meta_data.db"
@ -98,7 +99,7 @@ class CLIDbManager:
IND_TVAL_STR = 3 IND_TVAL_STR = 3
IND_TVAL = 4 IND_TVAL = 4
IND_USE_ICON_BOOL = 5 IND_USE_ICON_BOOL = 5
IND_STOCK_ID =6 IND_STOCK_ID = 6
ICON_NONE = 0 ICON_NONE = 0
ICON_RECOVERY = 1 ICON_RECOVERY = 1
@ -194,7 +195,7 @@ class CLIDbManager:
# translators: needed for French, ignore otherwise # translators: needed for French, ignore otherwise
print(_(" %(item)s: %(summary)s") % { print(_(" %(item)s: %(summary)s") % {
'item' : item, 'item' : item,
'summary' : summary[item] } ) 'summary' : summary[item]})
def family_tree_summary(self, database_names=None): def family_tree_summary(self, database_names=None):
""" """
@ -210,7 +211,7 @@ class CLIDbManager:
dbname == name) dbname == name)
for dbname in database_names])): for dbname in database_names])):
retval = self.get_dbdir_summary(dirpath, name) retval = self.get_dbdir_summary(dirpath, name)
summary_list.append( retval ) summary_list.append(retval)
return summary_list return summary_list
def _populate_cli(self): def _populate_cli(self):
@ -245,10 +246,10 @@ class CLIDbManager:
name = file.readline().strip() name = file.readline().strip()
(tval, last) = time_val(dirpath) (tval, last) = time_val(dirpath)
(enable, stock_id) = self.icon_values(dirpath, self.active, (enable, stock_id) = self.icon_values(
self.dbstate.db.is_open()) dirpath, self.active, self.dbstate.db.is_open())
if (stock_id == 'gramps-lock'): if stock_id == 'gramps-lock':
last = find_locker_name(dirpath) last = find_locker_name(dirpath)
self.current_names.append( self.current_names.append(
@ -296,7 +297,7 @@ class CLIDbManager:
path_name = os.path.join(new_path, NAME_FILE) path_name = os.path.join(new_path, NAME_FILE)
if title is None: if title is None:
name_list = [ name[0] for name in self.current_names ] name_list = [name[0] for name in self.current_names]
title = find_next_db_name(name_list) title = find_next_db_name(name_list)
with open(path_name, "w", encoding='utf8') as name_file: with open(path_name, "w", encoding='utf8') as name_file:
@ -355,9 +356,9 @@ class CLIDbManager:
# write locally: # write locally:
temp_fp.write(data) temp_fp.write(data)
url_fp.close() url_fp.close()
from gen.db.dbconst import BDBVERSFN from gramps.gen.db.dbconst import BDBVERSFN
versionpath = os.path.join(name, BDBVERSFN) versionpath = os.path.join(name, BDBVERSFN)
_LOG.debug("Write bsddb version %s" % str(dbase.version())) _LOG.debug("Write bsddb version %s", str(dbase.version()))
with open(versionpath, "w") as version_file: with open(versionpath, "w") as version_file:
version_file.write(str(dbase.version())) version_file.write(str(dbase.version()))
temp_fp.close() temp_fp.close()
@ -392,7 +393,7 @@ class CLIDbManager:
""" """
Returns True if there is a lock file in the dirpath Returns True if there is a lock file in the dirpath
""" """
if os.path.isfile(os.path.join(dbpath,"lock")): if os.path.isfile(os.path.join(dbpath, "lock")):
return True return True
return False return False
@ -400,7 +401,7 @@ class CLIDbManager:
""" """
Returns True if the database in dirpath needs recovery Returns True if the database in dirpath needs recovery
""" """
if os.path.isfile(os.path.join(dbpath,"need_recover")): if os.path.isfile(os.path.join(dbpath, "need_recover")):
return True return True
return False return False
@ -444,12 +445,11 @@ class CLIDbManager:
""" """
try: try:
with open(filepath, "r", encoding='utf8') as name_file: with open(filepath, "r", encoding='utf8') as name_file:
old_text=name_file.read() old_text = name_file.read()
with open(filepath, "w", encoding='utf8') as name_file: with open(filepath, "w", encoding='utf8') as name_file:
name_file.write(new_text) name_file.write(new_text)
except (OSError, IOError) as msg: except (OSError, IOError) as msg:
CLIDbManager.ERROR(_("Could not rename Family Tree"), CLIDbManager.ERROR(_("Could not rename Family Tree"), str(msg))
str(msg))
return None, None return None, None
return old_text, new_text return old_text, new_text
@ -465,11 +465,11 @@ class CLIDbManager:
If the directory path is the active path, then return values If the directory path is the active path, then return values
that indicate to use the icon, and which icon to use. that indicate to use the icon, and which icon to use.
""" """
if os.path.isfile(os.path.join(dirpath,"need_recover")): if os.path.isfile(os.path.join(dirpath, "need_recover")):
return (True, self.ICON_MAP[self.ICON_RECOVERY]) return (True, self.ICON_MAP[self.ICON_RECOVERY])
elif dirpath == active and is_open: elif dirpath == active and is_open:
return (True, self.ICON_MAP[self.ICON_OPEN]) return (True, self.ICON_MAP[self.ICON_OPEN])
elif os.path.isfile(os.path.join(dirpath,"lock")): elif os.path.isfile(os.path.join(dirpath, "lock")):
return (True, self.ICON_MAP[self.ICON_LOCK]) return (True, self.ICON_MAP[self.ICON_LOCK])
else: else:
return (False, self.ICON_MAP[self.ICON_NONE]) return (False, self.ICON_MAP[self.ICON_NONE])
@ -484,7 +484,8 @@ def make_dbdir(dbdir):
except (IOError, OSError) as msg: except (IOError, OSError) as msg:
LOG.error(_("\nERROR: Wrong database path in Edit Menu->Preferences.\n" LOG.error(_("\nERROR: Wrong database path in Edit Menu->Preferences.\n"
"Open preferences and set correct database path.\n\n" "Open preferences and set correct database path.\n\n"
"Details: Could not make database directory:\n %s\n\n") % msg) "Details: Could not make database directory:\n %s\n\n"),
str(msg))
return False return False
return True return True