
    Ifl                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZ ddlmZ  ej                  ej                   d        ej"                  ej$                  ej&                          ej(                  ej$                         ej                  Zdadad Zd Zd	 Zd
 Zd Zd Z G d d      Z G d d      Zd Z e!dk(  r e	jD                   e               yy)    N)BaseDirectory   )buildconfig Fc                 ~    t        |        t        r,t        j                  dt	        j
                  |       z         yy)zZOutput information messages for the user on stdout
    and if desired, by espeak synthesisz	espeak %sN)printuse_espeak_synthesisossystemshlexquote)msgs    7/usr/lib/python3/dist-packages/speechd_config/config.pyreportr   0   s-     
#J
		+C 001     c                  <    t         rt        j                  d       yy)zBProduce a sound for the event 'input requested' used in question()zespeak "Type in"N)r	   r
   r    r   r   input_audio_iconr   7   s    
		&' r   c                    	 t        |t              r|rd}nd}nt        |      }t        | dz   |z   dz          t	                t
        st        d      }t
        st              dk(  r|S t        |t              r|dv ry|d	v ry
t        d       t        |t              rt        |      S t        |t              r|S t        d      )z3Ask a simple question and suggest the default valueyesnoz [z] :>r   )r   yYtruet1T)r   nNfalsef0Fz#Unknown answer (type 'yes' or 'no')z"Invalid type for the default value)

isinstanceboolstrr   r   dont_askinputlenint	TypeError)textdefaultdefault_strstr_inps       r   questionr/   <   s     gt$#"g,Ktd{;&u,-CjG G)N&;;??=>%w<%N@AAr   c                     t        | |      }||vrbt        t        d|z               t        t        dt        |      z                t        t        d      d      }|rt        | |      }n|S ||vrb|S )zAsk a question with suggested answers. If the answer typed is not
    in 'suggest', the user is notified and given an opportunity to correct
    his choicezRThe value you have chosen is not among the suggested values.
You have chosen '%s'.zThe suggested values are z#Do you want to correct your answer?Tr/   r   _r%   )r+   r,   suggestreplycorrects        r   question_with_suggested_answersr6   `   s    
 T7#E
w
q  ! " 	#q,s7|;<=1BCTJT7+EL w
 Lr   c           
          t        | |      }||vr4t        t        d|dt        |                   t        | |      }||vr4|S )zGAsk a question and repeat it until the answer typed in is in 'required'zYou have chosen 'z'. Please choose one of r1   )r+   r,   requiredr4   s       r   question_with_required_answersr9   q   sK     T7#E
x
qE3x=YZ[w' x
 Lr   c            
         t        j                  t        d            } | j                  dddddt        d      	       | j                  d
ddddt        d      	       | j                  dddddt        d      	       | j                  dddddt        d      	       | j                  dddddt        d      	       | j                  ddddt        d      	       | j                  ddddt        d      	       | j                  d d!ddt        d"      	       | j                  d#d$ddt        d%      	       | j                  d&d'd(dt        t        d)      	       | j                  d*d+d,ddt        d-      	       | j                  d.d/d0ddt        d1      	       | j                  d2d3dt        d4      5       | S )6z;Set up an argparser instance with all the options accepted.zRA simple tool for basic configuration of Speech Dispatcher and problem diagnostics)descriptionz-uz--create-user-confcreate_user_configuration
store_trueFz9Create Speech Dispatcher configuration for the given user)destactionr,   helpz-cz--config-basic-settings-userconfig_basic_settings_userz.Configure basic settings in user configurationz-Cz--config-basic-settings-systemconfig_basic_settings_systemz5Configure basic settings in system-wide configurationz-dz--diagnosticsdiagnosticsz(Diagnose problems with the current setupz-sz--test-spd-saytest_spd_sayz2Test connection to Speech Dispatcher using spd-sayz--test-festivaltest_festival'Test whether Festival works as a serverz--test-espeaktest_espeakz0Test whether Espeak works as a standalone binaryz--test-alsa	test_alsazTest ALSA audio outputz--test-pulse
test_pulsezTest Pulse Audio outputz-ez--espeakr	   z!Use espeak to synthesize messagesz-nz
--dont-askr&   z3Do not ask any questions, always use default valuesz-Dz--debugdebugz%Debug a problem and generate a reportz	--versionversion Print version and copyright info)r>   r?   r@   )argparseArgumentParserr2   add_argumentr	   )parsers    r   setup_argparserQ   z   s.   $$jkmF
2(uJK  M <),?@  B >+L%FG  I oMU9:  < .^UCD  F )U89  ; mLAPQ  S
KA67  9
\,"; <  >
j/E)=67  9 lHI  K ig:;  = )56  8 Mr   c                       e Zd ZdZd Zd Zd Zd Zd ZddZ	d Z
d	 Zd
 Zd Zd Zd Zd Zd Z	 	 ddZd Zd ZddZy)TestszrTests of functionality of Speech Dispatcher and its dependencies
    and methods for determination of proper pathsc                     d | _         y N)festival_socketselfs    r   __init__zTests.__init__   s
    #r   c                 l    t        dt        j                   d       t        t        d      dz         y)rL   z	spd-conf 
a$  Copyright (C) %d-%d Brailcom, o.p.s.
This is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version. Please see COPYING for more details.

)i  i  N)r   r   VERSIONr2   rW   s    r   rK   zTests.version   s9    ;../r23q ? @
  	r   c                 ^    t         j                  j                  t        j                  d      S )z#Return user configuration directoryspeech-dispatcher)r
   pathjoinr   xdg_config_homerW   s    r   user_conf_dirzTests.user_conf_dir   s    ww||M99;NOOr   c                 "    t         j                  S )z(Determine system configuration directory)r   SPD_CONF_PATHrW   s    r   system_conf_dirzTests.system_conf_dir   s    (((r   c                 \    t         j                  j                  | j                               S )z5Determine whether user configuration directory exists)r
   r_   existsrb   rW   s    r   user_conf_dir_existszTests.user_conf_dir_exists   s    ww~~d00233r   c                    t        j                   t         j                  t         j                        | _        	 | j                  j	                  t        j
                  |      |f       y# t         j                  $ rI}|j                  \  }}t        t        d||fz               t        t        d|z               Y d}~yd}~ww xY w)z
        Try to connect to festival and determine whether it is possible.
        On success self.festival_socket is initialized with the opened socket.
        ztERROR: It was not possible to connect to Festival on the
given host and port. Connection failed with error %d : %s .zHint: Most likely, your Festival server is not running now
or not at the default port %d.

Try /etc/init.d/festival start or run 'festival --server' from the command line.NFT)
socketAF_INETSOCK_STREAMrV   connectgethostbynameerrorargsr   r2   )rX   hostportenumreasons         r   festival_connectzTests.festival_connect   s    
  &}}V^^V=O=OP
	  ((&*>*>t*Dd)KL  || 	FFMS&1 ?BEvO P Q1 T W[[ \ ] 	s   0A* *C=?CCc                 *   | j                   s| j                         sy| j                   j                  t        dd             t	        | j                   j                  d            }d|v rt        t        d             yt        t        d             y)	zSTest whether festival works and contains working festival-freebsoft-utils.
        Fz(require 'speech-dispatcher)
asciii   LPz"Festival contains freebsoft-utils.TzERROR: Your Festival server is working but it doesn't seem
to load festival-freebsoft-utils. You need to install festival-freebsoft-utils
to be able to use Festival with Speech Dispatcher.)rV   rv   sendbytesr%   recvr   r2   )rX   r4   s     r   festival_with_freebsoft_utilsz#Tests.festival_with_freebsoft_utils   s     ##((*!!%(H'"RSD((--d345=19:;1 6 7 8 r   c                 v    ddl }	 |j                  d       y# t        $ r t        t	        d             Y yw xY w)z0Try whether python speechd library is installed.r   NspeechdzPython can't find the Speech Dispatcher library.
Is it installed? This won't prevent Speech Dispatcher to work, but no
Python applications like Orca will be able to use it.
Search for package like python-speechd, download and install it.FT)	importlibimport_moduleImportErrorr   r2   )rX   r   s     r   python_speechd_in_pathzTests.python_speechd_in_path   sJ    	##I.   	1 D E F 	s    88c                 B   t         j                  j                  t        j                  d      }d}|dk(  rd}n|dk(  rd}nt        d      t        j                  |      s4t        t        |d|d	             t        t        d
|z        d      }|S |d|}t        j                  |      r,t        t        d|z               t        t        d             yt        t        d      d      }|st        t        d             yt        t        d|z               y)z]Try to play a sound through the standard playback utility for the
        given audio method.ztest.wavNalsaaplaypulsepaplayz-Test for this audio system is not implementedz selected, but zT not installed. This might be a false
warning, but most likely sound is not working.z&Are you sure that %s audio is working?F zCan't play audio via
     %szUYour audio doesn't seem to work, please fix audio first or choose
a different method.zDid you hear the sound?TzPlease examine the above output from the sound playback
utility. If everything seems right, are you sure your audio is loud enough and
not muted in the mixer? Please fix your audio system first or choose a different
audio output method in configuration.zAudio output '%s' works)r
   r_   r`   r   SPD_SOUND_DATA_PATHNotImplementedErrorshutilwhichr   r2   r/   r   )rX   typewavfilebinaryr4   cmds         r   audio_try_playzTests.audio_try_play   s    '',,{>>zJ6>FW_F%&UVV||F#1596C D EQG$NOQVWEL)99S>14s:;<1    45t<1 ) * + 1.567r   c                    t        t        d             	 t        j                  d      rt        t        d             yt	        t        d      d      }|rt        t        d             yt        t        d             y)	z$Test Speech Dispatcher using spd_sayz'Testing Speech Dispatcher using spd_sayTz.spd-say -P important "Speech Dispatcher works"z\Can't execute the spd-say binary,
it is very likely that Speech Dispatcher is not installed.Fz9Did you hear the message about Speech Dispatcher working?z+Speech Dispatcher is installed and working!z8Speech Dispatcher is installed but there is some problemr   r2   r
   r   r/   )rX   hearing_tests     r   rD   zTests.test_spd_say  sr     	q:;<yyKLq > ? @#A&a$bdhiLqFGHqSTUr   c                     t        t        d             | j                         }|st        t        d             yt        t        d             y)rF   z*Testing whether Festival works as a serverzFestival server is not working.Fz'Festival server seems to work correctlyT)r   r2   r}   )rX   rets     r   rE   zTests.test_festival,  sC    q=>?00216781>?@r   c                     t        t        d             t        j                  d      rt        t        d             yt        t        d             y)zTest the espeak utilityzTesting whether Espeak worksespeakzEspeak is installedTzKCan't execute the espeak binary, it is likely that espeak
is not installed.F)r   r2   r   r   rW   s    r   rG   zTests.test_espeak8  sF     	q/01<<!1*+,1   r   c                 N    t        t        d             | j                  d      S )zTest ALSA sound outputzTesting ALSA sound outputr   r   r   r2   r   rW   s    r   rH   zTests.test_alsaD  s$    q,-."""//r   c                 N    t        t        d             | j                  d      S )zTest Pulse Audio sound outputzTesting PULSE sound outputr   r   r   rW   s    r   rI   zTests.test_pulseI  s$    q-./"""00r   Nc                    g }g }|r0| j                         rd}t        t        d      d      }|r	ddiS d}nd}|st        t        d      d      sddiS d } |dd|      r| j                         r|dgz  } |d	d
|      r| j	                         r|d	gz  } |dd|      r| j                         r|dgz  } |dd|      r| j                         r|dgz  }t        t        d             | j                         }	||||	dS )zPerform a complete diagnosticsTz9Speech Dispatcher works. Do you want to skip other tests?spd_say_workingFz
Speech Dispatcher isn't running or we can't connect to it (see above),
do you want to proceed with other tests? (They can help to determine
what is wrong)c                 D    |sy| |v rt        t        d|z        d      ryy)z3Ask the user whether to test a specific capability.FzDo you want to test the %s now?T)r/   r2   )
identifiernamelistings      r   decide_to_testz)Tests.diagnostics.<locals>.decide_to_testh  s+    w&Q@4GH$Or   festivalzFestival synthesizerr   zEspeak synthesizerr   zALSA sound systemr   zPulse Audio sound systemzJTesting whether Python Speech Dispatcher library is in path and importable)r   audiosynthesizerspython_speechd)	rD   r/   r2   rE   rG   rH   rI   r   r   )
rX   speechd_runningoutput_modulesaudio_outputworking_modulesworking_audior   skipr   python_speechd_workings
             r   rC   zTests.diagnosticsN  sB      ""&"] ^ $&-t44"'#OA    *511	 *&<nM!!#J</($8.I!H:-&"5|D~~&)'#=|L '*q]^_!%!<!<!>$3'!0$:< 	<r   c                    t        t        d             d|v r.|d   rt        t        d             nt        t        d             d|v r#t        t        d      t        |d         z         d|v r#t        t        d      t        |d         z         d	|v r.|d	   rt        t        d
             nt        t        d             t        t        d             y)z,Write out diagnostics results using report()z

Diagnostics results:r   zSpeech Dispatcher is workingz-Speech Dispatcher not working through spd-sayr   z2Synthesizers that were tested and seem to work: %sr   z3Audio systems that were tested and seem to work: %sr   z-Python Speech Dispatcher module is importablezTPython Speech Dispatcher module not importable.
Either not installed or not in path.zEnd of diagnostics resultsN)r   r2   r%   )rX   resultss     r   write_diagnostics_resultszTests.write_diagnostics_results  s     	q   	 '()q789qHIJW$1IJw~./0 1g1JKww'() *w&'(qHIJq ( ) *q-./r   c                 ,   t         j                  j                  t         j                  j                  | j	                         d            syt        t        j                  | j	                                     dkD  syt         j                  j                  t         j                  j                  | j	                         d            syt         j                  j                  t         j                  j                  | j	                         d            syy)z:Decide if the user configuration seems reasonably completespeechd.confF   modulesclientsT)r
   r_   rg   r`   rb   r(   listdirrW   s    r   !user_configuration_seems_completez'Tests.user_configuration_seems_complete  s    ww~~bggll4+=+=+?PQ2::d00234q8ww~~bggll4+=+=+?KLww~~bggll4+=+=+?KLr   c                    t        t        d             |st        t        d      dddg      }t        t        d      d      }|r+t	        j
                  d       t	        j
                  d       n?t        t        d	             t        t        d
      d      }|st        t        d             t        j                  d       dt        j                  v rt        j                  d   }nd}t        j                  j                  |d      }t        j                  j                         }t        j                  j                  |d|j                  |j                  |j                   fz        }|dk(  r;t        t        d             t	        j
                  d       }| j#                         }nft        t        d             t        t        d             t        t        d      d      }|rd}nt        t        d             | j%                         }t        j                  d       st        t        d      d      }t        t        d             t	        j
                  d      }	|	s+t	        j
                  d       t	        j
                  d       nt        t        d             t        t        d             t        j                  d       t        t        d              t	        j
                  d!       t	        j
                  d"|d#|d$|       t	        j
                  d       t	        j
                  d       t	        j
                  d%|z         t        t        d&|z               y')(zvStart Speech Dispatcher in debugging mode, collect the debugging output
        and offer to send it to the developersz@Starting collecting debugging output, configuration and logfilesz<
Do you want to debug 'system' or  'user' Speech Dispatcher?userr   zdIt is necessary to kill the currently running Speech Dispatcher
processes. Do you want to do it now?Tkillall speech-dispatcherkillall speech-dispatchzy
You decided not to kill running Speech Dispatcher processes.
Please make sure your Speech Dispatcher is not running now.z*Is your Speech Dispatcher not running now?z@Can't continue, please stop your Speech Dispatcher and try againr   TMPDIRz/tmp/zspeechd-debugzspeechd-debug-%d-%d-%d.tar.gzz7Speech Dispatcher will be started now in debugging modezspeech-dispatcher -D3Warning: You must be root or under sudo to do this.zC
Please start your system Speech Dispatcher now with parameter '-D'z&Is your Speech Dispatcher running now?Can't continuez5Speech Dispatcher failed to start, continuing anyway?FzTrying to speak some messagesz'spd-say "Speech Dispatcher debugging 1"z'spd-say "Speech Dispatcher debugging 2"z'spd-say "Speech Dispatcher debugging 3"z6Can't test Speech Dispatcher connection, can't connectzPlease wait (about 5 seconds)   z>Collecting debugging output and your configuration informationz	umask 077ztar -cz r   z > z	rm -rf %sz
Please send %s to speechd-discuss@nongnu.org with
a short description of what you did. We will get in touch with you soon
and suggest a solution.N)r   r2   r9   r/   r
   r   timesleepenvironr_   r`   datetimedatetodaydaymonthyearrb   re   )
rX   r   r4   tmpdirdebugdir_pathr   debugarchive_pathspeechd_startedconfigure_directoryr   s
             r   debug_and_reportzTests.debug_and_report  s    	qSTU1! 5? 3@2868:LND
  ( )*.0II12II/01 ? @ A QKLdSEq[\]

1 rzz!ZZ)FFV_=}}""$GGLL1P*.((DJJ		)J2K L 6>1NOP"$)),B"CCO"&"4"4"61JKT1 F G HQGH$OE"&q)*+"&"6"6"8

1QVWE 	q012iiCDIIABIIAB1MNOq012

1qQRT
		+
		 "57HJ 	K
		-.
		+,
		+-.q  // 0 	1r   )	localhosti"  )TNNrU   )__name__
__module____qualname____doc__rY   rK   rb   re   rh   rv   r}   r   r   rD   rE   rG   rH   rI   rC   r   r   r   r   r   r   rS   rS      so    5$P)4&"&P$

0
1
 BF:<x02 S1r   rS   c                   N    e Zd ZdZdZdZdZd Zd Zd Z	d Z
ddZd Zd	 Zd
 Zy)	ConfigurezNSetup user configuration and/or set basic options in user/system configurationNc                     || _         y rU   )test)rX   r   s     r   rY   zConfigure.__init__  s	    	r   c                 ^    t        j                  | j                  j                                y)zRemove user configuration treeN)r   rmtreer   rb   rW   s    r   remove_user_configurationz#Configure.remove_user_configuration  s    dii--/0r   c                    t        j                  |dd      D ]  }|j                         D ]  \  }}||v sd}|j                         D ]!  }|dk(  s|dk(  r||k(  r
|dk7  sd} n|dz  }# |dk(  sGt	        |t
              r
|rd	}n,|s*d
}n't	        |t              rt        |      }nt        |      }t        |dz   z            t        |d        y)zSubstitute the given options with given values.

        Arguments:
        configfile -- the file path of the configuration file as a string
        options -- a list of tuples (option_name, value)Tz.bak)inplacebackupr   #	r   r   r   2z   r   )endN)		fileinputr'   itemssplitr#   r$   r)   r%   r   )	rX   
configfileoptionslineoptvalueunknownwordspd_vals	            r   options_substitutezConfigure.options_substitute  s     OOJVL &	%D%mmo $%
U$;  G $

 
)#:$!S[  '!|*+ %#qLG
) !|%eT2$*-%**-'s3&)%jG&)%jGcEkG34C$%H d$M&	%r   c                 Z   | j                   j                         r| j                   j                         r=t        t	        d      d      }|st        t	        d             y| j                          n=t        t	        d      d      }|s| j                          nt        t	        d             y| j                   j                         }t        j                  t        j                  |       t        j                  d      }t        j                  |       t        j                  | j                   j                         d| z         t        j                  | j                   j                               D ]  \  }}}|D ]:  }t        j                  t        j                   j#                  ||      d| z         < |D ]:  }t        j                  t        j                   j#                  ||      d	| z         <  t        t	        d
| j                   j                         z               y)z2Create user configuration in the standard locationzLUser configuration already exists.
Do you want to rewrite it with a new one?Fz:Keeping configuration intact and continuing with settings.NzYUser configuration already exists, but it seems to be incomplete.
Do you want to keep it?z*Keeping configuration intact and aborting.r   i  i  z User configuration created in %s)r   rh   r   r/   r2   r   r   rb   r   copytreer   SPD_CONF_ORIG_PATHr
   umaskchmodwalkr_   r`   )	rX   r4   config_rootr   rootdirsfilesdr!   s	            r   r<   z#Configure.create_user_configurationF  s    99))+yy::<  $- "./461YZ[224  $ ""$2241IJK ii--/66D

((*UeV^<!#)@)@)B!C 	@D$ @dA.?@ @dA.?@	@ 	q3dii6M6M6OOPQr   c           
      D   |dk(  rt        t        d             n9|dk(  r)t        t        d             t        t        d             nt        d      t        ddg d	      | _        t        d
d      | _        t        ddg d      | _        t        t        d      d      }t        t        d      d      }t        t        d      d      }|dk(  r9t        j                  j                  | j                  j                         d      }n=|dk(  r8t        j                  j                  | j                  j                         d      }| j                  | j                  | j                  | j                  |||d       |dk(  rt        t        d      d      }|rt        j                   t        j                  j                  t"        j$                  d      t        j                  j                  t&        j(                  d             t        t        d|z               yyy)zAAsk for basic settings and rewrite them in the configuration filer   z/Configuring user settings for Speech Dispatcherr   r   z1Configuring system settings for Speech DispatcherInvalid configuration typezDefault output module	espeak-ng)r   r   r   fliteivonapicozespeak-ng-mbrola-genericzespeak-mbrola-genericzswift-genericzepos-genericzdtk-genericibmttscicerokalizmary-generic	baratinooznDefault language (two/three-letter iso language code like "en" or "cs", possibly with a region qualification.)zen-USzDefault audio output methodr   )r   libaor   ossz
pulse,alsazZDefault speech rate (on the scale of -100..100, 0 is default, 50 is faster, -50 is slower)r"   zZDefault speech pitch (on the scale of -100..100, 0 is default, 50 is higher, -50 is lower)z`Default speech pitch range (on the scale of -100..100, 0 is default, 50 is higher, -50 is lower)r   )DefaultModuleDefaultLanguageAudioOutputMethodDefaultRateDefaultPitchDefaultPitchRangezDo you want to have Speech Dispatcher automatically started from ~/.config/autostart ?
This is usually not necessary, most applications will start Speech Dispatcher automatically.Fzspeechd.desktopz
autostart/z
Configuration written to %s
Basic configuration now complete. You might still need to fine tune it by
manually editing the configuration file above. Especially if you need to
use special audio settings, non-standard synthesizer ports etc.N)r   r2   
ValueErrorr6   default_output_moduler/   default_languagedefault_audio_methodr
   r_   r`   r   rb   re   r   r   copyr   SPD_DESKTOP_CONF_PATHr   ra   )rX   r   default_speech_ratedefault_speech_pitchdefault_speech_pitch_ranger   setup_autostarts          r   configure_basic_settingsz"Configure.configure_basic_settingsk  s    6>1FGHX1JKL1HIJ9:: &E#*&+" !) A! %D);%=!
 'jk  (jk  &.pq&"
 6>dii&=&=&?PJXdii&?&?&A>RJ
262L2L484I4I6:6O6O0C1E6P!#	$ 6>& ` aO GGLL!B!BDUVGGLL!>!>M
 q C FP	P Q R  r   c                 f   t        t        d             t        j                  d      }|rt        t        d|z               t	        t        d      d      }|rWt        j                  d       t        j                  d       t        j                  d      }|rt        t        d             y	yy	y)
z$Start Speech Dispatcher in user-modez'Starting Speech Dispatcher in user-moder^   4Can't start Speech Dispatcher. Exited with status %dzPerhaps this is because your Speech Dispatcher is already running.
Do you want to kill all running Speech Dispatchers and try again?Tr   r   zCan't start Speech DispatcherFr   )rX   errr4   s      r   speechd_start_userzConfigure.speechd_start_user  s     	q:;<ii+,1KcQRSQ  E FGKME		56		34ii 341<=>   r   c                    t        t        d             t        t        d             t        t        d      d      }|rmt        t        d             t        j                  d       t        t        d             t        j                  d      }|rt        t        d	|z               y
yt        t        d             t        t        d      d      }|st        t        d             y
y)z&Start Speech Dispatcher in system-moder   z)Starting Speech Dispatcher in system-modez=Is your system using an /etc/init.d/speech-dispatcher script?Tz9Stopping Speech Dispatcher in case any is running alreadyz"/etc/init.d/speech-dispatcher stopz<Starting Speech Dispatcher via /etc/init.d/speech-dispatcherz#/etc/init.d/speech-dispatcher startr  Fz]Do not know how to start system Speech Dispatcher,
you have to start it manually to continue.z'Have you started Speech Dispatcher now?r   )r   r2   r/   r
   r   )rX   r4   r   s      r   speechd_start_systemzConfigure.speechd_start_system  s     	qFGPq<=>Z[1PQRII:;1STU))ABCqORUUVW  1 . / 0QHI4PEq)*+r   c                    t        t        d      dddg      }|dk(  r#| j                          | j                  d       n#|dk(  r| j                  d       nt	        d      t        t        d      d      }|st        t        d             y	|dk(  r| j                         }n|dk(  r| j                         }st        t        d
             | j                  j                  || j                  g| j                  g      }| j                  j                  |       |s5t        t        d      d      }|r| j                  j                  |       y	y	y	)zJCreate a complete configuration, run diagnosis and if necessary, debuggingz?Do you want to create/setup a 'user' or 'system' configuration?r   r   r   r   zFDo you want to start/restart Speech Dispatcher now and run some tests?Tz-Your configuration is now done but not testedNz%Your Speech Dispatcher is not running)r   r   r   zODo you want to run debugging now and send a request for help to the developers?F)r9   r2   r<   r  r  r/   r   r  r  r   rC   r  r  r   r   )rX   speechd_typer4   startedresults        r   complete_configzConfigure.complete_config  sS    6OPVX&( 6!**,))v)6X%))x)89::cdfjk1DEFv%113)3351<=>&&040I0I/J262L2L1M ' O 			++F3Qpq"$E		***=  r   )r   )r   r   r   r   r  r  r  rY   r   r   r<   r  r  r  r"  r   r   r   r   r     sE    X 1.%`#RJFRP,2%>r   r   c                     t               } | j                         } | j                  a| j                  at	               }t        |      }| j                  st        t        d             | j                  r;|j                          t        t        d      d      }|r|j                  d       y y | j                  r|j                  d       y | j                  r|j                  d       y | j                  r|j                          y | j                  r|j                          y | j                   r|j!                          y | j"                  r|j%                  d       y | j&                  r|j%                  d       y | j(                  r"|j)                         }|j+                  |       y | j,                  r|j/                          y | j                  r|j                          y t        t        d	      d      }|r|j1                          y t        t        d
      d      }|r"|j)                         }|j+                  |       y t        t        d             y )Nz&
Speech Dispatcher configuration tool
z,Do you want to continue with basic settings?Tr   r   r   r   r   z4Do you want to setup a completely new configuration?z)Do you want to run diagnosis of problems?zwPlease run this command again and select what you want to do
or read the quick help available through '-h' or '--help'.)rQ   
parse_argsr&   r	   rS   r   rK   r   r2   r<   r/   r  rA   rB   rE   rD   rG   rH   r   rI   rC   r   rJ   r   r"  )r   r   	configurer4   r   s        r   mainr&    s    G  "GH"777D$I ??q;<=((++-IJDQ..F.; 		+	+***7		-	-***9												(			)			 &&s+		 QRTXY%%'QJKTRE$$&..s3q > ? @r   __main__)#rM   r   r   gettextlocaler
   r   r   rj   sysr   xdgr   r   r   	setlocaleLC_ALLbindtextdomainGETTEXT_PACKAGE	LOCALEDIR
textdomainr2   r	   r&   r   r   r/   r6   r9   rQ   rS   r   r&  r   exitr   r   r   <module>r3     s   (      	    
       #   33[5J5J K   ;.. /OO  2(
"BH"(Tb1 b1H> >H>@@ zCHHTV r   