ó
žS]c           @@  sb   d  Z  d d l m Z d d l Z d d l m Z d
 Z e d Z d Z d e f d	     YZ	 d S(   s4   Project "local state" file loading and manipulation.i    (   t   absolute_importN(   t   YamlFiles   anaconda-project-local.ymls   anaconda-project-local.yamlt   service_run_statest   LocalStateFilec           B@  s>   e  Z d  Z d Z e d    Z d   Z d   Z d   Z RS(   su  Represents the locally-configured/user-specific state of the project directory.

    Project config that you might want in source control should be
    in ``ProjectFile`` instead.

    Be careful with creating your own instance of this class,
    because you have to think about when other code might load or
    save in a way that conflicts with your loads and saves.
    sQ   
# Anaconda local project state (specific to this user/machine)
__dummy__: dummy
c         C@  s[   x? t  D]7 } t j j | |  } t j j |  r t |  Sq Wt t j j | t   S(   se  Load the project local state file from the given directory, even if it doesn't exist.

        If the directory has no project file, the loaded
        ``LocalStateFile`` will be empty. It won't actually be
        created on disk unless you call ``save()``.

        If the local state file has syntax problems, the
        ``corrupted`` and ``corrupted_error_message`` properties
        will be set and attempts to modify or save the file will
        raise an exception.

        Args:
            directory (str): path to the project directory

        Returns:
            a new ``LocalStateFile``

        (   t   possible_local_state_file_namest   ost   patht   joint   isfileR   t   DEFAULT_LOCAL_STATE_FILENAME(   t   clst	   directoryt   nameR   (    (    s@   lib/python2.7/site-packages/anaconda_project/local_state_file.pyt   load_for_directory)   s
    c         C@  s8   t  | t  s t d   n  |  j t | g |  d S(   sŅ  Set a dict value in the ``service_run_states`` section.

        This is used to save the state of a running service, such as
        its port or process ID.

        Conventionally the state can also include a
        ``shutdown_commands`` property with a list of list of
        strings value. The lists of strings are args to pass to
        exec. In order to shut down a service, we run all
        ``shutdown_commands`` and then delete the entire service
        run state dict.

        This method does not save the file, call ``save()`` to do that.

        Args:
            service_name (str): environment variable identifying the service
            state (dict): state for the running service process
        s   service state should be a dictN(   t
   isinstancet   dictt
   ValueErrort	   set_valuet   SERVICE_RUN_STATES_SECTION(   t   selft   service_namet   state(    (    s@   lib/python2.7/site-packages/anaconda_project/local_state_file.pyt   set_service_run_stateC   s    c         C@  s   |  j  t | g d t   S(   sâ   Get the running instance state for a service.

        Args:
            service_name (str): environment variable identifying the service

        Returns:
            The state dict (empty dict if no state was saved)
        t   default(   t	   get_valueR   R   (   R   R   (    (    s@   lib/python2.7/site-packages/anaconda_project/local_state_file.pyt   get_service_run_stateZ   s    	c         C@  s   |  j  t d t   S(   sģ   Get all saved service run states.

        Returns the entire ``service_run_states`` section.

        Returns:
            a dict from service name to service state dict
        R   (   R   R   R   (   R   (    (    s@   lib/python2.7/site-packages/anaconda_project/local_state_file.pyt   get_all_service_run_statese   s    (	   t   __name__t
   __module__t   __doc__t   templatet   classmethodR   R   R   R   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/local_state_file.pyR      s   			(   s   anaconda-project-local.ymls   anaconda-project-local.yaml(
   R   t
   __future__R    R   t   anaconda_project.yaml_fileR   R   R	   R   R   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/local_state_file.pyt   <module>   s   
