Skip to content

Commit

Permalink
fix retry when take screenshot, update readthedocs
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Feb 18, 2020
1 parent 4328a7c commit 8f5fdd3
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 40 deletions.
23 changes: 0 additions & 23 deletions .readthedocs.yml

This file was deleted.

4 changes: 2 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
Expand Down
8 changes: 8 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
API
----------

.. autoclass:: uiautomator2.Device
:members:

.. autoclass:: uiautomator2.Session
:members:
16 changes: 11 additions & 5 deletions docs/source/conf.py → docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath('..'))

import uiautomator2


# -- Project information -----------------------------------------------------
Expand All @@ -27,24 +29,28 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ["sphinx.ext.autodoc"]
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
#html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
7 changes: 2 additions & 5 deletions docs/source/index.rst → docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.. uiautomator2 documentation master file, created by
sphinx-quickstart on Tue Feb 18 09:46:00 2020.
sphinx-quickstart on Tue Feb 18 15:32:23 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Expand All @@ -10,11 +10,8 @@ Welcome to uiautomator2's documentation!
:maxdepth: 2
:caption: Contents:

.. automodule:: uiautomator2.Device
:members:
api

.. automodule:: uiautomator2.Session
:members:

Indices and tables
==================
Expand Down
1 change: 0 additions & 1 deletion docs/requirements.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 7 additions & 4 deletions uiautomator2/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def drag(self, sx, sy, ex, ey, duration=0.5):
return self.jsonrpc.drag(sx, sy, ex, ey, int(duration * 200))

@retry((IOError, SyntaxError), delay=.5, tries=5, jitter=0.1,
max_delay=1) # delay .5, .6, .7, .8 ...
max_delay=1, logger=logging) # delay .5, .6, .7, .8 ...
def screenshot(self, filename=None, format='pillow'):
"""
Image format is JPEG
Expand All @@ -492,9 +492,12 @@ def screenshot(self, filename=None, format='pillow'):
f.write(r.content)
return filename
elif format == 'pillow':
from PIL import Image
buff = io.BytesIO(r.content)
return Image.open(buff).convert("RGB")
try:
from PIL import Image
buff = io.BytesIO(r.content)
return Image.open(buff).convert("RGB")
except Exception as ex:
raise IOError("PIL.Image.open IOError", ex)
elif format == 'opencv':
import cv2
import numpy as np
Expand Down

0 comments on commit 8f5fdd3

Please sign in to comment.