From 6c04f8b151f5396cb313d9297e9e8b33ab0b0d3f Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Fri, 28 Jun 2013 12:49:31 +0000 Subject: [PATCH] GEP18: add deprecated decorator to gramps, use in src and citation Usage: python -W all Gramps.py svn: r22622 --- gramps/gen/constfunc.py | 30 ++++++++++++++++++++++++++++++ gramps/gen/lib/citation.py | 3 ++- gramps/gen/lib/src.py | 7 ++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/gramps/gen/constfunc.py b/gramps/gen/constfunc.py index 08b851f05..c3c768d2f 100644 --- a/gramps/gen/constfunc.py +++ b/gramps/gen/constfunc.py @@ -35,6 +35,14 @@ perform a translation on import, eg Gtk. import platform import sys +#------------------------------------------------------------------------- +# +# set up logging +# +#------------------------------------------------------------------------- +import warnings +import functools + #------------------------------------------------------------------------- # # Platforms @@ -159,3 +167,25 @@ def mod_key(): return "" return "" + +#------------------------------------------------------------------------- +# +# DECORATORS +# +#------------------------------------------------------------------------- + +def deprecated(func): + '''This is a decorator which can be used to mark functions + as deprecated. It will result in a warning being emitted + when the function is used.''' + + @functools.wraps(func) + def new_func(*args, **kwargs): + warnings.warn_explicit( + "Call to deprecated function {}.".format(func.__name__), + category=DeprecationWarning, + filename=func.func_code.co_filename, + lineno=func.func_code.co_firstlineno + 1 + ) + return func(*args, **kwargs) + return new_func diff --git a/gramps/gen/lib/citation.py b/gramps/gen/lib/citation.py index 5c6ad323c..52f0e3cda 100644 --- a/gramps/gen/lib/citation.py +++ b/gramps/gen/lib/citation.py @@ -45,7 +45,7 @@ from .notebase import NoteBase from .datebase import DateBase from .tagbase import TagBase from .srcattrbase import SrcAttributeBase -from ..constfunc import cuni +from ..constfunc import cuni, deprecated from .handle import Handle #------------------------------------------------------------------------- @@ -288,6 +288,7 @@ class Citation(MediaBase, NoteBase, SrcAttributeBase, PrimaryObject, DateBase): """Set the page indicator of the Citation.""" self.page = page + @deprecated def get_page(self): """Get the page indicator of the Citation.""" return self.page diff --git a/gramps/gen/lib/src.py b/gramps/gen/lib/src.py index 2bd478439..1e02bccfa 100644 --- a/gramps/gen/lib/src.py +++ b/gramps/gen/lib/src.py @@ -39,7 +39,7 @@ from .srcattrbase import SrcAttributeBase from .srctemplate import SrcTemplate from .reporef import RepoRef from .const import DIFFERENT, EQUAL, IDENTICAL -from ..constfunc import cuni +from ..constfunc import cuni, deprecated from .handle import Handle #------------------------------------------------------------------------- @@ -273,6 +273,7 @@ class Source(MediaBase, NoteBase, SrcAttributeBase, PrimaryObject): """ self.title = title + @deprecated def get_title(self): """ Return the descriptive title of the Place object. @@ -286,6 +287,7 @@ class Source(MediaBase, NoteBase, SrcAttributeBase, PrimaryObject): ## """Set the author of the Source.""" ## self.author = author + @deprecated def get_author(self): """Return the author of the Source. Author depends on the source template. The logic is: @@ -302,6 +304,7 @@ class Source(MediaBase, NoteBase, SrcAttributeBase, PrimaryObject): ## """Set the publication information of the Source.""" ## self.pubinfo = text + @deprecated def get_publication_info(self): """Return the publication information of the Source. PubInfo depends on the source template. The logic is: @@ -318,8 +321,10 @@ class Source(MediaBase, NoteBase, SrcAttributeBase, PrimaryObject): """Set the title abbreviation of the Source.""" self.abbrev = abbrev + @deprecated def get_abbreviation(self): """Return the title abbreviation of the Source.""" + print 'test' return self.abbrev def add_repo_reference(self, repo_ref):