~ubuntu-branches/ubuntu/trusty/cinder/trusty

« back to all changes in this revision

Viewing changes to cinder/openstack/common/version.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Yolanda Robla Mota, James Page, Chuck Short
  • Date: 2013-02-22 10:45:17 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20130222104517-ng3r6ace9vi4m869
Tags: 2013.1.g3-0ubuntu1
[ Yolanda Robla Mota ]
* d/control: Add BD on python-hp3parclient.
* d/patches: Drop patches related to disabling hp3parclient.

[ James Page ]
* d/control: Add Suggests: python-hp3parclient for python-cinder.
* d/control: Add BD on python-oslo-config.
* d/*: Wrapped and sorted.

[ Chuck Short ]
* New upstream release.
* debian/rules, debian/cinder-volumes.install: 
  - Fail if binaries are missing and install missing binaries.
* debian/patches/fix-ubuntu-tests.patch: Fix failing tests.
* debian/control: Add python-rtslib and python-mock.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#    Copyright 2012 OpenStack LLC
 
3
#    Copyright 2012-2013 Hewlett-Packard Development Company, L.P.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
#    Unless required by applicable law or agreed to in writing, software
 
12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
"""
 
18
Utilities for consuming the version from pkg_resources.
 
19
"""
 
20
 
 
21
import pkg_resources
 
22
 
 
23
 
 
24
class VersionInfo(object):
 
25
 
 
26
    def __init__(self, package):
 
27
        """Object that understands versioning for a package
 
28
        :param package: name of the python package, such as glance, or
 
29
                        python-glanceclient
 
30
        """
 
31
        self.package = package
 
32
        self.release = None
 
33
        self.version = None
 
34
        self._cached_version = None
 
35
 
 
36
    def _get_version_from_pkg_resources(self):
 
37
        """Get the version of the package from the pkg_resources record
 
38
        associated with the package."""
 
39
        try:
 
40
            requirement = pkg_resources.Requirement.parse(self.package)
 
41
            provider = pkg_resources.get_provider(requirement)
 
42
            return provider.version
 
43
        except pkg_resources.DistributionNotFound:
 
44
            # The most likely cause for this is running tests in a tree with
 
45
            # produced from a tarball where the package itself has not been
 
46
            # installed into anything. Check for a PKG-INFO file.
 
47
            from cinder.openstack.common import setup
 
48
            return setup.get_version_from_pkg_info(self.package)
 
49
 
 
50
    def release_string(self):
 
51
        """Return the full version of the package including suffixes indicating
 
52
        VCS status.
 
53
        """
 
54
        if self.release is None:
 
55
            self.release = self._get_version_from_pkg_resources()
 
56
 
 
57
        return self.release
 
58
 
 
59
    def version_string(self):
 
60
        """Return the short version minus any alpha/beta tags."""
 
61
        if self.version is None:
 
62
            parts = []
 
63
            for part in self.release_string().split('.'):
 
64
                if part[0].isdigit():
 
65
                    parts.append(part)
 
66
                else:
 
67
                    break
 
68
            self.version = ".".join(parts)
 
69
 
 
70
        return self.version
 
71
 
 
72
    # Compatibility functions
 
73
    canonical_version_string = version_string
 
74
    version_string_with_vcs = release_string
 
75
 
 
76
    def cached_version_string(self, prefix=""):
 
77
        """Generate an object which will expand in a string context to
 
78
        the results of version_string(). We do this so that don't
 
79
        call into pkg_resources every time we start up a program when
 
80
        passing version information into the CONF constructor, but
 
81
        rather only do the calculation when and if a version is requested
 
82
        """
 
83
        if not self._cached_version:
 
84
            self._cached_version = "%s%s" % (prefix,
 
85
                                             self.version_string())
 
86
        return self._cached_version