~felipe-alfaro-gmail/charms/xenial/neutron-api/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/osplatform.py

  • Committer: Felipe Alfaro Solana
  • Date: 2017-04-05 19:45:40 UTC
  • Revision ID: felipe.alfaro@gmail.com-20170405194540-85i0nhnp98ipob0y
Neutron API charm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import platform
 
2
 
 
3
 
 
4
def get_platform():
 
5
    """Return the current OS platform.
 
6
 
 
7
    For example: if current os platform is Ubuntu then a string "ubuntu"
 
8
    will be returned (which is the name of the module).
 
9
    This string is used to decide which platform module should be imported.
 
10
    """
 
11
    # linux_distribution is deprecated and will be removed in Python 3.7
 
12
    # Warings *not* disabled, as we certainly need to fix this.
 
13
    tuple_platform = platform.linux_distribution()
 
14
    current_platform = tuple_platform[0]
 
15
    if "Ubuntu" in current_platform:
 
16
        return "ubuntu"
 
17
    elif "CentOS" in current_platform:
 
18
        return "centos"
 
19
    elif "debian" in current_platform:
 
20
        # Stock Python does not detect Ubuntu and instead returns debian.
 
21
        # Or at least it does in some build environments like Travis CI
 
22
        return "ubuntu"
 
23
    else:
 
24
        raise RuntimeError("This module is not supported on {}."
 
25
                           .format(current_platform))