Merge pull request #33 from ChrisTruncer/bin_

Small change to reference object attribute
This commit is contained in:
Sylvain Peyrefitte
2015-06-01 11:40:37 +02:00

View File

@@ -23,7 +23,9 @@ example of use rdpy
take screenshot of login page
"""
import sys, os, getopt
import getopt
import os
import sys
from PyQt4 import QtCore, QtGui
from rdpy.protocol.rdp import rdp
@@ -32,15 +34,17 @@ import rdpy.core.log as log
from rdpy.core.error import RDPSecurityNegoFail
from twisted.internet import task
#set log level
# set log level
log._LOG_LEVEL = log.Level.INFO
class RDPScreenShotFactory(rdp.ClientFactory):
"""
@summary: Factory for screenshot exemple
"""
__INSTANCE__ = 0
__STATE__ = []
def __init__(self, reactor, app, width, height, path, timeout):
"""
@param reactor: twisted reactor
@@ -71,7 +75,7 @@ class RDPScreenShotFactory(rdp.ClientFactory):
connector.connect()
return
log.info("connection lost : %s"%reason)
log.info("connection lost : %s" % reason)
RDPScreenShotFactory.__STATE__.append((connector.host, connector.port, reason))
RDPScreenShotFactory.__INSTANCE__ -= 1
if(RDPScreenShotFactory.__INSTANCE__ == 0):
@@ -91,7 +95,6 @@ class RDPScreenShotFactory(rdp.ClientFactory):
self._reactor.stop()
self._app.exit()
def buildObserver(self, controller, addr):
"""
@summary: build ScreenShot observer
@@ -124,7 +127,7 @@ class RDPScreenShotFactory(rdp.ClientFactory):
"""
image = RDPBitmapToQtImage(width, height, bitsPerPixel, isCompress, data);
with QtGui.QPainter(self._buffer) as qp:
#draw image
# draw image
qp.drawImage(destLeft, destTop, image, 0, 0, destRight - destLeft + 1, destBottom - destTop + 1)
if not self._startTimeout:
self._startTimeout = False
@@ -134,7 +137,7 @@ class RDPScreenShotFactory(rdp.ClientFactory):
"""
@summary: callback use when RDP stack is connected (just before received bitmap)
"""
log.info("connected %s"%addr)
log.info("connected %s" % addr)
def onSessionReady(self):
"""
@@ -147,13 +150,13 @@ class RDPScreenShotFactory(rdp.ClientFactory):
"""
@summary: callback use when RDP stack is closed
"""
log.info("save screenshot into %s"%self._path)
log.info("save screenshot into %s" % self._path)
self._buffer.save(self._path)
def checkUpdate(self):
self._controller.close();
controller.setScreen(width, height);
controller.setScreen(self._width, self._height);
controller.setSecurityLevel(self._security)
return ScreenShotObserver(controller, self._width, self._height, self._path, self._timeout, self._reactor)
@@ -181,12 +184,13 @@ def main(width, height, path, timeout, hosts):
else:
ip, port = host, "3389"
reactor.connectTCP(ip, int(port), RDPScreenShotFactory(reactor, app, width, height, path + "%s.jpg"%ip, timeout))
reactor.connectTCP(ip, int(port), RDPScreenShotFactory(reactor, app, width, height, path + "%s.jpg" % ip, timeout))
reactor.runReturn()
app.exec_()
return RDPScreenShotFactory.__STATE__
def help():
print "Usage: rdpy-rdpscreenshot [options] ip[:port]"
print "\t-w: width of screen default value is 1024"
@@ -195,7 +199,7 @@ def help():
print "\t-t: timeout of connection without any updating order (default is 2s)"
if __name__ == '__main__':
#default script argument
# default script argument
width = 1024
height = 800
path = "/tmp/"