<s> from driver_base import DriverBase <EOL> import socket <EOL> import sys <EOL> import time <EOL> import os <EOL> os . sys . path . insert ( <NUM_LIT:0> , os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) ) <EOL> import log <EOL> class CMDTYPE : <EOL> SETUP_DATA = <NUM_LIT:1> <EOL> PIXEL_DATA = <NUM_LIT:2> <EOL> BRIGHTNESS = <NUM_LIT:3> <EOL> class RETURN_CODES : <EOL> SUCCESS = <NUM_LIT:255> <EOL> ERROR = <NUM_LIT:0> <EOL> ERROR_SIZE = <NUM_LIT:1> <EOL> ERROR_UNSUPPORTED = <NUM_LIT:2> <EOL> class DriverNetwork ( DriverBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , num = <NUM_LIT:0> , width = <NUM_LIT:0> , height = <NUM_LIT:0> , host = "<STR_LIT:localhost>" , port = <NUM_LIT> ) : <EOL> super ( DriverNetwork , self ) . __init__ ( num , width , height ) <EOL> self . _host = host <EOL> self . _port = port <EOL> def _generateHeader ( self , cmd , size ) : <EOL> packet = bytearray ( ) <EOL> packet . append ( cmd ) <EOL> packet . append ( size & <NUM_LIT> ) <EOL> packet . append ( size >> <NUM_LIT:8> ) <EOL> return packet <EOL> def _connect ( self ) : <EOL> try : <EOL> s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> s . connect ( ( self . _host , self . _port ) ) <EOL> return s <EOL> except socket . gaierror : <EOL> error = "<STR_LIT>" . format ( <EOL> self . _host ) <EOL> log . error ( error ) <EOL> raise IOError ( error ) <EOL> def update ( self , data ) : <EOL> try : <EOL> s = self . _connect ( ) <EOL> count = self . bufByteCount <EOL> packet = self . _generateHeader ( CMDTYPE . PIXEL_DATA , count ) <EOL> packet . extend ( data ) <EOL> s . sendall ( packet ) <EOL> resp = ord ( s . recv ( <NUM_LIT:1> ) ) <EOL> s . close ( ) <EOL> if resp != RETURN_CODES . SUCCESS : <EOL> log . warning ( "<STR_LIT>" , resp ) <EOL> except Exception as e : <EOL> log . exception ( e ) <EOL> error = "<STR_LIT>" <EOL> log . error ( error ) <EOL> raise IOError ( error ) <EOL> def setMasterBrightness ( self , brightness ) : <EOL> packet = self . _generateHeader ( CMDTYPE . BRIGHTNESS , <NUM_LIT:1> ) <EOL> packet . append ( brightness ) <EOL> s = self . _connect ( ) <EOL> s . sendall ( packet ) <EOL> resp = ord ( s . recv ( <NUM_LIT:1> ) ) <EOL> if resp != RETURN_CODES . SUCCESS : <EOL> return False <EOL> else : <EOL> return True <EOL> MANIFEST = [ <EOL> { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:class>" : DriverNetwork , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:label>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT:int>" , <EOL> "<STR_LIT:default>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , { <EOL> "<STR_LIT:id>" : "<STR_LIT:width>" , <EOL> "<STR_LIT:label>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT:int>" , <EOL> "<STR_LIT:default>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:label>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT:int>" , <EOL> "<STR_LIT:default>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , { <EOL> "<STR_LIT:id>" : "<STR_LIT:host>" , <EOL> "<STR_LIT:label>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT:str>" , <EOL> "<STR_LIT:default>" : "<STR_LIT:localhost>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , { <EOL> "<STR_LIT:id>" : "<STR_LIT:port>" , <EOL> "<STR_LIT:label>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT:int>" , <EOL> "<STR_LIT:default>" : <NUM_LIT> , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ] <EOL> } <EOL> ] </s>
