<s> import argparse <EOL> import sys <EOL> from ouimeaux . environment import Environment <EOL> from ouimeaux . utils import matcher <EOL> from ouimeaux . signals import receiver , statechange , devicefound <EOL> def mainloop ( name ) : <EOL> matches = matcher ( name ) <EOL> @ receiver ( devicefound ) <EOL> def found ( sender , ** kwargs ) : <EOL> if matches ( sender . name ) : <EOL> print "<STR_LIT>" , sender . name <EOL> @ receiver ( statechange ) <EOL> def motion ( sender , ** kwargs ) : <EOL> if matches ( sender . name ) : <EOL> print "<STR_LIT>" . format ( <EOL> sender . name , state = "<STR_LIT>" if kwargs . get ( '<STR_LIT:state>' ) else "<STR_LIT>" ) <EOL> env = Environment ( ) <EOL> try : <EOL> env . start ( ) <EOL> env . discover ( <NUM_LIT:10> ) <EOL> env . wait ( ) <EOL> except ( KeyboardInterrupt , SystemExit ) : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = argparse . ArgumentParser ( "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT:name>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> mainloop ( args . name ) </s>
