ó
šßÈ[c           @` s‘   d  d l  m Z m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d d l	 m
 Z
 m Z d d l m Z d g Z d  d „ Z d S(	   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   logt   __version__i   (   t   SAMPHubServeru   mainc         C` sñ  t  j d d t ƒ } | j d d d d d d d	 d
 ƒ| j d d d d d d d	 d ƒ| j d d d d d d d t d	 d ƒ| j d d d d d d d	 d ƒ| j d d d d d d d	 d  d! t ƒ| j d" d# d d$ d d% d t d	 d& d! d' ƒ| j d( d) ƒ } | j d* d+ d d, d d- d	 d. d t d! d/ ƒ| j d0 d1 d d2 d d- d	 d3 d t d! d/ ƒ| j | ƒ | j d4 d5 ƒ } | j d6 d7 d d8 d d9 d	 d: d t d; d< d= d> d? d@ g d! d? ƒ| j dA dB d dC d d d	 dD d! dE ƒ| j | ƒ | j dF dG ƒ } | j dH dI d dJ d dK d	 dL d! dE ƒ| j dM dN d dO d	 dP d dQ dR dS d! dT ƒ| j | ƒ | j ƒ  } yì | j	 d[ k r¥t
 j | j	 ƒ n  | j dE k rÉt
 j | j ƒ } n dU t f dV „  ƒ  Y} | ƒ  } | { t j | j ƒ } | d8 =| dC =t |   }	 |	 j t ƒ |  sNx4 |	 j rJt j dW ƒ q1Wn t j |  ƒ |	 j ƒ  WdX QXWn~ t k
 r¡y |	 j ƒ  Wqít k
 rqíXnL t k
 rÜ}
 t dY j |
 j |
 j ƒ ƒ t  j! dZ ƒ n t" k
 rìn XdX S(\   uO   
    This main function is executed by the ``samp_hub`` command line tool.
    t   progu	   samp_hub u   -ku   --secrett   destu   secrett   metavaru   CODEt   helpu   custom secret code.u   -du   --addru   addru   ADDRu   listening address (or IP).u   -pu   --portu   portu   PORTt   typeu   listening port number.u   -fu
   --lockfileu   lockfileu   FILEu   custom lockfile.u   -wu   --no-web-profileu   web_profilet   actionu   store_falseu&   run the Hub disabling the Web Profile.t   defaultu   -Pu   --pool-sizeu	   pool_sizeu   SIZEu!   the socket connections pool size.i   u   Timeout groupup  Special options to setup hub and client timeouts.It contains a set of special options that allows to set up the Hub and clients inactivity timeouts, that is the Hub or client inactivity time interval after which the Hub shuts down or unregisters the client. Notification of samp.hub.disconnect MType is sent to the clients forcibly unregistered for timeout expiration.u   -tu	   --timeoutu   timeoutu   SECONDSud   set the Hub inactivity timeout in SECONDS. By default it is set to 0, that is the Hub never expires.i    u   -cu   --client-timeoutu   client_timeoutuj   set the client inactivity timeout in SECONDS. By default it is set to 0, that is the client never expires.u   Logging optionsuD  Additional options which allow to customize the logging output. By default the SAMP Hub uses the standard output and standard error devices to print out INFO level logging messages. Using the options here below it is possible to modify the logging level and also specify the output files where redirect the logging messages.u   -Lu   --log-levelu   loglevelu   LEVELuB   set the Hub instance log level (OFF, ERROR, WARNING, INFO, DEBUG).t   choicesu   OFFu   ERRORu   WARNINGu   INFOu   DEBUGu   -Ou   --log-outputu   logoutu)   set the output file for the log messages.u    u   Advanced groupu„  Advanced options addressed to facilitate administrative tasks and allow new non-standard Hub behaviors. In particular the --label options is used to assign a value to hub.label token and is used to assign a name to the Hub instance. The very special --multi option allows to start a Hub in multi-instance mode. Multi-instance mode is a non-standard Hub behavior that enables multiple contemporaneous running Hubs. Multi-instance hubs place their non-standard lock-files within the <home directory>/.samp-1 directory naming them making use of the format: samp-hub-<PID>-<ID>, where PID is the Hub process ID while ID is an internal ID (integer).u   -lu   --labelu   labelu   LABELu   assign a LABEL to the Hub.u   -mu   --multiu   modeuS   run the Hub in multi-instance mode generating a custom lockfile with a random name.u   store_constt   constu   multipleu   singlet   dummy_contextc           B` s   e  Z d  „  Z d „  Z RS(   c         S` s   d  S(   N(    (   t   self(    (    s6   lib/python2.7/site-packages/astropy/samp/hub_script.pyt	   __enter__p   s    c         S` s   d  S(   N(    (   R   t   exc_typet	   exc_valuet	   traceback(    (    s6   lib/python2.7/site-packages/astropy/samp/hub_script.pyt   __exit__s   s    (   t   __name__t
   __module__R   R   (    (    (    s6   lib/python2.7/site-packages/astropy/samp/hub_script.pyR   n   s   	g{®Gáz„?Nu!   [SAMP] Error: I/O error({0}): {1}i   (   u   OFFu   ERRORu   WARNINGu   DEBUGu   INFO(#   t   argparset   ArgumentParserR   t   add_argumentt   intt   Truet   add_argument_groupt   strt
   parse_argst   loglevelR   t   setLevelt   logoutt   log_to_filet   objectt   copyt   deepcopyt   __dict__R   t   startt   Falset
   is_runningt   timet   sleept   stopt   KeyboardInterruptt	   NameErrort   IOErrort   printt   formatt   errnot   strerrort   syst   exitt
   SystemExit(   t   timeoutt   parsert   timeout_groupt	   log_groupt	   adv_groupt   optionst   contextR   t   argst   hubt   e(    (    s6   lib/python2.7/site-packages/astropy/samp/hub_script.pyt
   hub_script   s†    !!				"			(   t
   __future__R    R   R   R   R&   R,   R6   R   t    R   R   RA   R   t   __all__RC   (    (    (    s6   lib/python2.7/site-packages/astropy/samp/hub_script.pyt   <module>   s   "	