Skip to content

Instantly share code, notes, and snippets.

@mcomisso
Created March 13, 2016 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcomisso/41c4b85334c19022da2f to your computer and use it in GitHub Desktop.
Save mcomisso/41c4b85334c19022da2f to your computer and use it in GitHub Desktop.
Example of classes with dynamically selectors in python
class Http_Server(object):
environment = {}
def __init__(self, env):
self.environment = env
print self.environment
# Dynamically fetch the environments variables for the operating system
self.os = getattr(__import__('enheritage'), self.environment.get('os', 'Debian'))
def reload(self):
raise NotImplementedError
def restart(self):
raise NotImplementedError
def graceful(self):
raise NotImplementedError
def create_directories(self):
raise NotImplementedError
class Apache(Http_Server):
def restart(self):
pass
def reload(self):
pass
def graceful(self):
pass
class Nginx(Http_Server):
def restart(self):
pass
def reload(self):
pass
def graceful(self):
pass
class Environments(object):
def __init__(self, configuration):
self.executablePath = configuration.get('exec', '')
class Debian(Environments):
current_name='ubuntu_12.04'
pass
class RedHat(Environments):
current_name='RH_1010'
pass
if __name__ == '__main__':
environ = {'test': 'test', 'os': 'Debian'}
apache = Apache(environ)
print apache.os.current_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment