Source code for

"""Video recording library

Configuration for this module + fixture:
.. code-block:: yaml

          enabled: True
          dir: video
          display: ":99"
          quality: 10

import os
import subprocess
from signal import SIGINT

from cfme.utils.conf import env
# from utils.log import logger

vid_options = env.get('logging', {}).get('video')

[docs]def process_running(pid): """Check whether specified process is running""" try: os.kill(pid, 0) except OSError as e: if e.errno == 3: return False else: raise else: return True
[docs]class Recorder(object): """Recorder class Usage: with Recorder(filename): # do something # or r = Recorder(filename) r.start() # do something r.stop() The first way is preferred, obviously """ def __init__(self, filename, display=None, quality=None): self.filename = filename self.display = display or vid_options["display"] self.quality = quality or vid_options["quality"] = None
[docs] def start(self): cmd_line = ['recordmydesktop', '--display', str(self.display), '-o', str(self.filename), '--no-sound', '--v_quality', str(self.quality), '--on-the-fly-encoding', '--overwrite'] try: proc = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE) = except OSError: # Had to disable for artifactor # logger.exception("Couldn't initialize videoer! Is recordmydesktop installed?") pass
[docs] def stop(self): if is not None: if process_running( os.kill(, SIGINT) os.waitpid(, 0) # Had to disable for artifactor #"Recording finished") = None else: # Had to disable for artifactor # logger.exception("Could not find recordmydesktop process #%d" % pass
def __enter__(self): self.start() def __exit__(self, t, v, tb): self.stop() def __del__(self): """If the reference is lost and the object is destroyed ...""" self.stop()