From c6e8251faf2bac768e026a53cd413df5906899ba Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 9 Jan 2013 11:20:30 -0500 Subject: [PATCH] version: Add get_versions and teach rss2email --full-version This makes it easier for users to submit useful bug reports. Signed-off-by: W. Trevor King --- rss2email/main.py | 11 +++++++++++ rss2email/version.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 rss2email/version.py diff --git a/rss2email/main.py b/rss2email/main.py index 47817fe..3c8dc1c 100644 --- a/rss2email/main.py +++ b/rss2email/main.py @@ -11,6 +11,14 @@ from . import LOG as _LOG from . import command as _command from . import error as _error from . import feeds as _feeds +from . import version as _version + + +class FullVersionAction (_argparse.Action): + def __call__(self, *args, **kwargs): + for package,version in _version.get_versions(): + print('{} {}'.format(package, version)) + _sys.exit(0) def run(*args, **kwargs): @@ -25,6 +33,9 @@ def run(*args, **kwargs): parser.add_argument( '-v', '--version', action='version', version='%(prog)s {}'.format(__version__)) + parser.add_argument( + '--full-version', action=FullVersionAction, nargs=0, + help='print the version information of all related packages and exit') parser.add_argument( '-c', '--config', metavar='PATH', default=[], action='append', help='path to the configuration file') diff --git a/rss2email/version.py b/rss2email/version.py new file mode 100644 index 0000000..65e8b5d --- /dev/null +++ b/rss2email/version.py @@ -0,0 +1,35 @@ +# Copyright + +"""Calculate version numbers for this package and its dependencies + +This makes it easier for users to submit useful bug reports. +""" + +import importlib as _importlib +import sys as _sys + +from . import __version__ + + +def get_rss2email_version(package): + return __version__ + +def get_python_version(package): + return _sys.version + +def get_python_package_version(package): + try: + module = _importlib.import_module(package) + except ImportError as e: + return None + return getattr(module, '__version__', 'unknown') + +def get_versions(packages=None): + if not packages: + packages = ['rss2email', 'python', 'feedparser', 'html2text'] + for package in packages: + get = globals().get( + 'get_{}_version'.format(package), + get_python_package_version) + version = get(package=package) + yield (package, version) -- 2.26.2