/src/lib/Server/Plugins/Cvs.py

https://github.com/ab/bcfg2-old · Python · 47 lines · 34 code · 8 blank · 5 comment · 4 complexity · 8441086600cf6ae83ac727c58e189c57 MD5 · raw file

  1. import os
  2. from subprocess import Popen, PIPE
  3. import Bcfg2.Server.Plugin
  4. # for debugging output only
  5. import logging
  6. logger = logging.getLogger('Bcfg2.Plugins.Cvs')
  7. class Cvs(Bcfg2.Server.Plugin.Plugin,
  8. Bcfg2.Server.Plugin.Version):
  9. """CVS is a version plugin for dealing with Bcfg2 repository."""
  10. name = 'Cvs'
  11. __version__ = '$Id$'
  12. __author__ = 'bcfg-dev@mcs.anl.gov'
  13. experimental = True
  14. def __init__(self, core, datastore):
  15. Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
  16. self.core = core
  17. self.datastore = datastore
  18. # path to cvs directory for Bcfg2 repo
  19. cvs_dir = "%s/CVSROOT" % datastore
  20. # Read revision from Bcfg2 repo
  21. if os.path.isdir(cvs_dir):
  22. self.get_revision()
  23. else:
  24. logger.error("%s is not a directory" % cvs_dir)
  25. raise Bcfg2.Server.Plugin.PluginInitError
  26. logger.debug("Initialized cvs plugin with cvs directory = %s" % cvs_dir)
  27. def get_revision(self):
  28. """Read cvs revision information for the Bcfg2 repository."""
  29. try:
  30. data = Popen("env LC_ALL=C cvs log",
  31. shell=True,
  32. cwd=self.datastore,
  33. stdout=PIPE).stdout.readlines()
  34. revision = data[3].strip('\n')
  35. except IndexError:
  36. logger.error("Failed to read cvs log; disabling cvs support")
  37. logger.error('''Ran command "cvs log %s"''' % (self.datastore))
  38. logger.error("Got output: %s" % data)
  39. raise Bcfg2.Server.Plugin.PluginInitError