
    ~ go                     ,    S SK r S SKJr   " S S5      rg)    N)sos_get_command_outputc                   `    \ rS rSrSr  SS jrS rS rS rSS jr	S	 r
S
 rS rS rS rSrg)
InitSystem   a  Encapsulates an init system to provide service-oriented functions to
sos.

This should be used to query the status of services, such as if they are
enabled or disabled on boot, or if the service is currently running.

:param init_cmd: The binary used to interact with the init system
:type init_cmd: ``str``

:param list_cmd: The list subcmd given to `init_cmd` to list services
:type list_cmd: ``str``

:param query_cmd: The query subcmd given to `query_cmd` to query the
                  status of services
:type query_cmd: ``str``

:param chroot:  Location to chroot to for any command execution, i.e. the
                sysroot if we're running in a container
:type chroot:   ``str`` or ``None``

Nc                     0 U l         Xl        U R                   SU 3=(       d    SU l        U R                   SU 3=(       d    SU l        X@l        g)zInitialize a new InitSystem() N)servicesinit_cmdlist_cmd	query_cmdchroot)selfr
   r   r   r   s        D/usr/lib/python3/dist-packages/sos/policies/init_systems/__init__.py__init__InitSystem.__init__&   sK      ==/8*5= MM?!I;7?4    c                 n    U R                   (       a$  XR                   ;   a  U R                   U   S   S:H  $ g)zCheck if given service name is enabled

:param name: The name of the service
:type name: ``str``

:returns: ``True`` if the service is enabled, else ``False``
:rtype: ``bool``
configenabledFr	   r   names     r   
is_enabledInitSystem.is_enabled1   s0     ==T]]2==&x0I==r   c                 n    U R                   (       a$  XR                   ;   a  U R                   U   S   S:H  $ g)zCheck if a given service name is disabled
:param name: The name of the service
:type name: ``str``

:returns: ``True`` if the service is disabled, else ``False``
:rtype: ``bool``
r   disabledFr   r   s     r   is_disabledInitSystem.is_disabled>   s0     ==T]]2==&x0J>>r   c                     XR                   ;   $ )zChecks if the given service name exists on the system at all, this
does not check for the service status

:param name: The name of the service
:type name: ``str``

:returns: ``True`` if the service exists, else ``False``
:rtype: ``bool``
r   r   s     r   
is_serviceInitSystem.is_serviceJ   s     }}$$r   c                     U$ )a\  Checks if the given service name is in a running state.

This should be overridden by initsystems that subclass InitSystem

:param name: The name of the service
:type name: ``str``

:param default: The default response in case the check fails
:type default:  ``bool`

:returns: ``True`` if the service is running, else ``default``
:rtype: ``bool``
 )r   r   defaults      r   
is_runningInitSystem.is_runningW   s	    $ r   c                     [         e)a  This loads all services known to the init system into a dict.
The dict should be keyed by the service name, and contain a dict of the
name and service status

This must be overridden by anything that subclasses `InitSystem` in
order for service methods to function properly
)NotImplementedError)r   s    r   load_all_servicesInitSystem.load_all_servicesk   s
     "!r   c                     U R                   (       a$   [        U R                    SU 3U R                  S9$ g! [         a     gf = f)zQuery an individual servicer   )r   N)r   r   r   	Exceptionr   s     r   _query_serviceInitSystem._query_serviceu   sN    >>-~~&av.;;    s   "7 
AAc                     U$ )a  Parses the output returned by the query command to make a
determination of what the state of the service is

This should be overriden by anything that subclasses InitSystem

:param output: The raw output from querying the service with the
               configured `query_cmd`
:type output: ``str``

:returns: A state for the service, e.g. 'active', 'disabled', etc...
:rtype: ``str``
r#   )r   outputs     r   parse_queryInitSystem.parse_query   s	     r   c                     [         R                  " U[         R                  5      nU R                   Vs/ s H  o2R	                  U5      (       d  M  UPM     sn$ s  snf )zGet a list of all services discovered on the system that match the
given regex.

:param regex: The service name regex to match against
:type regex: ``str``
)recompileIr	   match)r   regexregss       r   get_service_namesInitSystem.get_service_names   s<     jj%==9=aIIaL=999s   AAc                 0   USSS.nXR                   ;  a  U$ SU R                   U   ;   a  U R                   U   $ U R                  U5      nUbH  U R                  US   5      U R                   U   S'   US   U R                   U   S'   U R                   U   $ U$ )a  Get the status for the given service name along with the output
of the query command

:param name: The name of the service
:type name: ``str``

:returns: Service status and query_cmd output from the init system
:rtype: ``dict`` with keys `name`, `status`, and `output`
missing )r   statusr0   r@   r0   )r	   r-   r1   )r   r   _defaultsvcs       r   get_service_statusInitSystem.get_service_status   s     

 }}$Ot}}T**==&&!!$'?,0,<,<S],KDMM$),/MDMM$)==&&r   )r   r
   r   r   r	   )NNNN)T)__name__
__module____qualname____firstlineno____doc__r   r   r   r    r%   r)   r-   r1   r;   rC   __static_attributes__r#   r   r   r   r      sC    , @D	

%("
:r   r   )r4   sos.utilitiesr   r   r#   r   r   <module>rL      s    
 0d dr   