Permalink
Browse files

whitespace clean up, rename f -> factory

  • Loading branch information...
1 parent 96b1223 commit f1eba1a8717d5bca7e3ea8615a64a7879a2b54a9 Marc Sibson committed Feb 7, 2011
Showing with 31 additions and 27 deletions.
  1. +5 −4 tests/test_client.py
  2. +1 −0 tests/test_command.py
  3. +3 −4 vncdotool/client.py
  4. +22 −19 vncdotool/command.py
View
@@ -4,6 +4,7 @@
from vncdotool.client import VNCDoToolClient, VNCDoToolFactory
from vncdotool import rfb
+
class TestVNCDoToolClient(object):
def setUp(self):
self.client = VNCDoToolClient()
@@ -85,9 +86,9 @@ def test_expectScreen(self):
def test_expectCompareSuccess(self):
client = self.client
d = client.deferred = mock.Mock()
- client.expected = [ 2, 2, 2 ]
+ client.expected = [2, 2, 2]
image = mock.Mock()
- image.histogram.return_value = [ 1, 2, 3 ]
+ image.histogram.return_value = [1, 2, 3]
client._expectCompare(image, 5)
d.callback.assert_called_once_with(client)
@@ -96,10 +97,10 @@ def test_expectCompareSuccess(self):
def test_expectCompareFails(self):
client = self.client
client.deferred = mock.Mock()
- client.expected = [ 2, 2, 2 ]
+ client.expected = [2, 2, 2]
client.updates = mock.Mock()
image = mock.Mock()
- image.histogram.return_value = [ 1, 2, 3 ]
+ image.histogram.return_value = [1, 2, 3]
client._expectCompare(image, 0)
View
@@ -2,6 +2,7 @@
from vncdotool import command
import mock
+
@mock.isolate(command.build_command_list)
class TestBuildCommandList(object):
def setUp(self):
View
@@ -89,6 +89,7 @@
'kpenter': rfb.KEY_KP_Enter,
}
+
class VNCDoToolClient(rfb.RFBClient):
x = 0
y = 0
@@ -159,8 +160,8 @@ def _expectCompare(self, image, maxrms):
hist = image.histogram()
rms = math.sqrt(
- reduce(operator.add,
- map(lambda a,b: (a-b)**2, hist, self.expected)) / len(hist))
+ reduce(operator.add, map(
+ lambda a, b: (a - b) ** 2, hist, self.expected)) / len(hist))
self.log('rms %d', rms)
@@ -172,7 +173,6 @@ def _expectCompare(self, image, maxrms):
d = self.updates.get()
d.addCallback(self._expectCompare, maxrms)
-
def mouseMove(self, x, y):
""" Move the mouse pointer to position (x, y)
"""
@@ -192,7 +192,6 @@ def image(self):
from PIL import Image
return Image
-
#
# base customizations
#
View
@@ -13,13 +13,16 @@
from vncdotool.client import VNCDoToolFactory, VNCDoToolClient
import sys
+
def logger(fmt, *args):
print fmt % args
+
def log_connected(pcol):
print 'connected to', pcol.name
return pcol
+
def error(reason):
try:
reason = reason.getErrorMessage()
@@ -30,12 +33,14 @@ def error(reason):
reactor.exit_status = 10
reactor.stop()
+
def stop(pcol):
reactor.exit_status = 0
pcol.transport.loseConnection()
# XXX delay
reactor.callLater(0.1, reactor.stop)
+
class VNCDoToolOptionParser(optparse.OptionParser):
def format_help(self, **kwargs):
result = optparse.OptionParser.format_help(self, **kwargs)
@@ -54,43 +59,42 @@ def format_help(self, **kwargs):
def build_command_list(factory, args):
- f = factory
client = VNCDoToolClient
while args:
cmd = args.pop(0)
if cmd == 'key':
key = args.pop(0)
- f.deferred.addCallback(client.keyPress, key)
+ factory.deferred.addCallback(client.keyPress, key)
elif cmd == 'move':
x, y = int(args.pop(0)), int(args.pop(0))
- f.deferred.addCallback(client.mouseMove, x, y)
+ factory.deferred.addCallback(client.mouseMove, x, y)
elif cmd == 'click':
button = int(args.pop(0))
- f.deferred.addCallback(client.mousePress, button)
+ factory.deferred.addCallback(client.mousePress, button)
elif cmd == 'type':
for key in args.pop(0):
- f.deferred.addCallback(client.keyPress, key)
+ factory.deferred.addCallback(client.keyPress, key)
elif cmd == 'capture':
filename = args.pop(0)
- f.deferred.addCallback(client.captureScreen, filename)
+ factory.deferred.addCallback(client.captureScreen, filename)
elif cmd == 'expect':
filename = args.pop(0)
rms = int(args.pop(0))
- f.deferred.addCallback(client.expectScreen, filename, rms)
+ factory.deferred.addCallback(client.expectScreen, filename, rms)
else:
print 'unknown cmd "%s"' % cmd
def main():
usage = '%prog [options] CMD CMDARGS'
- description='Command line interaction with a VNC server'
+ description = 'Command line interaction with a VNC server'
op = VNCDoToolOptionParser(usage=usage, description=description,
add_help_option=False)
op.add_option('-d', '--display', action='store', metavar='DISPLAY',
type='int', default=0,
help='connect to vnc server on DISPLAY [%default]')
- op.add_option('--help', action='help',
+ op.add_option('--help', action='help',
help='show this help message')
op.add_option('-h', '--host', action='store', metavar='HOST',
default='127.0.0.1',
@@ -103,25 +107,24 @@ def main():
opts, args = op.parse_args()
if opts.port is None:
opts.port = opts.display + 5900
-
+
if not len(args):
op.error('no command provided')
- f = VNCDoToolFactory()
+ factory = VNCDoToolFactory()
if opts.verbose:
print 'connecting to %s:%d' % (opts.host, opts.port)
- f.logger = logger
-
- if opts.verbose:
- f.deferred.addCallbacks(log_connected)
+ factory.logger = logger
- build_command_list(f, args)
+ if opts.verbose:
+ factory.deferred.addCallbacks(log_connected)
- f.deferred.addCallback(stop)
- f.deferred.addErrback(error)
+ build_command_list(factory, args)
- d = reactor.connectTCP(opts.host, opts.port, f)
+ factory.deferred.addCallback(stop)
+ factory.deferred.addErrback(error)
+ reactor.connectTCP(opts.host, opts.port, factory)
reactor.exit_status = 1
reactor.run()

0 comments on commit f1eba1a

Please sign in to comment.