Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

formatting by autopep8

  • Loading branch information...
commit 0c863c58bbbdf38eb274ee02c3fbd845d747e4e2 1 parent 7bc6c63
ponty authored
View
33 docs/conf.py
@@ -4,6 +4,7 @@
import sphinx
import sys
+
def read_project_version(py=None, where='.', exclude=['bootstrap', 'pavement', 'doc', 'docs', 'test', 'tests', ]):
if not py:
py = path(where) / find_packages(where=where, exclude=exclude)[0]
@@ -23,18 +24,18 @@ def read_project_version(py=None, where='.', exclude=['bootstrap', 'pavement', '
author = 'ponty'
copyright = '2011, ponty'
-#logging.basicConfig(level=logging.DEBUG)
+# logging.basicConfig(level=logging.DEBUG)
# Extension
extensions = [
- # -*-Extensions: -*-
- 'sphinx.ext.autodoc',
- 'sphinxcontrib.programoutput',
- 'sphinxcontrib.programscreenshot',
- 'sphinx.ext.graphviz',
- #'sphinx.ext.autosummary',
- 'sphinx.ext.intersphinx',
- ]
+ # -*-Extensions: -*-
+ 'sphinx.ext.autodoc',
+ 'sphinxcontrib.programoutput',
+ 'sphinxcontrib.programscreenshot',
+ 'sphinx.ext.graphviz',
+ #'sphinx.ext.autosummary',
+ 'sphinx.ext.intersphinx',
+]
intersphinx_mapping = {'http://docs.python.org/': None}
# Source
@@ -54,15 +55,15 @@ def read_project_version(py=None, where='.', exclude=['bootstrap', 'pavement', '
# latex build settings
latex_documents = [
('index', '%s.tex' % project, u'%s Documentation' % project,
- author, 'manual'),
+ author, 'manual'),
]
# remove blank pages from pdf
-# http://groups.google.com/group/sphinx-dev/browse_thread/thread/92e19267d095412d/d60dcba483c6b13d
-latex_font_size = '10pt,oneside'
+# http://groups.google.com/group/sphinx-
+# dev/browse_thread/thread/92e19267d095412d/d60dcba483c6b13d
+latex_font_size = '10pt,oneside'
-latex_elements=dict(
- papersize='a4paper',
- )
-
+latex_elements = dict(
+ papersize='a4paper',
+)
View
39 pavement.py
@@ -14,7 +14,8 @@
from sphinxcontrib import paverutils
# get info from setup.py
-setup_py=''.join([x for x in path('setup.py').lines() if 'setuptools' not in x])
+setup_py = ''.join(
+ [x for x in path('setup.py').lines() if 'setuptools' not in x])
exec(setup_py)
@@ -22,25 +23,25 @@
sphinx=Bunch(
docroot='docs',
builddir="_build",
- ),
+ ),
pdf=Bunch(
builddir='_build',
builder='latex',
),
- )
+)
-options.paved.clean.rmdirs += ['.tox',
- 'dist',
- 'build' ,
- ]
+options.paved.clean.rmdirs += ['.tox',
+ 'dist',
+ 'build',
+ ]
options.paved.clean.patterns += ['*.pickle',
'*.doctree',
- '*.gz' ,
+ '*.gz',
'nosetests.xml',
'sloccount.sc',
'*.pdf', '*.tex',
'*.png',
- '*.zip',
+ '*.zip',
'distribute_setup.py',
]
@@ -51,22 +52,24 @@
@task
@needs(
-# 'clean',
- 'sloccount',
- 'html',
- 'pdf',
- 'sdist',
- 'nose', 'tox',
- )
+ # 'clean',
+ 'sloccount',
+ 'html',
+ 'pdf',
+ 'sdist',
+ 'nose', 'tox',
+)
def alltest():
'all tasks to check'
pass
+
@task
@needs('sphinxcontrib.paverutils.html')
def html():
pass
+
@task
@needs('sphinxcontrib.paverutils.pdf')
def pdf():
@@ -75,16 +78,16 @@ def pdf():
d.makedirs()
fpdf.copy(d)
+
@task
def tox():
'''Run tox.'''
sh('tox')
-
+
@task
@needs('manifest', 'setuptools.command.sdist')
def sdist():
"""Overrides sdist to make sure that our MANIFEST.in is generated.
"""
pass
-
View
45 pyvirtualdisplay/abstractdisplay.py
@@ -14,16 +14,17 @@
random.seed()
MIN_DISPLAY_NR = 1000
-
+
+
class AbstractDisplay(EasyProcess):
'''
Common parent for Xvfb and Xephyr
'''
-
+
@property
def new_display_var(self):
return ':%s' % (self.display)
-
+
@property
def _cmd(self):
raise NotImplementedError()
@@ -34,28 +35,29 @@ def lock_files(self):
# ls = path('/tmp').files('.X*-lock')
# remove path.py dependency
names = fnmatch.filter(os.listdir(tmpdir), pattern)
- ls = [os.path.join(tmpdir , child) for child in names]
+ ls = [os.path.join(tmpdir, child) for child in names]
ls = [p for p in ls if os.path.isfile(p)]
return ls
-
+
def search_for_display(self):
# search for free display
- ls = map(lambda x:int(x.split('X')[1].split('-')[0]), self.lock_files())
+ ls = map(
+ lambda x: int(x.split('X')[1].split('-')[0]), self.lock_files())
if len(ls):
display = max(MIN_DISPLAY_NR, max(ls) + 1)
else:
display = MIN_DISPLAY_NR
-
- if RANDOMIZE_DISPLAY_NR:
- display += random.randint(0, 100)
+
+ if RANDOMIZE_DISPLAY_NR:
+ display += random.randint(0, 100)
return display
-
+
def redirect_display(self, on):
'''
on:
* True -> set $DISPLAY to virtual screen
* False -> set $DISPLAY to original screen
-
+
:param on: bool
'''
d = self.new_display_var if on else self.old_display_var
@@ -65,22 +67,23 @@ def redirect_display(self, on):
def start(self):
'''
start display
-
+
:rtype: self
'''
self.display = self.search_for_display()
EasyProcess.__init__(self, self._cmd)
EasyProcess.start(self)
-
+
# https://github.com/ponty/PyVirtualDisplay/issues/2
- self.old_display_var = os.environ['DISPLAY'] if 'DISPLAY' in os.environ else ':0'
-
+ self.old_display_var = os.environ[
+ 'DISPLAY'] if 'DISPLAY' in os.environ else ':0'
+
self.redirect_display(True)
# wait until X server is active
# TODO: better method
time.sleep(0.1)
return self
-
+
def stop(self):
'''
stop display
@@ -90,13 +93,3 @@ def stop(self):
self.redirect_display(False)
EasyProcess.stop(self)
return self
-
-
-
-
-
-
-
-
-
-
View
35 pyvirtualdisplay/display.py
@@ -7,8 +7,8 @@
class Display(AbstractDisplay):
'''
Common class
-
- :param color_depth: [8, 16, 24, 32]
+
+ :param color_depth: [8, 16, 24, 32]
:param size: screen size (width,height)
:param bgcolor: background color ['black' or 'white']
:param visible: True -> Xephyr, False -> Xvfb
@@ -26,35 +26,32 @@ def __init__(self, backend=None, visible=False, size=(1024, 768), color_depth=24
if not self.backend:
if self.visible:
- self.backend='xephyr'
+ self.backend = 'xephyr'
else:
- self.backend='xvfb'
+ self.backend = 'xvfb'
- self._obj = self.display_class(
- size=size,
- color_depth=color_depth,
- bgcolor=bgcolor,
- **kwargs)
+ self._obj = self.display_class(
+ size=size,
+ color_depth=color_depth,
+ bgcolor=bgcolor,
+ **kwargs)
-
@property
def display_class(self):
assert self.backend
- if self.backend=='xvfb':
+ if self.backend == 'xvfb':
cls = XvfbDisplay
- if self.backend=='xvnc':
+ if self.backend == 'xvnc':
cls = XvncDisplay
- if self.backend=='xephyr':
+ if self.backend == 'xephyr':
cls = XephyrDisplay
-
+
# TODO: check only once
cls.check_installed()
-
+
return cls
-
+
@property
def _cmd(self):
- self._obj.display=self.display
+ self._obj.display = self.display
return self._obj._cmd
-
-
View
3  pyvirtualdisplay/examples/lowres.py
@@ -1,6 +1,5 @@
from easyprocess import EasyProcess
from pyvirtualdisplay import Display
-
+
Display(visible=1, size=(320, 240)).start()
EasyProcess('gnumeric').start()
-
View
1  pyvirtualdisplay/examples/screenshot1.py
@@ -7,4 +7,3 @@
xmessage.stop()
disp.stop()
img.show()
-
View
1  pyvirtualdisplay/examples/vncserver.py
@@ -6,6 +6,7 @@
from entrypoint2 import entrypoint
from pyvirtualdisplay.display import Display
+
@entrypoint
def main(rfbport=5904):
with Display(backend='xvnc', rfbport=rfbport) as disp:
View
31 pyvirtualdisplay/smartdisplay.py
@@ -18,9 +18,10 @@ class DisplayTimeoutError(Exception):
class SmartDisplay(Display):
pyscreenshot_backend = None
+
def autocrop(self, im):
'''Crop borders off an image.
-
+
:param im: Source image.
:param bgcolor: Background color, using either a color tuple or a color name (1.1.4 only).
:return: An image without borders, or None if there's no actual content in the image.
@@ -37,7 +38,8 @@ def autocrop(self, im):
def grab(self, autocrop=True):
try:
# first try newer pyscreenshot version
- img = pyscreenshot.grab(childprocess=1, backend=self.pyscreenshot_backend)
+ img = pyscreenshot.grab(
+ childprocess=1, backend=self.pyscreenshot_backend)
except TypeError:
# try older pyscreenshot version
img = pyscreenshot.grab()
@@ -48,14 +50,14 @@ def grab(self, autocrop=True):
def waitgrab(self, timeout=60, autocrop=True, cb_imgcheck=None):
'''start process and create screenshot.
- Repeat screenshot until it is not empty and
- cb_imgcheck callback function returns True
+ Repeat screenshot until it is not empty and
+ cb_imgcheck callback function returns True
for current screenshot.
-
- :param autocrop: True -> crop screenshot
- :param timeout: int
- :param cb_imgcheck: None or callback for testing img,
- True = accept img,
+
+ :param autocrop: True -> crop screenshot
+ :param timeout: int
+ :param cb_imgcheck: None or callback for testing img,
+ True = accept img,
False = reject img
'''
t = 0
@@ -83,14 +85,3 @@ def waitgrab(self, timeout=60, autocrop=True, cb_imgcheck=None):
# if not img:
# log.debug('screenshot is empty!')
return img
-
-
-
-
-
-
-
-
-
-
-
View
17 pyvirtualdisplay/xephyr.py
@@ -5,10 +5,11 @@
URL = None
PACKAGE = 'xephyr'
+
class XephyrDisplay(AbstractDisplay):
'''
Xephyr wrapper
-
+
Xephyr is an X server outputting to a window on a pre-existing X display
'''
def __init__(self, size=(1024, 768), color_depth=24, bgcolor='black'):
@@ -24,15 +25,15 @@ def __init__(self, size=(1024, 768), color_depth=24, bgcolor='black'):
@classmethod
def check_installed(cls):
- EasyProcess([PROGRAM, '-help'], url=URL, ubuntu_package=PACKAGE).check_installed()
+ EasyProcess([PROGRAM, '-help'], url=URL,
+ ubuntu_package=PACKAGE).check_installed()
@property
def _cmd(self):
- cmd = [PROGRAM ,
+ cmd = [PROGRAM,
dict(black='-br', white='-wr')[self.bgcolor],
- '-screen',
- 'x'.join(map(str, list(self.size) + [self.color_depth])),
- self.new_display_var,
- ]
+ '-screen',
+ 'x'.join(map(str, list(self.size) + [self.color_depth])),
+ self.new_display_var,
+ ]
return cmd
-
View
26 pyvirtualdisplay/xvfb.py
@@ -12,7 +12,7 @@
class XvfbDisplay(AbstractDisplay):
'''
Xvfb wrapper
-
+
Xvfb is an X server that can run on machines with no display
hardware and no physical input devices. It emulates a dumb
framebuffer using virtual memory.
@@ -27,23 +27,19 @@ def __init__(self, size=(1024, 768), color_depth=24, bgcolor='black'):
self.process = None
self.bgcolor = bgcolor
self.display = None
-
+
@classmethod
def check_installed(cls):
- EasyProcess([PROGRAM, '-help'], url=URL, ubuntu_package=PACKAGE).check_installed()
-
+ EasyProcess([PROGRAM, '-help'], url=URL,
+ ubuntu_package=PACKAGE).check_installed()
+
@property
def _cmd(self):
- cmd = [PROGRAM ,
+ cmd = [PROGRAM,
dict(black='-br', white='-wr')[self.bgcolor],
- '-screen',
- str(self.screen),
- 'x'.join(map(str, list(self.size) + [self.color_depth])),
- self.new_display_var,
- ]
+ '-screen',
+ str(self.screen),
+ 'x'.join(map(str, list(self.size) + [self.color_depth])),
+ self.new_display_var,
+ ]
return cmd
-
-
-
-
-
View
31 pyvirtualdisplay/xvnc.py
@@ -8,6 +8,7 @@
URL = None
PACKAGE = 'tightvncserver'
+
class XvncDisplay(AbstractDisplay):
'''
Xvnc wrapper
@@ -15,7 +16,7 @@ class XvncDisplay(AbstractDisplay):
def __init__(self, size=(1024, 768), color_depth=24, bgcolor='black', rfbport=5900):
'''
:param bgcolor: 'black' or 'white'
- :param rfbport: Specifies the TCP port on which Xvnc listens for connections from viewers (the protocol used in VNC is called RFB - "remote framebuffer"). The default is 5900 plus the display number.
+ :param rfbport: Specifies the TCP port on which Xvnc listens for connections from viewers (the protocol used in VNC is called RFB - "remote framebuffer"). The default is 5900 plus the display number.
'''
self.screen = 0
self.size = size
@@ -24,24 +25,20 @@ def __init__(self, size=(1024, 768), color_depth=24, bgcolor='black', rfbport=59
self.bgcolor = bgcolor
self.display = None
self.rfbport = rfbport
-
+
@classmethod
def check_installed(cls):
- EasyProcess([PROGRAM, '-help'], url=URL, ubuntu_package=PACKAGE).check_installed()
-
+ EasyProcess([PROGRAM, '-help'], url=URL,
+ ubuntu_package=PACKAGE).check_installed()
+
@property
def _cmd(self):
- cmd = [PROGRAM ,
-# dict(black='-br', white='-wr')[self.bgcolor],
-# '-screen',
-# str(self.screen),
-# 'x'.join(map(str, list(self.size) + [self.color_depth])),
- '-rfbport', self.rfbport,
- self.new_display_var,
- ]
+ cmd = [PROGRAM,
+ # dict(black='-br', white='-wr')[self.bgcolor],
+ # '-screen',
+ # str(self.screen),
+ # 'x'.join(map(str, list(self.size) + [self.color_depth])),
+ '-rfbport', self.rfbport,
+ self.new_display_var,
+ ]
return cmd
-
-
-
-
-
View
14 setup.py
@@ -4,7 +4,7 @@
def read_project_version(package):
- py = os.path.join(package , '__init__.py')
+ py = os.path.join(package, '__init__.py')
__version__ = None
for line in open(py).read().splitlines():
if '__version__' in line:
@@ -12,7 +12,7 @@ def read_project_version(package):
break
return __version__
-PACKAGE='pyvirtualdisplay'
+PACKAGE = 'pyvirtualdisplay'
NAME = 'PyVirtualDisplay'
URL = 'https://github.com/ponty/PyVirtualDisplay'
DESCRIPTION = 'python wrapper for Xvfb, Xephyr and Xvnc'
@@ -23,12 +23,13 @@ def read_project_version(package):
extra['use_2to3'] = True
classifiers = [
- # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+ # Get more strings from
+ # http://www.python.org/pypi?%3Aaction=list_classifiers
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
- ]
+]
install_requires = open("requirements.txt").read().split('\n')
@@ -41,7 +42,7 @@ def read_project_version(package):
classifiers=classifiers,
keywords='Xvfb Xephyr X wrapper',
author='ponty',
- #author_email='',
+ # author_email='',
url=URL,
license='BSD',
packages=find_packages(exclude=['bootstrap', 'pavement', ]),
@@ -50,5 +51,4 @@ def read_project_version(package):
zip_safe=False,
install_requires=install_requires,
**extra
- )
-
+)
View
7 tests/slowgui.py
@@ -1,9 +1,10 @@
from easyprocess import EasyProcess
import time
+
def main():
time.sleep(5)
EasyProcess('zenity --question').start()
-
-if __name__=="__main__":
- main()
+
+if __name__ == "__main__":
+ main()
View
13 tests/test_core.py
@@ -3,23 +3,24 @@
from unittest import TestCase
import sys
+
class Test(TestCase):
def test_virt(self):
vd = Display().start().stop()
# self.assertEquals(vd.return_code, 0)
ok_(not vd.is_alive())
-
+
def test_nest(self):
vd = Display().start()
ok_(vd.is_alive())
nd = Display(visible=1).start().stop()
-
+
# self.assertEquals(nd.return_code, 0)
vd.stop()
ok_(not vd.is_alive())
-
+
def test_disp(self):
vd = Display().start()
ok_(vd.is_alive())
@@ -29,10 +30,6 @@ def test_disp(self):
d = Display(visible=0).start().stop()
# self.assertEquals(d.return_code, 0)
-
+
vd.stop()
ok_(not vd.is_alive())
-
-
-
-
View
14 tests/test_smart.py
@@ -4,6 +4,7 @@
from unittest import TestCase
from path import path
+
class Test(TestCase):
def test_disp(self):
vd = SmartDisplay().start()
@@ -13,9 +14,9 @@ def test_disp(self):
d = SmartDisplay(visible=0).start().stop()
self.assertEquals(d.return_code, 0)
-
+
vd.stop()
-
+
def test_slowshot(self):
disp = SmartDisplay(visible=0).start()
py = path(__file__).parent / ('slowgui.py')
@@ -24,7 +25,7 @@ def test_slowshot(self):
proc.stop()
disp.stop()
eq_(img is not None, True)
-
+
def test_slowshot_wrap(self):
disp = SmartDisplay(visible=0)
py = path(__file__).parent / ('slowgui.py')
@@ -32,17 +33,16 @@ def test_slowshot_wrap(self):
f = disp.wrap(proc.wrap(disp.waitgrab))
img = f()
eq_(img is not None, True)
-
+
def test_empty(self):
disp = SmartDisplay(visible=0)
proc = EasyProcess('python')
f = disp.wrap(proc.wrap(disp.waitgrab))
self.assertRaises(Exception, f)
-
+
def test_slowshot_timeout(self):
disp = SmartDisplay(visible=0)
py = path(__file__).parent / ('slowgui.py')
proc = EasyProcess('python ' + py)
- f = disp.wrap(proc.wrap(lambda : disp.waitgrab(timeout=1)))
+ f = disp.wrap(proc.wrap(lambda: disp.waitgrab(timeout=1)))
self.assertRaises(DisplayTimeoutError, f)
-
View
2  tests/test_smart2.py
@@ -46,5 +46,3 @@ def test_double_wx_pyqt(self):
def test_double_pygtk_pyqt(self):
self.check_double('pygtk', 'pyqt')
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.