Permalink
Browse files

formatting by autopep8

  • Loading branch information...
ponty
ponty committed Dec 3, 2012
1 parent 7bc6c63 commit 0c863c58bbbdf38eb274ee02c3fbd845d747e4e2
View
@@ -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
@@ -14,33 +14,34 @@
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)
options(
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
-
@@ -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
-
-
-
-
-
-
-
-
-
-
@@ -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
-
-
@@ -1,6 +1,5 @@
from easyprocess import EasyProcess
from pyvirtualdisplay import Display
-
+
Display(visible=1, size=(320, 240)).start()
EasyProcess('gnumeric').start()
-
@@ -7,4 +7,3 @@
xmessage.stop()
disp.stop()
img.show()
-
@@ -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:
@@ -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
-
-
-
-
-
-
-
-
-
-
-
Oops, something went wrong.

0 comments on commit 0c863c5

Please sign in to comment.