Merge pull request #182 from prculley/logwarn

fix LOG.warn() deprecation warning
This commit is contained in:
Paul Franklin 2016-06-29 18:54:37 +00:00 committed by GitHub
commit 1abc0ad1fa
14 changed files with 58 additions and 53 deletions

View File

@ -335,7 +335,7 @@ class Gramplet:
return False return False
except Exception as e: except Exception as e:
import traceback import traceback
LOG.warn("Gramplet gave an error: %s" % self.gui.title) LOG.warning("Gramplet gave an error: %s" % self.gui.title)
traceback.print_exc() traceback.print_exc()
print("Continuing after gramplet error...") print("Continuing after gramplet error...")
self._idle_id = 0 self._idle_id = 0

View File

@ -530,8 +530,8 @@ class GrampsLocale:
os.path.exists(os.path.abspath(_first.localedir))): os.path.exists(os.path.abspath(_first.localedir))):
self.localedir = _first.localedir self.localedir = _first.localedir
else: else:
LOG.warn('Missing or invalid localedir %s; no translations will be available.', repr(localedir)) LOG.warning('Missing or invalid localedir %s; no translations'
' will be available.', repr(localedir))
self.lang = lang self.lang = lang
self.localedomain = domain or 'gramps' self.localedomain = domain or 'gramps'
if languages: if languages:
@ -864,7 +864,7 @@ class GrampsLocale:
try: try:
key = locale.strxfrm(string) key = locale.strxfrm(string)
except Exception as err: except Exception as err:
LOG.warn("Failed to obtain key for %s because %s", LOG.warning("Failed to obtain key for %s because %s",
self.collation, str(err)) self.collation, str(err))
return string return string
return key return key

View File

@ -217,7 +217,7 @@ def __create_thumbnail_image(src_file, mtype=None, rectangle=None,
pixbuf.savev(filename, "png", "", "") pixbuf.savev(filename, "png", "", "")
return True return True
except Exception as err: except Exception as err:
LOG.warn("Error scaling image down: %s", str(err)) LOG.warning("Error scaling image down: %s", str(err))
return False return False
#------------------------------------------------------------------------- #-------------------------------------------------------------------------

View File

@ -75,21 +75,21 @@ def EditObject(dbstate, uistate, track, obj_class, prop=None, value=None, callba
try: try:
EDITORS[obj_class](dbstate, uistate, track, obj, callback=callback) EDITORS[obj_class](dbstate, uistate, track, obj, callback=callback)
except Exception as msg: except Exception as msg:
LOG.warn(str(msg)) LOG.warning(str(msg))
elif prop in ("gramps_id", "handle"): elif prop in ("gramps_id", "handle"):
obj = dbstate.db.get_table_metadata(obj_class)[prop + "_func"](value) obj = dbstate.db.get_table_metadata(obj_class)[prop + "_func"](value)
if obj: if obj:
try: try:
EDITORS[obj_class](dbstate, uistate, track, obj, callback=callback) EDITORS[obj_class](dbstate, uistate, track, obj, callback=callback)
except Exception as msg: except Exception as msg:
LOG.warn(str(msg)) LOG.warning(str(msg))
else: else:
LOG.warn("gramps://%s/%s/%s not found" % LOG.warning("gramps://%s/%s/%s not found" %
(obj_class, prop, value)) (obj_class, prop, value))
else: else:
LOG.warn("unknown property to edit '%s'; " LOG.warning("unknown property to edit '%s'; "
"should be 'gramps_id' or 'handle'" % prop) "should be 'gramps_id' or 'handle'" % prop)
else: else:
LOG.warn("unknown object to edit '%s'; " LOG.warning("unknown object to edit '%s'; "
"should be one of %s" % (obj_class, list(EDITORS.keys()))) "should be one of %s" % (obj_class, list(EDITORS.keys())))

View File

@ -852,13 +852,13 @@ class EditFamily(EditPrimary):
self.obj.set_father_handle(person.get_handle()) self.obj.set_father_handle(person.get_handle())
self.update_father(person.get_handle()) self.update_father(person.get_handle())
except: except:
log.warn("Failed to update father: \n" log.warning("Failed to update father: \n"
"obj returned from selector was: %s\n" "obj returned from selector was: %s\n"
% (repr(obj),)) % (repr(obj),))
raise raise
else: else:
log.warn( log.warning(
"Object selector returned obj.__class__ = %s, it should " "Object selector returned obj.__class__ = %s, it should "
"have been of type %s." % (obj.__class__.__name__, "have been of type %s." % (obj.__class__.__name__,
Person.__name__)) Person.__name__))

View File

@ -179,7 +179,8 @@ class Gramps:
theme.append_search_path(IMAGE_DIR) theme.append_search_path(IMAGE_DIR)
if lin() and glocale.lang != 'C' and not gettext.find(GTK_GETTEXT_DOMAIN): if lin() and glocale.lang != 'C' and not gettext.find(GTK_GETTEXT_DOMAIN):
LOG.warn("GTK translations missing, GUI will be broken, especially for RTL languages!") LOG.warning("GTK translations missing, GUI will be broken, "
"especially for RTL languages!")
# Note: the warning dialog below will likely have wrong stock icons! # Note: the warning dialog below will likely have wrong stock icons!
# Translators: the current language will be the one you translate into. # Translators: the current language will be the one you translate into.
WarningDialog( WarningDialog(

View File

@ -146,9 +146,12 @@ class Spell:
# the language does not exist # the language does not exist
# and presumably if there is no dictionary # and presumably if there is no dictionary
if not self.gtkspell_spell.get_language_list(): if not self.gtkspell_spell.get_language_list():
LOG.warn(_("You have no installed dictionaries. Either install one or disable spell checking")) LOG.warning(_("You have no installed dictionaries. "
"Either install one or disable spell "
"checking"))
else: else:
LOG.warn(_("Spelling checker initialization failed: %s"), err) LOG.warning(_("Spelling checker initialization "
"failed: %s"), err)
else: else:
if spellcheck_code == 'on': if spellcheck_code == 'on':
return return

View File

@ -936,7 +936,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.warn("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())

View File

@ -135,7 +135,7 @@ def get_gramplet_opts(name, opts):
my_data.update(opts) my_data.update(opts)
return my_data return my_data
else: else:
LOG.warn("Unknown gramplet name: '%s'", name) LOG.warning("Unknown gramplet name: '%s'", name)
return {} return {}
def get_gramplet_options_by_name(name): def get_gramplet_options_by_name(name):
@ -145,7 +145,7 @@ def get_gramplet_options_by_name(name):
if name in AVAILABLE_GRAMPLETS(): if name in AVAILABLE_GRAMPLETS():
return GET_AVAILABLE_GRAMPLETS(name).copy() return GET_AVAILABLE_GRAMPLETS(name).copy()
else: else:
LOG.warn("Unknown gramplet name: '%s'", name) LOG.warning("Unknown gramplet name: '%s'", name)
return None return None
def get_gramplet_options_by_tname(name): def get_gramplet_options_by_tname(name):
@ -155,7 +155,7 @@ def get_gramplet_options_by_tname(name):
for key in AVAILABLE_GRAMPLETS(): for key in AVAILABLE_GRAMPLETS():
if GET_AVAILABLE_GRAMPLETS(key)["tname"] == name: if GET_AVAILABLE_GRAMPLETS(key)["tname"] == name:
return GET_AVAILABLE_GRAMPLETS(key).copy() return GET_AVAILABLE_GRAMPLETS(key).copy()
LOG.warn("Unknown gramplet name: '%s'",name) LOG.warning("Unknown gramplet name: '%s'",name)
return None return None
def make_requested_gramplet(gui_class, pane, opts, dbstate, uistate): def make_requested_gramplet(gui_class, pane, opts, dbstate, uistate):
@ -175,11 +175,11 @@ def make_requested_gramplet(gui_class, pane, opts, dbstate, uistate):
if module: if module:
getattr(module, opts["content"])(gui) getattr(module, opts["content"])(gui)
else: else:
LOG.warn("Error loading gramplet '%s': skipping content", LOG.warning("Error loading gramplet '%s': "
name) "skipping content", name)
return gui return gui
else: else:
LOG.warn("Error loading gramplet: unknown name") LOG.warning("Error loading gramplet: unknown name")
return None return None
def logical_true(value): def logical_true(value):
@ -515,7 +515,8 @@ class GuiGramplet:
url = attributes["wiki"] url = attributes["wiki"]
self.link_region(start, stop, "WIKI", url) # tooltip? self.link_region(start, stop, "WIKI", url) # tooltip?
else: else:
LOG.warn("warning: no url on link: '%s'", text[start, stop]) LOG.warning("warning: no url on link: '%s'",
text[start, stop])
def link_region(self, start, stop, link_type, url): def link_region(self, start, stop, link_type, url):
link_data = (LinkTag(self.buffer), link_type, url, url) link_data = (LinkTag(self.buffer), link_type, url, url)
@ -1057,7 +1058,7 @@ class GrampletPane(Gtk.ScrolledWindow):
self.gramplet_map[unique] = g self.gramplet_map[unique] = g
self.frame_map[str(g.mainframe)] = g self.frame_map[str(g.mainframe)] = g
else: else:
LOG.warn("Can't make gramplet of type '%s'.", name) LOG.warning("Can't make gramplet of type '%s'.", name)
self.place_gramplets() self.place_gramplets()
def show_all(self): def show_all(self):
@ -1259,7 +1260,7 @@ class GrampletPane(Gtk.ScrolledWindow):
fp.write("%s=%s\n\n" % (key, base_opts[key])) fp.write("%s=%s\n\n" % (key, base_opts[key]))
except IOError as err: except IOError as err:
LOG.warn("Failed to open %s because $s; gramplets not saved", LOG.warning("Failed to open %s because $s; gramplets not saved",
filename, str(err)) filename, str(err))
return return
@ -1363,7 +1364,7 @@ class GrampletPane(Gtk.ScrolledWindow):
self.gramplet_map[opts["title"]] = g self.gramplet_map[opts["title"]] = g
self.frame_map[str(g.mainframe)] = g self.frame_map[str(g.mainframe)] = g
else: else:
LOG.warn("Can't make gramplet of type '%s'.", name) LOG.warning("Can't make gramplet of type '%s'.", name)
if g: if g:
gramplet = g gramplet = g
gramplet.gstate = "maximized" gramplet.gstate = "maximized"
@ -1387,8 +1388,8 @@ class GrampletPane(Gtk.ScrolledWindow):
all_opts = get_gramplet_options_by_tname(tname) all_opts = get_gramplet_options_by_tname(tname)
name = all_opts["name"] name = all_opts["name"]
if all_opts is None: if all_opts is None:
LOG.warn("Unknown gramplet type: '%s'; bad gramplets.ini file?", LOG.warning("Unknown gramplet type: '%s'; bad "
name) "gramplets.ini file?", name)
return return
if "title" not in all_opts: if "title" not in all_opts:
all_opts["title"] = "Untitled Gramplet" all_opts["title"] = "Untitled Gramplet"
@ -1424,7 +1425,7 @@ class GrampletPane(Gtk.ScrolledWindow):
gramplet.pui.active = True gramplet.pui.active = True
gramplet.pui.update() gramplet.pui.update()
else: else:
LOG.warn("Can't make gramplet of type '%s'.", name) LOG.warning("Can't make gramplet of type '%s'.", name)
def _button_press(self, obj, event): def _button_press(self, obj, event):
if is_right_click(event): if is_right_click(event):

View File

@ -175,7 +175,7 @@ class PackageWriter:
try: try:
archive = tarfile.open(self.filename,'w:gz') archive = tarfile.open(self.filename,'w:gz')
except EnvironmentError as msg: except EnvironmentError as msg:
log.warn(str(msg)) LOG.warning(str(msg))
self.user.notify_error(_('Failure writing %s') % self.filename, str(msg)) self.user.notify_error(_('Failure writing %s') % self.filename, str(msg))
return 0 return 0

View File

@ -166,7 +166,7 @@ class GrampsXmlWriter(UpdateCallback):
else: else:
g = open(filename,"wb") g = open(filename,"wb")
except IOError as msg: except IOError as msg:
LOG.warn(str(msg)) LOG.warning(str(msg))
raise DbWriteFailure(_('Failure writing %s') % filename, raise DbWriteFailure(_('Failure writing %s') % filename,
str(msg)) str(msg))
return 0 return 0

View File

@ -88,7 +88,7 @@ def rd(line_number, row, col, key, default = None):
""" Return Row data by column name """ """ Return Row data by column name """
if key in col: if key in col:
if col[key] >= len(row): if col[key] >= len(row):
LOG.warn("missing '%s, on line %d" % (key, line_number)) LOG.warning("missing '%s, on line %d" % (key, line_number))
return default return default
retval = row[col[key]].strip() retval = row[col[key]].strip()
if retval == "": if retval == "":
@ -302,7 +302,7 @@ class CSVParser:
else: else:
return None return None
else: else:
LOG.warn("invalid lookup type in CSV import: '%s'" % type_) LOG.warning("invalid lookup type in CSV import: '%s'" % type_)
return None return None
def storeup(self, type_, id_, object_): def storeup(self, type_, id_, object_):
@ -320,7 +320,7 @@ class CSVParser:
id_ = self.db.pid2user_format(id_) id_ = self.db.pid2user_format(id_)
self.placeref[id_.lower()] = object_ self.placeref[id_.lower()] = object_
else: else:
LOG.warn("invalid storeup type in CSV import: '%s'" % type_) LOG.warning("invalid storeup type in CSV import: '%s'" % type_)
def parse(self, filehandle): def parse(self, filehandle):
""" """
@ -391,7 +391,7 @@ class CSVParser:
elif "place" in header: elif "place" in header:
self._parse_place(line_number, row, col) self._parse_place(line_number, row, col)
else: else:
LOG.warn("ignoring line %d" % line_number) LOG.warning("ignoring line %d" % line_number)
return None return None
def _parse_marriage(self, line_number, row, col): def _parse_marriage(self, line_number, row, col):
@ -408,8 +408,8 @@ class CSVParser:
husband = self.lookup("person", husband) husband = self.lookup("person", husband)
if husband is None and wife is None: if husband is None and wife is None:
# might have children, so go ahead and add # might have children, so go ahead and add
LOG.warn("no parents on line %d; adding family anyway" % LOG.warning("no parents on line %d; adding family anyway" %
line_number) line_number)
family = self.get_or_create_family(marriage_ref, husband, wife) family = self.get_or_create_family(marriage_ref, husband, wife)
# adjust gender, if not already provided # adjust gender, if not already provided
if husband: if husband:
@ -479,8 +479,8 @@ class CSVParser:
"Parse the content of a family line" "Parse the content of a family line"
family_ref = rd(line_number, row, col, "family") family_ref = rd(line_number, row, col, "family")
if family_ref is None: if family_ref is None:
LOG.warn("no family reference found for family on line %d" % LOG.warning("no family reference found for family on line %d" %
line_number) line_number)
return # required return # required
child = rd(line_number, row, col, "child") child = rd(line_number, row, col, "child")
source = rd(line_number, row, col, "source") source = rd(line_number, row, col, "source")
@ -489,12 +489,12 @@ class CSVParser:
child = self.lookup("person", child) child = self.lookup("person", child)
family = self.lookup("family", family_ref) family = self.lookup("family", family_ref)
if family is None: if family is None:
LOG.warn("no matching family reference found for family " LOG.warning("no matching family reference found for family "
"on line %d" % line_number) "on line %d" % line_number)
return return
if child is None: if child is None:
LOG.warn("no matching child reference found for family " LOG.warning("no matching child reference found for family "
"on line %d" % line_number) "on line %d" % line_number)
return return
# is this child already in this family? If so, don't add # is this child already in this family? If so, don't add
LOG.debug("children: %s", [ref.ref for ref in LOG.debug("children: %s", [ref.ref for ref in
@ -586,8 +586,8 @@ class CSVParser:
person = self.lookup("person", person_ref) person = self.lookup("person", person_ref)
if person is None: if person is None:
if surname is None: if surname is None:
LOG.warn("empty surname for new person on line %d" % LOG.warning("empty surname for new person on line %d" %
line_number) line_number)
surname = "" surname = ""
# new person # new person
person = self.create_person() person = self.create_person()

View File

@ -750,8 +750,8 @@ class GrampsParser(UpdateCallback):
self.import_handles[orig_handle][target][INSTANTIATED] = True self.import_handles[orig_handle][target][INSTANTIATED] = True
return handle return handle
elif handle in self.import_handles: elif handle in self.import_handles:
LOG.warn("The file you import contains duplicate handles " LOG.warning("The file you import contains duplicate handles "
"which is illegal and being fixed now.") "which is illegal and being fixed now.")
handle = create_id() handle = create_id()
while handle in self.import_handles: while handle in self.import_handles:
handle = create_id() handle = create_id()
@ -3205,7 +3205,7 @@ class GrampsParser(UpdateCallback):
{'family' : family.gramps_id, {'family' : family.gramps_id,
'father' : father.gramps_id}) 'father' : father.gramps_id})
self.info.add('unlinked-family', txt, None) self.info.add('unlinked-family', txt, None)
LOG.warn(txt) LOG.warning(txt)
if mother_handle: if mother_handle:
mother = self.db.get_person_from_handle(mother_handle) mother = self.db.get_person_from_handle(mother_handle)
@ -3221,7 +3221,7 @@ class GrampsParser(UpdateCallback):
{'family' : family.gramps_id, {'family' : family.gramps_id,
'mother' : mother.gramps_id}) 'mother' : mother.gramps_id})
self.info.add('unlinked-family', txt, None) self.info.add('unlinked-family', txt, None)
LOG.warn(txt) LOG.warning(txt)
for child_ref in family.get_child_ref_list(): for child_ref in family.get_child_ref_list():
child_handle = child_ref.ref child_handle = child_ref.ref
@ -3243,7 +3243,7 @@ class GrampsParser(UpdateCallback):
{'family' : family.gramps_id, {'family' : family.gramps_id,
'child' : child.gramps_id}) 'child' : child.gramps_id})
self.info.add('unlinked-family', txt, None) self.info.add('unlinked-family', txt, None)
LOG.warn(txt) LOG.warning(txt)
def append_value(orig, val): def append_value(orig, val):
if orig: if orig:

View File

@ -1394,7 +1394,7 @@ class CairoDoc(BaseDoc, TextDoc, DrawDoc):
elif fe[-1] != self.EXT: elif fe[-1] != self.EXT:
# NOTE: the warning will be bogus # NOTE: the warning will be bogus
# if the EXT isn't properly overridden by derived class # if the EXT isn't properly overridden by derived class
log.warn(_( LOG.warning(_(
"""Mismatch between selected extension %(ext)s and actual format. """Mismatch between selected extension %(ext)s and actual format.
Writing to %(filename)s in format %(impliedext)s.""") % Writing to %(filename)s in format %(impliedext)s.""") %
{'ext' : fe[-1], {'ext' : fe[-1],