diff options
author | Rick Harris <rconradharris@gmail.com> | 2012-08-24 18:01:30 +0000 |
---|---|---|
committer | Rick Harris <rconradharris@gmail.com> | 2012-08-24 19:17:46 +0000 |
commit | b54330bfd255faaec6edae8b99053269a13607d3 (patch) | |
tree | 448c0f69fa6cefa867a1341d6453ab7398d1d9bf | |
parent | 8ccd9059d62a96815c25f6a5ea3510322bc599e6 (diff) | |
download | python-novaclient-b54330bfd255faaec6edae8b99053269a13607d3.tar.gz |
Adding --version option
Change-Id: I7d37af1ddee186af22457baea9af71a955720053
-rw-r--r-- | novaclient/__init__.py | 20 | ||||
-rw-r--r-- | novaclient/shell.py | 5 | ||||
-rw-r--r-- | setup.py | 3 |
3 files changed, 27 insertions, 1 deletions
diff --git a/novaclient/__init__.py b/novaclient/__init__.py index ec3ff60e..fa6b8e59 100644 --- a/novaclient/__init__.py +++ b/novaclient/__init__.py @@ -11,3 +11,23 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import inspect +import os + + +def _get_novaclient_version(): + """Read version from versioninfo file.""" + mod_abspath = inspect.getabsfile(inspect.currentframe()) + novaclient_path = os.path.dirname(mod_abspath) + version_path = os.path.join(novaclient_path, 'versioninfo') + + if os.path.exists(version_path): + version = open(version_path).read().strip() + else: + version = "Unknown, couldn't find versioninfo file at %s"\ + % version_path + + return version + + +__version__ = _get_novaclient_version() diff --git a/novaclient/shell.py b/novaclient/shell.py index c0ea2022..3d56b944 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -28,6 +28,7 @@ import pkgutil import sys import logging +import novaclient from novaclient import client from novaclient import exceptions as exc import novaclient.extension @@ -81,6 +82,10 @@ class OpenStackComputeShell(object): help=argparse.SUPPRESS, ) + parser.add_argument('--version', + action='version', + version=novaclient.__version__) + parser.add_argument('--debug', default=False, action='store_true', @@ -47,5 +47,6 @@ setuptools.setup( ], entry_points={ "console_scripts": ["nova = novaclient.shell:main"] - } + }, + data_files=[('novaclient', ['novaclient/versioninfo'])] ) |