<s> import config <EOL> import uuid <EOL> import atexit <EOL> import pybonjour <EOL> def buildTxtRecord ( dic ) : <EOL> return "<STR_LIT>" . join ( [ chr ( len ( s ) ) + s for s in <EOL> ( "<STR_LIT>" % ( k , str ( v ) ) for k , v in dic . iteritems ( ) ) ] ) <EOL> def getHWAddress ( ) : <EOL> macAddr = hex ( uuid . getnode ( ) ) [ <NUM_LIT:2> : ] . upper ( ) <EOL> return [ a + b for a , b in zip ( macAddr [ : : <NUM_LIT:2> ] , macAddr [ <NUM_LIT:1> : : <NUM_LIT:2> ] ) ] <EOL> def registerAirPlay ( targetPort = <NUM_LIT> ) : <EOL> params = { <EOL> "<STR_LIT>" : "<STR_LIT::>" . join ( getHWAddress ( ) ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : config . model , <EOL> "<STR_LIT>" : config . rhd , <EOL> "<STR_LIT>" : config . server_version , <EOL> "<STR_LIT>" : config . rmodel , <EOL> "<STR_LIT>" : str ( int ( config . password is not None ) ) , <EOL> "<STR_LIT>" : "<STR_LIT:1>" <EOL> } <EOL> sdRef = pybonjour . DNSServiceRegister ( <EOL> name = config . service_name , <EOL> regtype = "<STR_LIT>" , <EOL> port = targetPort , <EOL> txtRecord = buildTxtRecord ( params ) ) <EOL> atexit . register ( sdRef . close ) <EOL> def registerAirTunes ( targetPort ) : <EOL> params = { <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : config . model , <EOL> "<STR_LIT>" : "<STR_LIT:2>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:true>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" if config . password is None else "<STR_LIT:true>" , <EOL> "<STR_LIT>" : config . rhd , <EOL> "<STR_LIT>" : config . rmodel , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:false>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : config . server_version , <EOL> "<STR_LIT>" : "<STR_LIT:1>" <EOL> } <EOL> sdRef = pybonjour . DNSServiceRegister ( <EOL> name = "<STR_LIT>" % ( "<STR_LIT>" . join ( getHWAddress ( ) ) , config . service_name ) , <EOL> regtype = "<STR_LIT>" , <EOL> port = targetPort , <EOL> txtRecord = buildTxtRecord ( params ) ) <EOL> atexit . register ( sdRef . close ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import sys <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> config . service_name = sys . argv [ <NUM_LIT:1> ] <EOL> registerAirPlay ( ) </s>
