Commit c96f2c96 by Michael DeHaan

Merge branch 'nigelm_freebsd' of git://github.com/nigelm/ansible into merge-service

Make things more reusable, correct some errors along the SSH key path

Conflicts:
	library/user
parents 49ad8631 cdfa81d9
......@@ -53,6 +53,7 @@ import stat
import stat
import grp
import pwd
import platform
HAVE_SELINUX=False
try:
......@@ -84,6 +85,47 @@ FILE_COMMON_ARGUMENTS=dict(
setype = dict(),
)
def get_platform():
''' what's the platform? example: Linux is a platform. '''
return platform.system()
def get_distribution():
''' return the distribution name '''
if platform.system() == 'Linux':
try:
distribution = platform.linux_distribution()[0].capitalize
except:
# FIXME: MethodMissing, I assume?
distribution = platform.dist()[0].capitalize
else:
distribution = None
return distribution
def load_platform_subclass(cls, *args, **kwargs):
'''
used by modules like User to have different implementations based on detected platform. See User
module for an example.
'''
this_platform = get_platform()
distribution = get_distribution()
subclass = None
# get the most specific superclass for this platform
if distribution is not None:
for sc in cls.__subclasses__():
if sc.distribution is not None and sc.distribution == distribution and sc.platform == this_platform:
subclass = sc
if subclass is None:
for sc in cls.__subclasses__():
if sc.platform == this_platform and sc.distribution is None:
subclass = sc
if subclass is None:
subclass = cls
return super(cls, subclass).__new__(subclass, *args, **kwargs)
class AnsibleModule(object):
def __init__(self, argument_spec, bypass_checks=False, no_log=False,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment