-
-
Save knowncitizen/f6385e335fe22d5f5226e00f180a906e to your computer and use it in GitHub Desktop.
A half-baked idea to make it easier to have a repeatable screencast process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright 2016 Red Hat, Inc. | |
| # All Rights Reserved. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may | |
| # not use this file except in compliance with the License. You may obtain | |
| # a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
| # License for the specific language governing permissions and limitations | |
| # under the License. | |
| import signal | |
| import subprocess | |
| from threading import Thread | |
| import time | |
| from selenium import webdriver | |
| from selenium.webdriver.common.keys import Keys | |
| class Camera(object): | |
| def __init__(self, output_file, xPos=None, yPos=None, height=None, | |
| width=None): | |
| self.output_file = output_file | |
| self.recording = False | |
| self.stderr = None | |
| self.stdout = None | |
| recording_args = ['recordmydesktop'] | |
| if xPos: | |
| recording_args.append("-x") | |
| recording_args.append(str(xPos)) | |
| if yPos: | |
| recording_args.append("-y") | |
| recording_args.append(str(yPos)) | |
| if height: | |
| recording_args.append("-height") | |
| recording_args.append(str(height)) | |
| if width: | |
| recording_args.append("-width") | |
| recording_args.append(str(width)) | |
| recording_args.append("-o") | |
| recording_args.append(self.output_file) | |
| self.process = subprocess.Popen( | |
| recording_args, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE | |
| ) | |
| def start_recording(self): | |
| self.stdout, self.stderr = self.process.communicate() | |
| if self.stderr == '': | |
| self.recording = True | |
| def toggle_pause(self): | |
| self.process.send_signal(signal.SIGUSR1) | |
| return self.process.communicate() | |
| def pause_recording(self): | |
| stdout, stderr = self.toggle_pause() | |
| def unpause_recording(self): | |
| stdout, stderr = self.toggle_pause() | |
| def stop_recording(self): | |
| self.process.send_signal(signal.SIGINT) | |
| return self.process.communicate() | |
| class Narrator(object): | |
| def __init__(self, options): | |
| self.options = options | |
| def say(self, text): | |
| initial_pause = self.options.get("initial_pause", 0) | |
| time.sleep(initial_pause) | |
| process = subprocess.Popen(['espeak', '"%s"' % text], | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE) | |
| process.communicate() | |
| class Movie(object): | |
| def __init__(self, camera): | |
| self.camera = camera | |
| def __enter__(self): | |
| cameraman = Thread(target=self.camera.start_recording, args=()) | |
| cameraman.start() | |
| def __exit__(self, type, value, traceback): | |
| self.camera.stop_recording() | |
| pass | |
| class Scene(object): | |
| def __init__(self, script, narrator): | |
| self.script = script | |
| self.narrator = narrator | |
| def __enter__(self): | |
| narration = Thread(target=self.narrator.say, args=(self.script,)) | |
| narration.start() | |
| def __exit__(self, type, value, traceback): | |
| pass | |
| def main(): | |
| # set the stage | |
| browser = webdriver.Firefox() | |
| window_pos = browser.get_window_position() | |
| window_size = browser.get_window_size() | |
| browser.get("http://www.google.com/") | |
| time.sleep(2) | |
| camera = Camera( | |
| 'demo.ogv', | |
| xPos=window_pos.get('x'), | |
| yPos=window_pos.get('y'), | |
| height=window_size.get('height'), | |
| width=window_size.get('width') | |
| ) | |
| narrator = Narrator({}) | |
| with Movie(camera) as movie: | |
| script = ("This is an example demonstration of how to search google to" | |
| " find more information about Triple O.") | |
| with Scene(script, narrator) as scene: | |
| search = browser.find_element_by_name('q') | |
| search.send_keys("openstack on openstack") | |
| search.send_keys(Keys.RETURN) # hit return after you enter search text | |
| time.sleep(10) # sleep for 5 seconds so you can see the results | |
| browser.quit() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment