Commit 7753ee03 authored by Elger Jonker's avatar Elger Jonker

robustness increase in screenshots

parent 25957d50
......@@ -17,6 +17,7 @@ import logging
import os
import platform
import re
import subprocess
from datetime import datetime
import pytz
......@@ -31,8 +32,6 @@ logger = logging.getLogger(__package__)
# todo: wait:, FFX 57
# todo: how to instruct the environment that there is a chrome present.
chrome = settings.TOOLS['chrome']['executable'][platform.system()]
firefox = settings.TOOLS['firefox']['executable'][platform.system()]
# deprecated
working_directory = '../map/static/images/screenshots' # deprecated
......@@ -67,7 +66,8 @@ def screenshot_endpoint(endpoint):
# filed bug:
def screenshot_with_firefox(endpoint, skip_if_latest=False):
import subprocess
if not check_installation('firefox'):
now = str("_%Y%m%d_%H%M%S_%f"))
screenshot_image = settings.TOOLS['firefox']['screenshot_output_dir'] + \
......@@ -87,7 +87,7 @@ def screenshot_with_firefox(endpoint, skip_if_latest=False):
logger.debug("Skipped making screenshot, by request")
......@@ -132,7 +132,8 @@ def thumbnail(image_path, output_path):
# todo: what about directories? directory = application_endpoint?
def screenshot_with_chrome(endpoint, skip_if_latest=False):
import subprocess
if not check_installation('chrome'):
now = str("_%Y%m%d_%H%M%S_%f"))
logger.debug("Chrome Headless : Making screenshot: %s, on %s" % (endpoint.uri_url(), now))
......@@ -165,7 +166,7 @@ def screenshot_with_chrome(endpoint, skip_if_latest=False):
# timeout doesn't work, it just blocks the process and hangs it.['mkdir', tmp_dir])['cd', tmp_dir])[chrome,[settings.TOOLS['chrome']['executable'][platform.system()],
......@@ -184,6 +185,25 @@ def screenshot_with_chrome(endpoint, skip_if_latest=False):'Made screenshot of: %s' % endpoint.uri_url())
def check_installation(browser):
browser_binary = settings.TOOLS[browser]['executable'][platform.system()]
except KeyError:
logger.error("Not possible to read configuration setting: TOOLS[browser]['executable'][platform].")
logger.error("Platform can be Darwin, Unix. Browser can be chrome or firefox.")
return False
if not browser_binary:
logger.error('%s is not available for %s, please update the configuration with the correct binary.'
% (browser, platform.system()))
return False
if not os.path.exists(browser_binary):
logger.error('Supplied browser does not exist in configured path: %s' % browser_binary)
return False
return True
# delivers transparent / empty pages all the time.
# also looks to be clogging the cybers.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment