<s> """<STR_LIT>""" <EOL> import os <EOL> from focus import common <EOL> from focus . plugin import base <EOL> class PlaySound ( base . Plugin ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> version = '<STR_LIT>' <EOL> target_version = '<STR_LIT>' <EOL> events = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> options = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False <EOL> } , <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False <EOL> } , <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False <EOL> } <EOL> ] <EOL> } <EOL> ] <EOL> def __init__ ( self ) : <EOL> super ( PlaySound , self ) . __init__ ( ) <EOL> self . files = { } <EOL> def _get_external_player ( self ) : <EOL> """<STR_LIT>""" <EOL> if common . IS_MACOSX : <EOL> return '<STR_LIT>' <EOL> else : <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if common . which ( name ) : <EOL> return name <EOL> return None <EOL> def _play_sound ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> command = self . _get_external_player ( ) <EOL> if not command : <EOL> return <EOL> if common . IS_MACOSX : <EOL> command += '<STR_LIT>' . format ( filename ) <EOL> else : <EOL> is_play = ( command == '<STR_LIT>' ) <EOL> command += '<STR_LIT>' . format ( filename ) <EOL> if is_play and not common . which ( '<STR_LIT>' ) : <EOL> command += '<STR_LIT>' <EOL> common . shell_process ( command , background = True ) <EOL> def parse_option ( self , option , block_name , * values ) : <EOL> """<STR_LIT>""" <EOL> if len ( values ) != <NUM_LIT:1> : <EOL> raise TypeError <EOL> value = os . path . realpath ( os . path . expanduser ( values [ <NUM_LIT:0> ] ) ) <EOL> if not os . path . isfile ( value ) and not os . path . islink ( value ) : <EOL> raise ValueError ( u'<STR_LIT>' <EOL> . format ( value ) ) <EOL> ext = os . path . splitext ( value ) [ <NUM_LIT:1> ] . lower ( ) <EOL> if ext != '<STR_LIT>' and self . _get_external_player ( ) == '<STR_LIT>' : <EOL> raise ValueError ( u"<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if option == '<STR_LIT>' : <EOL> option = '<STR_LIT>' + option <EOL> key = option . split ( '<STR_LIT:_>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> self . files [ key ] = value <EOL> def on_taskstart ( self , task ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT:start>' in self . files : <EOL> self . _play_sound ( self . files [ '<STR_LIT:start>' ] ) <EOL> def on_taskend ( self , task ) : <EOL> """<STR_LIT>""" <EOL> key = '<STR_LIT>' if task . elapsed else '<STR_LIT:end>' <EOL> filename = self . files . get ( key ) <EOL> if filename : <EOL> self . _play_sound ( filename ) </s>
