Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhs-shine committed Oct 11, 2016
2 parents 29581b1 + cba67eb commit 4ca01d7
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ Version 0.3.1 22 Sep 2016
Version 0.3.2 07 Oct 2016
---------------------------
- Support artik and more standalone device types

Version 0.3.3 11 Oct 2016
---------------------------
- Support device.screenshot() API
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Buliding & installing

$ cd ..

$ sudo dpkg -i litmus_0.3.1-1_amd64.deb
$ sudo dpkg -i litmus_0.3.3-1_amd64.deb


Getting started
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
litmus (0.3.3-1) unstable; urgency=low

* Support device.screenshot API

-- Donghoon Shin <[email protected]> Tue, 11 Oct 2016 12:41:00 +0900

litmus (0.3.2-1) unstable; urgency=low

* Support artik and more standalone device types
Expand Down
2 changes: 2 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ Depends: ${python3:Depends}, ${misc:Depends},
python3-yaml (>= 3.10),
python3-requests (>= 2.2.1),
python3-bs4 (>= 4.2.1),
python3-pil (>= 2.3.0),
python3-fasteners (>= 0.12),
git (>= 1.9),
lthor (>= 2.0),
imagemagick (>= 6.7.7),
clewarecontrol (>= 4.1),
smartpower (>= 0.1),
heimdall-flash (>= 1.4.1-2),
Expand Down
2 changes: 1 addition & 1 deletion litmus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
import os

__version__ = '0.3.2'
__version__ = '0.3.3'
_homedir_ = os.path.expanduser('~')
_confdir_ = os.path.join(_homedir_, '.litmus')
_duts_ = os.path.join(_confdir_, 'topology')
Expand Down
83 changes: 83 additions & 0 deletions litmus/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import time
import serial
import logging
import tempfile
import fasteners
from PIL import Image
from threading import Thread, Lock
from litmus.core.util import call, check_output
from litmus.core.util import convert_single_item_to_list
Expand Down Expand Up @@ -52,6 +54,8 @@ class device(object):
_max_attempt_boot_retry = 3
_boot_timeout = 50.0
_path_for_locks = _path_for_locks_
_screen_width = 1920
_screen_height = 1080

_cutter = None
_uart = None
Expand Down Expand Up @@ -349,7 +353,86 @@ def run_tests(self):
elif isinstance(l['args'], tuple):
l['func'](self, *l['args'])

def screenshot(self, filename):
"""
Take a screenshot (png format)
:param str filename: screenshot file name
Example:
>>> dut.screenshot('screenshot.png')
"""
logging.debug('==== Take a screenshot: {}, width: {}, height: {} ===='
.format(filename,
self._screen_width,
self._screen_height))
dt = self._get_display_server_type()
if dt == 'X11':
self._screenshot_x11(filename)
elif dt == 'WAYLAND':
self._screenshot_wayland(filename)

# private methods.
def _get_display_server_type(self):
"""docstring for get_display_server_type"""
res = self.run_cmd('ls /usr/lib', timeout=10)
if find_pattern('.*libX11.*', res):
return 'X11'
else:
return 'WAYLAND'

def _screenshot_x11(self, filename):
"""docstring for _screenshot_x11"""
# take a screenshot using xwd
cmd = 'xwd -root -out /tmp/{}.xwd'.format(filename)
self.run_cmd(cmd, timeout=20)

# pull xwd file
self.pull_file('/tmp/{}.xwd'.format(filename), os.curdir, timeout=20)

# convert xwd to png and resize it
call(['convert', '{0}.xwd'.format(filename), '-resize',
'{0}x{1}'.format(self._screen_width, self._screen_height),
filename], timeout=20)
call(['rm', '{}.xwd'.format(filename)], timeout=20)

def _screenshot_wayland(self, filename):
"""docstring for _screenshot_wayland"""
# Find all viewable window id
p_winid = '.*(0x[a-zA-Z0-9]{8})\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)\s+(\d+).*\sViewable.*'
winids = find_all_pattern(p_winid,
self.run_cmd('enlightenment_info -topvwins',
timeout=20))
if winids:
# Dump windows
outs = self.run_cmd('enlightenment_info -dump_topvwins',
timeout=20)
dirn = find_pattern('directory:\s(.*)',
outs,
groupindex=1).rstrip()

# Create tempdir and pull dump files
tmpdir = tempfile.mkdtemp()
self.pull_file(dirn, tmpdir, timeout=20)

# If dump does not exist then remove winid from list
winids = [winid for winid in winids
if os.path.exists(os.path.join(tmpdir, winid[0]+'.png'))]

# Base image
bg = Image.new('RGB', (self._screen_width, self._screen_height))
# Merge images
for winid in reversed(winids):
try:
fg = Image.open(os.path.join(tmpdir, winid[0]+'.png'))
bg.paste(fg, (int(winid[1]), int(winid[2])), fg)
except FileNotFoundError:
pass
# Save merged image
bg.save(filename)
# Remove tempdir
call(['rm', '-rf', tmpdir], timeout=10)

def _flush_uart_buffer(self):
"""docstring for flush_uart_buffer"""
Expand Down
2 changes: 2 additions & 0 deletions litmus/device/deviceartik5.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
class deviceartik5(deviceartik10):
"""docstring for device"""
_pattern_bootprompt = r'ARITK.*# .*'
_screen_width = 480
_screen_height = 800
4 changes: 2 additions & 2 deletions litmus/device/devicestandalone_m0.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

class devicestandalone_m0(devicestandalone):
"""docstring for device"""
pass

_screen_width = 720
_screen_height = 1280
4 changes: 2 additions & 2 deletions litmus/device/devicestandalone_tm1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

class devicestandalone_tm1(devicestandalone):
"""docstring for device"""
pass

_screen_width = 720
_screen_height = 1280
4 changes: 2 additions & 2 deletions litmus/device/devicestandalone_tm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

class devicestandalone_tm2(devicestandalone):
"""docstring for device"""
pass

_screen_width = 1440
_screen_height = 2560
4 changes: 2 additions & 2 deletions litmus/device/devicestandalone_tw1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

class devicestandalone_tw1(devicestandalone):
"""docstring for device"""
pass

_screen_width = 360
_screen_height = 360
1 change: 0 additions & 1 deletion litmus/device/devicestandalone_u3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
class devicestandalone_u3(devicestandalone):
"""docstring for device"""
pass

1 change: 0 additions & 1 deletion litmus/device/devicestandalone_xu3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
class devicestandalone_xu3(devicestandalone):
"""docstring for device"""
pass

4 changes: 2 additions & 2 deletions litmus/device/devicestandalone_z1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

class devicestandalone_z1(devicestandalone):
"""docstring for device"""
pass

_screen_width = 480
_screen_height = 800
1 change: 0 additions & 1 deletion litmus/device/deviceu3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
class deviceu3(device):
"""docstring for device"""
pass

2 changes: 0 additions & 2 deletions litmus/helper/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import time
import logging
import requests
import litmus
import urllib.parse
from bs4 import BeautifulSoup
from litmus.core.util import find_pattern, find_all_pattern
Expand Down Expand Up @@ -173,7 +172,6 @@ def install_plugin(dut, script, waiting=5, timeout=180):
dut.off()


import os
import tempfile
import shutil
from subprocess import DEVNULL
Expand Down

0 comments on commit 4ca01d7

Please sign in to comment.