PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/silversupport/abstractservice.py

https://bitbucket.org/ianb/silverlining/
Python | 79 lines | 42 code | 13 blank | 24 comment | 4 complexity | 6951083b3d368a663d252e732f6a42d3 MD5 | raw file
Possible License(s): GPL-2.0
  1. from silversupport.shell import apt_install
  2. class AbstractService(object):
  3. name = None
  4. # Any deb packages that need to be installed:
  5. packages = []
  6. # This should be like {'python': ['python-mydb']}
  7. # Packages that depend on the python/php platform
  8. platform_packages = {}
  9. def __init__(self, app_config, config_string, devel=False,
  10. devel_config=None, output=None):
  11. self.app_config = app_config
  12. self.config_string = config_string
  13. self.devel = devel
  14. self.devel_config = devel_config
  15. if output:
  16. self.output = output
  17. else:
  18. self.output = self.stdout_output
  19. self.env = self.env_setup()
  20. def __repr__(self):
  21. return '<%s.%s for %r>' % (
  22. self.__class__.__module__, self.__class__.__name__,
  23. self.app_config)
  24. def stdout_output(self, msg):
  25. print msg
  26. def install(self):
  27. """Installs everything for this service. This may have to
  28. install packages, configure the service, and probably has to
  29. setup a database for the application."""
  30. raise NotImplementedError
  31. def install_packages(self):
  32. """Install any (deb) packages needed for this service.
  33. This will read the class variables packages and
  34. platform_packages by default.
  35. Implementations of ``.install()`` should probably call this
  36. method."""
  37. packages = (self.packages +
  38. self.platform_packages.get(self.app_config.platform, []))
  39. apt_install(packages)
  40. def env_setup(self):
  41. """Returns an environment dictionary of any variables that
  42. should be set"""
  43. raise NotImplementedError
  44. def backup(self, output_dir):
  45. """Backs up this database into a directory"""
  46. raise NotImplementedError
  47. def restore(self, input_dir):
  48. """Restores this database from the given backup (unpacked)"""
  49. raise NotImplementedError
  50. def clear(self):
  51. """Clears the database"""
  52. raise NotImplementedError
  53. def check_setup(self):
  54. """This runs a check on the service, especially for use in
  55. development.
  56. For instance, you could connect to a database to make sure it
  57. is setup and available.
  58. This should raise an exception if there's a serious problem,
  59. or return a string warning if it's a suspected or non-fatal
  60. problem.
  61. """
  62. pass