
    S`                        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 d dlmZ d dlZd dlZddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl m"Z" ddlm#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ ddl*m,Z, ddl*m-Z- ddl*m.Z. ddl*m/Z/ ddl0m1Z1 ddl0m2Z2 ddl0m3Z3 ddl0m4Z4 dd l0m5Z5 dd!l0m6Z6 dd"l7m8Z8 dd#l9m:Z: dd$l;m<Z< dd%l;m=Z= dd&l;m>Z> dd'l?m@Z@ dd(l?mAZA dd)l?mBZB dd*lmCZC dd+lDmEZE dd,lDmFZF dd-lGmHZH dd.lGmIZI dd/l7mJZJ dd0l7mKZK dd1l7mLZL d d2lMmNZN d d3lMmOZO e"s
d d4lPmQZQmRZRmSZS  ej                  eU      ZVd5 ZWd6 ZXdeOj                  dfd7ZZd8 Z[d9 Z\d: Z]d; Z^dWd<Z_d= Z` G d> d?      Zad@ ZbdA ZcdB ZddC ZedD ZfdE ZgdF ZhdG ZidH ZjdI ZkdJ Zl	 	 	 dXdKZmdYdLZne j                  dM        ZpdN ZqdO ZrdP ZsdQ ZtdR ZudS ZvdT ZwdU ZxdV Zyy)Z    N)find_executable)getdoc)
attrgetter   )errors)signals   )__version__)ConfigurationError)parse_environment)parse_labels)resolve_build_args)Environment)serialize_config)
VolumeSpec)IS_LINUX_PLATFORM)IS_WINDOWS_PLATFORM)StreamParseError)metrics)ParallelStreamWriter)StreamOutputError)get_image_digests)MissingDigests)NoSuchService)OneOffFilter)ProjectError)BuildAction)
BuildError)ConvergenceStrategy)	ImageType)NeedsBuildError)OperationFailedErrorfilter_attached_for_up)AnsiMode)get_config_from_options)get_project_dir)project_from_options)DocoptDispatcher)get_handler)NoSuchCommand	UserError)ConsoleWarningFormatter)	Formatter)build_log_presenters)
LogPrinter)get_version_info)human_readable_file_size)yesno)MetricsCommand)Status)PseudoTerminalRunOperationExecOperationc            	         t        j                          d } 	 t        j                  t        t        t        j                  dd        dt        d      d      \  }}} 	 t               } |        t        s| dk(  rt        d       y y y # t        $ r Y 6w xY w# t        t         j                  f$ r t        | dt         j"                         Y y t$        t&        t(        t*        t,        f$ r0}t        | |j.                  t         j0                         Y d }~y d }~wt2        $ rg}d	}|j4                  rd
|j4                  z   }t        | dj7                  |j8                  j:                  |      t         j0                         Y d }~y d }~wt<        $ r&}t        | |t         j0                         Y d }~y d }~wt>        $ rI}t        | dj7                  |j8                  j:                        t         j0                         Y d }~y d }~wt@        $ ry}djC                  tE        dtG        |jH                                    }t        s|dz  }t        d	dj7                  |jJ                  |      t         j0                         Y d }~y d }~wtL        jN                  tP        f$ r t        | t         j0                         Y y tR        $ r1}t         jT                  }tW        t        j                        dkD  r"dt        j                  vrt         j0                  }| r7tW        t        j                        dk\  rt        j                  d   dk(  rd| z   } | s4tW        t        j                        dk\  rt        j                  d   dk(  rd} tW        |jX                        r|jX                  d   nd	}d}	t[        |j\                  t^              r|j\                  }	t        s| s|dz  }t        | |||	       Y d }~y d }~ww xY w)Nr   Tcomposeoptions_firstversionhelpzC
Docker Compose is now in the Docker CLI, try `docker compose` helpz	Aborting.status z : zService '{}' failed to build{}z:Service '{}' needs to be built, but --no-build was passed.
z	commands:z?

Docker Compose is now in the Docker CLI, try `docker compose`zNo such command: {}

{})log_msgrA   --help   r	   z--help r   )rD   rA   	exit_code)0r   ignore_sigpiper)   get_command_and_optionsTopLevelCommandget_filtered_argssysargvr2   	Exceptiondispatchr   printKeyboardInterruptShutdownExceptionexit_with_metricsr6   CANCELEDr-   r   r   r   r"   msgFAILUREr   reasonformatservicenamer   r!   r+   joinparse_doc_sectionr   supercommandcommandr   ConnectionErrorr   
SystemExitSUCCESSlenargs
isinstancecodeint)
r^   _optscommand_funcerW   commandsrA   rU   re   s
             2/usr/lib/python3/dist-packages/compose/cli/main.pymainrm   E   s   G+CCchhqrl+"/?	/JKM43*z W%6XY &7    w889 H';vG}&8.0 A'155@@ 188QXX%F':AA!))..RXY!'	1 	1  ='1V^^<< F'V]]iinn.6<nn	F 	F  999.{F1>><RST [[H"&A&H&HIIx'!)/	9 	9""$45 :'&..9 *sxx=1!9^^Fs388})chhqkX.E')G3sxx=A-#((1+2IGqvv;affQiBaffc"66D VVC'3v$(	* 	*'*su   AB 'B 	BB5O4O4+&DO4"AFO4F11O4=?HO4A/J7O4:	O4D'O//O4c                 ,    | d   dv rg S | d   dk(  rdgS y )Nr   )z-hrE   z	--versionr>    )rc   s    rl   rK   rK      s-    Aw""	Aw+{     c                     |r2| dk7  r-|st         j                  |       nt         j                  |       t        | |      j	                          t        j                  |       y )Nexecr@   )loginfoerrorr5   send_metricsrL   exit)r^   rD   rA   rG   s       rl   rS   rS      sF    7f$HHWIIg76*779HHYrp   c            
         t         j                  } t        j                  |       }t	        |       t        t        dt        d      d      }|j                  t         j                  dd        \  }}}t        j                  }	 |j                  d      rt        |j                  d            }|j                  d	      rA|j                  d      rt        d
      t"        j%                  d       t        j&                  }t)        ||j                  d      |j+                  |j,                        |j                  d             t/        |       |t        j&                  u rd|d<   t1        j2                  t4        |||      S # t        $ rE t        dj                  |j                  d      dj!                  d t        D                          w xY w)NTr;   r<   r   z--ansiz1Invalid value for --ansi: {}. Expected one of {}., c              3   4   K   | ]  }|j                     y wN)value).0ms     rl   	<genexpr>zdispatch.<locals>.<genexpr>   s     4a!''4   z	--no-ansiz(--no-ansi and --ansi cannot be combined.zb--no-ansi option is deprecated and will be removed in future versions. Use `--ansi never` instead.z	--verbosez--log-level
--no-color)rL   stderrloggingStreamHandlersetup_loggingr)   rJ   r2   parserM   r%   AUTOget
ValueErrorr-   rX   r[   rs   warningNEVERsetup_console_handleruse_ansi_codesstreamsetup_parallel_logger	functoolspartialperform_command)console_streamconsole_handler
dispatcheroptionshandlercommand_options	ansi_modes          rl   rO   rO      s   ZZN++N;O/"!+;I+FGIJ )3(8(8!"(F%GWoI	
;;x  X!67I {{;;;x FGG 2 	3NN	/!++k2#22?3I3IJ!++m46 )$HNN"(,%_gwPP+  
?FFH%		4844
 	

s   +F AGc                    | d   dv r	 ||       y | d   dk(  rt        d |       } |||       y t        d|       }t        ||       }t        j                  |j                        5   |||       d d d        y # 1 sw Y   y xY w)NCOMMAND)r?   r>   configr   .)rJ   r(   r   handle_connection_errorsclient)r   r   r   r^   projects        rl   r   r      s    y00 yX%!$8)"30Ggw7G		(	(	8 *)* * *s   (
A;;Bc                 (   t        j                         }|j                  |        |j                  t         j                         dt        j                  d      _        dt        j                  d      _        dt        j                  d      _        y )NFurllib3requestsdocker)r   	getLogger
addHandlersetLevelDEBUG	propagate)r   root_loggers     rl   r   r      sk    ##%K?+' .3Gi *.3Gj!+,1Gh)rp   c                 .    t        j                  |        y r{   )r   set_default_ansi_mode)r   s    rl   r   r      s    ..y9rp   c                    |rt         }nt        j                  }|r(| j                   |d             t        j                  }n&| j                   |              t        j
                  }|zt        j                  t        j
                  t        j                  t        j                  t        j                  d}|j                  |j                               }|t        d      | j                  |       y )Nz"%(name)s.%(funcName)s: %(message)s)r   INFOWARNINGERRORCRITICALzUInvalid value for --log-level. Expected one of DEBUG, INFO, WARNING, ERROR, CRITICAL.)r.   r   r/   setFormatterr   r   r   r   r   r   upperr-   r   )r   verboseuse_console_formatterlevelformat_classloglevellevelss          rl   r   r      s    .((\*NOP==\^,<<]]LL]]((
 ::ekkm,g  Xrp   c                     t        j                  d| z   dz   t         j                  t         j                  z        }|j	                  |      D cg c]  }|j                          c}S c c}w )Nz^([^
]*z[^
]*
?(?:[ 	].*?(?:
|$))*))recompile
IGNORECASE	MULTILINEfindallstrip)rZ   sourcepatternss       rl   r\   r\      sP    jjd*-NN57G&v67!AGGI777s   A)c                      e Zd ZdZd dZed        Zed        Z e       d        Z	 e       d        Z
 e       d        Z e       d	        Zd
 Z ed      d        Ze e       d               Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z e       d        Z  e       d        Z!e e       d               Z"y)!rJ   a8  Define and run multi-container applications with Docker.

    Usage:
      docker-compose [-f <arg>...] [--profile <name>...] [options] [--] [COMMAND] [ARGS...]
      docker-compose -h|--help

    Options:
      -f, --file FILE             Specify an alternate compose file
                                  (default: docker-compose.yml)
      -p, --project-name NAME     Specify an alternate project name
                                  (default: directory name)
      --profile NAME              Specify a profile to enable
      -c, --context NAME          Specify a context name
      --verbose                   Show more output
      --log-level LEVEL           Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
      --ansi (never|always|auto)  Control when to print ANSI control characters
      --no-ansi                   Do not print ANSI control characters (DEPRECATED)
      -v, --version               Print version and exit
      -H, --host HOST             Daemon socket to connect to

      --tls                       Use TLS; implied by --tlsverify
      --tlscacert CA_PATH         Trust certs signed only by this CA
      --tlscert CLIENT_CERT_PATH  Path to TLS certificate file
      --tlskey TLS_KEY_PATH       Path to TLS key file
      --tlsverify                 Use TLS and verify the remote
      --skip-hostname-check       Don't check the daemon's hostname against the
                                  name specified in the client certificate
      --project-directory PATH    Specify an alternate working directory
                                  (default: the path of the Compose file)
      --compatibility             If set, Compose will attempt to convert keys
                                  in v3 files to their non-Swarm equivalent (DEPRECATED)
      --env-file PATH             Specify an alternate environment file

    Commands:
      build              Build or rebuild services
      config             Validate and view the Compose file
      create             Create services
      down               Stop and remove resources
      events             Receive real time events from containers
      exec               Execute a command in a running container
      help               Get help on a command
      images             List images
      kill               Kill containers
      logs               View output from containers
      pause              Pause services
      port               Print the public port for a port binding
      ps                 List containers
      pull               Pull service images
      push               Push service images
      restart            Restart services
      rm                 Remove stopped containers
      run                Run a one-off command
      scale              Set number of containers for a service
      start              Start services
      stop               Stop services
      top                Display the running processes
      unpause            Unpause services
      up                 Create and start containers
      version            Show version information and quit
    Nc                 (    || _         |xs i | _        y r{   )r   toplevel_options)selfr   r   s      rl   __init__zTopLevelCommand.__init__@  s     '2rp   c                 ,    t        | j                        S r{   )r'   r   )r   s    rl   project_dirzTopLevelCommand.project_dirD  s    t4455rp   c                 x    | j                   j                  d      }t        j                  | j                  |      S )Nz
--env-file)r   r   r   from_env_filer   )r   environment_files     rl   toplevel_environmentz$TopLevelCommand.toplevel_environmentH  s3    0044\B(()9)9;KLLrp   c                    |d   }|j                  dd      }|ra|sIt        j                  j                  | j                  j
                  j                  d      rt        d      t        || j                        }| j                  j                  dd      }| j                  j                  |d   t        |j                  dd	            t        |j                  d
d	            t        |j                  dd	            |j                  d      t        |j                  dd	             ||j                  dd	      |j                  dd	      |j                  dd	      ||j                  d             y)a  
        Build or rebuild services.

        Services are built once and then tagged as `project_service`,
        e.g. `composetest_db`. If you change a service's `Dockerfile` or the
        contents of its build directory, you can run `docker-compose build` to rebuild it.

        Usage: build [options] [--build-arg key=val...] [--] [SERVICE...]

        Options:
            --build-arg key=val     Set build-time variables for services.
            --compress              Compress the build context using gzip.
            --force-rm              Always remove intermediate containers.
            -m, --memory MEM        Set memory limit for the build container.
            --no-cache              Do not use cache when building the image.
            --no-rm                 Do not remove intermediate containers after a successful build.
            --parallel              Build images in parallel.
            --progress string       Set type of progress output (auto, plain, tty).
            --pull                  Always attempt to pull a newer version of the image.
            -q, --quiet             Don't print anything to STDOUT
        SERVICEz--build-argN1.25z--build-arg is only supported when services are specified for API version < 1.25. Please use a Compose file version > 2.2 or specify which services to build.COMPOSE_DOCKER_CLI_BUILDTz
--no-cacheFz--pullz
--force-rmz--memoryz--no-rmz
--compress
--parallel--quietz
--progress)service_namesno_cachepullforce_rmmemoryrm
build_argsgzipparallel_buildsilentcliprogress)r   r   utils
version_ltr   r   api_versionr-   r   r   get_booleanbuildbool)r   r   r   r   native_builders        rl   r   zTopLevelCommand.buildM  s?   .  	*[[5
 V\\%<%<T\\=P=P=\=\^d%ec  ,J8Q8QRJ22>>?Y[_`!),'++lE:;gkk(E23'++lE:;;;z*Iu566!\51";;|U;;;y%0[[. 	 	
rp   c                    d|j                  d      i}t        d| j                  |      }d}|d   rct        d| j                  |      | _        t        j                  | j                  j                        5  t        | j                        }ddd       |d   ry|d   r_t               }|j                  D ]"  }d|v s|d   D ]  }|j                  |        $ t        dj                  t        |                   y|d	   r,t        dj                  d
 |j                  D                     y|d   r,t        dj                  d |j                  D                     y|d   |d   }t        d| j                  |      | _        |dk7  r"|d   j!                  d      D 	cg c]  }	|	 c}	nd}
t        j                  | j                  j                        5  | j                  j#                  |
      D ]1  }t        dj%                  |j&                  |j(                               3 	 ddd       yt        t+        |||d                 y# 1 sw Y   xY wc c}	w # 1 sw Y   yxY w)ac  
        Validate and view the Compose file.

        Usage: config [options]

        Options:
            --resolve-image-digests  Pin image tags to digests.
            --no-interpolate         Don't interpolate environment variables.
            -q, --quiet              Only validate the configuration, don't print
                                     anything.
            --profiles               Print the profile names, one per line.
            --services               Print the service names, one per line.
            --volumes                Print the volume names, one per line.
            --hash="*"               Print the service config hash, one per line.
                                     Set "service1,service2" for a list of specified services
                                     or use the wildcard symbol to display all services.
        z--no-interpolater   Nz--resolve-image-digestsr   z
--profilesprofilesrC   
--servicesc              3   &   K   | ]	  }|d      yw)rZ   Nro   r}   rY   s     rl   r   z)TopLevelCommand.config.<locals>.<genexpr>  s     SGFOSs   	--volumesc              3       K   | ]  }|  y wr{   ro   )r}   volumes     rl   r   z)TopLevelCommand.config.<locals>.<genexpr>  s     HvFHs   z--hash*,z{} {})r   r&   r   r(   r   r   r   r   image_digests_for_projectsetservicesaddrP   r[   sortedvolumessplitget_servicesrX   rZ   config_hashr   )r   r   additional_optionscompose_configimage_digestsr   rY   profilehsvcr   s              rl   r   zTopLevelCommand.config  s>   ( 1'++>P2QR0d6K6KM_`,-/T5J5JL^_DL001D1DE H 9$,, GH 9< uH)22 .(#*:#6 . W-.. $))F8,-.< $))S>;R;RSST;$))H1G1GHHI8(!A/T5J5JL^_DLHISwx'8'>'>s'CDDVZH001D1DE M#||88B MG'..w7J7JKLMM ~}'J\B]>]^_AH H4 EM s   7I"	IAI I I)c                     |d   }t         j                  d       | j                  j                  |t	        |      t        |             y)a  
        Creates containers for a service.
        This command is deprecated. Use the `up` command with `--no-start` instead.

        Usage: create [options] [SERVICE...]

        Options:
            --force-recreate       Recreate containers even if their configuration and
                                   image haven't changed. Incompatible with --no-recreate.
            --no-recreate          If containers already exist, don't recreate them.
                                   Incompatible with --force-recreate.
            --no-build             Don't build an image, even if it's missing.
            --build                Build images before creating containers.
        r   zVThe create command is deprecated. Use the up command with the --no-start flag instead.)r   strategydo_buildN)rs   r   r   createconvergence_strategy_from_optsbuild_action_from_opts)r   r   r   s      rl   r  zTopLevelCommand.create  sL       	*C	

 	'3G<+G4 	 	
rp   c                     | j                   j                  d      }|r|d   rt        d      t        d|d         }t	        |      }| j
                  j                  ||d   |d   ||       y)a  
        Stops containers and removes containers, networks, volumes, and images
        created by `up`.

        By default, the only things removed are:

        - Containers for services defined in the Compose file
        - Networks defined in the `networks` section of the Compose file
        - The default network, if one is used

        Networks and volumes defined as `external` are never removed.

        Usage: down [options]

        Options:
            --rmi type              Remove images. Type must be one of:
                                      'all': Remove all images used by any service.
                                      'local': Remove only images that don't have a
                                      custom tag set by the `image` field.
            -v, --volumes           Remove named volumes declared in the `volumes`
                                    section of the Compose file and anonymous volumes
                                    attached to containers.
            --remove-orphans        Remove containers for services not defined in the
                                    Compose file
            -t, --timeout TIMEOUT   Specify a shutdown timeout in seconds.
                                    (default: 10)
        COMPOSE_IGNORE_ORPHANS--remove-orphans?COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined.z--rmir   )timeoutignore_orphansN)r   r   r-   image_type_from_opttimeout_from_optsr   down)r   r   r  
image_typer  s        rl   r  zTopLevelCommand.down  s~    : 22>>?WXg&89]^^(''2BC
#G,K &') 	 	+rp   c                     d }d }| j                   j                         D ]:  }|d   r|n|}t         ||             t        j                  j                          < y)z
        Receive real time events from containers.

        Usage: events [options] [--] [SERVICE...]

        Options:
            --json      Output events as a stream of json objects
        c           	          | d   j                         D cg c]  }d|z  	 }} dj                  dddj                  t        |            i| S c c}w )N
attributesz%s=%sz%{time} {type} {action} {id} ({attrs})attrsry   ro   )itemsrX   r[   r   )eventitemr  s      rl   format_eventz,TopLevelCommand.events.<locals>.format_event  sa    5:<5H5N5N5PQT'D.QJQC;CC iiz 23  Rs   Ac                 z    | d   j                         | d<   | j                  d       t        j                  |       S )Ntime	container)	isoformatpopjsondumps)r  s    rl   json_format_eventz1TopLevelCommand.events.<locals>.json_format_event  s3    !&M335E&MIIk"::e$$rp   z--jsonN)r   eventsrP   rL   stdoutflush)r   r   r  r!  r  	formatters         rl   r"  zTopLevelCommand.events  sV    		%
 \\((* 	E-4X->)LI)E"#JJ	rp   rr   c           	         | j                   j                  d       }t        |j                  d            }| j                  j                  |d         }|j                  d      }|d   rjt        j                  j                  | j                  j                  j                  d      r,t        d| j                  j                  j                  z        |d   rjt        j                  j                  | j                  j                  j                  d	      r,t        d
| j                  j                  j                  z        	 |j                  |      }|d   g|d   z   }|d    }	t        s|rK|sIt!        j"                  t%        t'        ||j(                  |      | j*                  | j                                |d   |d   |	d|d   d}
t        j                  j-                  | j                  j                  j                  d      r|d   |
d<    |j.                  |fi |
}|r|j1                  ||	d       yt3        j4                          	 t7        | j                  j                  ||	      }t9        | j                  j                  |      }|j;                          | j                  j                  jC                  |      j                  d      }t!        j"                  |       y# t        $ r}t        t        |            d}~ww xY w# t2        j<                  $ r t>        jA                  d       Y w xY w)a]  
        Execute a command in a running container

        Usage: exec [options] [-e KEY=VAL...] [--] SERVICE COMMAND [ARGS...]

        Options:
            -d, --detach      Detached mode: Run command in the background.
            --privileged      Give extended privileges to the process.
            -u, --user USER   Run the command as this user.
            -T                Disable pseudo-tty allocation. By default `docker-compose exec`
                              allocates a TTY.
            --index=index     index of the container if there are multiple
                              instances of a service [default: 1]
            -e, --env KEY=VAL Set environment variables (can be used multiple times,
                              not supported in API < 1.25)
            -w, --workdir DIR Path to workdir directory for this command.
        COMPOSE_INTERACTIVE_NO_CLI--indexr   --detach--envr   z@Setting environment for exec is not supported in API < 1.25 (%s)	--workdirz1.35z<Setting workdir for exec is not supported in API < 1.35 (%s)numberNr   ARGS-T--privileged--userT)
privilegeduserttystdinworkdirenvironment)r4  r   )interactivez$received shutdown exception: closingExitCode)"r   r   rf   r   r   get_servicer   r   r   r   r   r-   get_containerr   strr   rL   rw   call_dockerbuild_exec_commandidr   version_gtecreate_exec
start_execr   set_signal_handler_to_shutdownr9   r7   startrR   rs   rt   exec_inspect)r   r   use_cliindexrY   detachr  rj   r^   r4  create_exec_optionsexec_id	operationptyrG   s                  rl   exec_commandzTopLevelCommand.exec_command  s   & //;;<XYYGKK	*+,,**79+=>Z(7 7 78K8K8W8WY_ `^"ll11==> ? ? ;FLL$;$;DLL<O<O<[<[]c$dZ"ll11==> ? ?	$--U-;I 9%&8$-'&HH["7ILL'B%%t'@'@B  ".1H%{+
 <<##DLL$7$7$C$CVL181A.')''G3FG  c$ ?..0		=%##I
 !!4!4i@CIIK LL''44W=AA*M	Q  	$CF##	$J (( 	=HH;<	=s+   K. AL .	L7LL(L>=L>c                 Z    |d   rt        | |d         }n| }t        t        |             y)zG
        Get help on a command.

        Usage: help [COMMAND]
        r   N)r*   rP   r   )clsr   subjects      rl   r?   zTopLevelCommand.helpi  s.     9!#wy'9:GGfWorp   c                 P   t        | j                  j                  |d   d      | j                  j                  |d   t        j                        z   t        d            }|d   r=|D ch c]  }|j                   c}D ]  }t        |j                  d      d	          ! y
d }g d}g }|D ]  }|j                  }	| j                  j                  |j                        }
d} ||
j                        }||	d   v r|	d   j                  |      }|	d   r|	d   |   j                  dd	      nd}|	d   j                  d      d	   d
d }t        |	d         }|j!                  |j"                  |d   |d	   ||g        t        t%        j&                  ||             y
c c}w )z
        List images used by the created containers.
        Usage: images [options] [--] [SERVICE...]

        Options:
            -q, --quiet  Only display IDs
        r   Tr   stoppedr   one_offrZ   keyr   :r   Nc                 T    d| j                  d      d   vrdj                  |       S | S )NrX  /z	{}:latest)r   rX   )img_names    rl   add_default_tagz/TopLevelCommand.images.<locals>.add_default_tag  s.    (..-b11"))(33Orp   )	Container
RepositoryTagzImage IdSizer   RepoTags)<none>rc  Id   ra  )r   r   
containersr   onlyr   imagerP   r   image_configr:  rY   
image_namerG  rsplitr3   appendrZ   r/   table)r   r   rf  crh  r]  headersrowsr  ri  rY   rG  r\  	repo_tagsimage_idsizes                   rl   imageszTopLevelCommand.imagesx  s    LL##')2Dd#SLL##')2DlN_N_#`a6"$

 9+56a!''6 +ekk#&q)*+	

 # 	I$11Lll..y/@/@AGE&w'9'9:H<
33$Z066x@BNzBZZ(/66sA>) 
 $D)//4Q7<H+L,@ADKK!! 	* 	ioogt,-M 7s   -F#c                 h    |j                  dd      }| j                  j                  |d   |       y)z
        Force stop service containers.

        Usage: kill [options] [--] [SERVICE...]

        Options:
            -s SIGNAL         SIGNAL to send to the container.
                              Default signal is SIGKILL.
        z-sSIGKILLr   )r   signalN)r   r   kill)r   r   rw  s      rl   rx  zTopLevelCommand.kill  s0     T9-	(:6Jrp   c           
         | j                   j                  |d   d      }|d   }|,|j                         rt        |      }n|dk7  rt	        d      |d   ||d	   d
}t        dt        |             t        | j                   ||d   || j                   j                  |d         |d          j                          y)a  
        View output from containers.

        Usage: logs [options] [--] [SERVICE...]

        Options:
            --no-color              Produce monochrome output.
            -f, --follow            Follow log output.
            -t, --timestamps        Show timestamps.
            --tail="all"            Number of lines to show from the end of the logs
                                    for each container.
            --no-log-prefix         Don't print prefix in logs.
        r   TrR  z--tailNallz!tail flag must be all or a numberz--followz--timestamps)followtail
timestampsAttaching tor   r   --no-log-prefixevent_streamkeep_prefix)
r   rf  isdigitrf   r-   rP   list_containerslog_printer_from_projectr"  run)r   r   rf  r|  log_argss        rl   logszTopLevelCommand.logs  s     \\,,79;MW[,\
x ||~4y CDDj)!.1

 	noj9: LLL!,,79;M,N#$566	8 9<rp   c                 ^    | j                   j                  |d         }t        | dd       y)zD
        Pause services.

        Usage: pause [SERVICE...]
        r   r  zNo containers to pauser   N)r   pauseexit_ifr   r   rf  s      rl   r  zTopLevelCommand.pause  /     \\''gi6H'I
J 8!<rp   c                 P   t        |j                  d            }| j                  j                  |d         }	 |j	                  |      }t        |j                  |d   |j                  d      xs d      xs d	       y# t
        $ r}t        t        |            d}~ww xY w)
aK  
        Print the public port for a port binding.

        Usage: port [options] [--] SERVICE PRIVATE_PORT

        Options:
            --protocol=proto  tcp or udp [default: tcp]
            --index=index     index of the container if there are multiple
                              instances of a service [default: 1]
        r(  r   r,  NPRIVATE_PORTz
--protocoltcp)protocolrB   )
rf   r   r   r:  r;  r   r-   r<  rP   get_local_port)r   r   rG  rY   r  rj   s         rl   portzTopLevelCommand.port  s     GKK	*+,,**79+=>	$--U-;I 	i&&N#[[.7% ' 9 ?<>	@  	$CF##	$s   B 	B%B  B%c                    |d   r|d   rt        d      |d   rkt        |j                  d            }| j                  j                  }|rt        ||| j                        }t        dj                  d |D                     y|d   rDt        | j                  j                  |d	   t        j                  d
      t        d            }nct        | j                  j                  |d	   d
      | j                  j                  |d	   t        j                        z   t        d            }|d   r|D ]  }t        |j                          yg d}g }|D ]W  }|j                  }t!        |      dkD  rd|dd z  }|j#                  |j$                  ||j&                  |j(                  g       Y t        t+        j,                  ||             y)ap  
        List containers.

        Usage: ps [options] [--] [SERVICE...]

        Options:
            -q, --quiet          Only display IDs
            --services           Display services
            --filter KEY=VAL     Filter services by a property
            -a, --all            Show all stopped containers (including those created by the run command)
        r   r   z)--quiet and --services cannot be combinedz--filterrC   c              3   4   K   | ]  }|j                     y wr{   rZ   r   s     rl   r   z%TopLevelCommand.ps.<locals>.<genexpr>  s     AWGLLAr   N--allr   T)r   rU  rS  rZ   rV  rR  rT  )NameCommandStatePorts   z%s ...   )r-   build_filterr   r   r   filter_servicesrP   r[   r   rf  r   includer   rg  r?  human_readable_commandrb   rl  rZ   human_readable_statehuman_readable_portsr/   rm  )	r   r   filtr   rf  r  ro  rp  r^   s	            rl   pszTopLevelCommand.ps  s    9',"7GHH< J 78D||,,H*44<<H$))AAAB7 7 7giFX@L@T@T^b !8 !d$.v$68J  ''gi6HRV'W''gi6HR^RcRc'dev&(J
 9' $	ill#$G D' 		#::w<"$&"5GNN2222	 		 )//'401rp   c           	         |j                  d      rt        j                  d       | j                  j	                  |d   |j                  d      |j                  d       |j                  d      |j                  d             y	)
aL  
        Pulls images for services defined in a Compose file, but does not start the containers.

        Usage: pull [options] [--] [SERVICE...]

        Options:
            --ignore-pull-failures  Pull what it can and ignores images with pull failures.
            --parallel              Deprecated, pull multiple images in parallel (enabled by default).
            --no-parallel           Disable parallel pulling.
            -q, --quiet             Pull without printing progress information
            --include-deps          Also pull services declared as dependencies
        r   zG--parallel option is deprecated and will be removed in future versions.r   z--ignore-pull-failuresz--no-parallelr   z--include-deps)r   ignore_pull_failuresparallel_pullr   include_depsN)r   rs   r   r   r   r   r   s     rl   r   zTopLevelCommand.pull<  sq     ;;|$KKab!),!(-E!F%kk/::;;y) %56 	 	
rp   c                 b    | j                   j                  |d   |j                  d             y)z
        Pushes images for services.

        Usage: push [options] [--] [SERVICE...]

        Options:
            --ignore-push-failures  Push what it can and ignores images with push failures.
        r   z--ignore-push-failures)r   ignore_push_failuresN)r   pushr   r  s     rl   r  zTopLevelCommand.pushT  s0     	!),!(-E!F 	 	
rp   c                 T   |j                  d      rt        j                  d       t        j                  }|j                  d      r | j
                  j                  |d   |       | j
                  j                  |d   d|      }|D cg c]  }|j                  r| }}t        |      dkD  rft        d	t        |             |j                  d
      st        dd      r2| j
                  j                  |d   |j                  dd      |       yyt        d       yc c}w )a[  
        Removes stopped service containers.

        By default, anonymous volumes attached to containers will not be removed. You
        can override this with `-v`. To list all volumes, use `docker volume ls`.

        Any data which is not in a volume will be lost.

        Usage: rm [options] [--] [SERVICE...]

        Options:
            -f, --force   Don't ask to confirm removal
            -s, --stop    Stop the containers, if required, before removing
            -v            Remove any anonymous volumes attached to containers
            -a, --all     Deprecated - no effect.
        r  zO--all flag is obsolete. This is now the default behavior of `docker-compose rm`z--stopr   rT  T)r   rS  rU  r   zGoing to removez--forcezAre you sure? [yN] F)defaultz-v)r   vrU  zNo stopped containersN)r   rs   r   r   r  r   stoprf  
is_runningrb   rP   r  r4   remove_stopped)r   r   rU  all_containersrn  stopped_containerss         rl   r   zTopLevelCommand.rmc  s   $ ;;wKK) &&;;x LLGI,>P00!),dG 1 
 *8LAq||aLL!"Q&#_5G%HI{{9%2EB++"))"4kk$.# ,  C )* Ms   D%D%c                    | j                   j                  |d         }|j                  d      }|d   r|d   rt        d      |d   |d   g|d   z   }n#|d	   g }n|j                  j                  d
      }|j                  j                  dd      |d<   t        |||      }t        || j                   ||| j                  | j                         y)a0  
        Run a one-off command on a service.

        For example:

            $ docker-compose run web python manage.py shell

        By default, linked services will be started, unless they are already
        running. If you do not want to start linked services, use
        `docker-compose run --no-deps SERVICE COMMAND [ARGS...]`.

        Usage:
            run [options] [-v VOLUME...] [-p PORT...] [-e KEY=VAL...] [-l KEY=VALUE...] [--]
                SERVICE [COMMAND] [ARGS...]

        Options:
            -d, --detach          Detached mode: Run container in the background, print
                                  new container name.
            --name NAME           Assign a name to the container
            --entrypoint CMD      Override the entrypoint of the image.
            -e KEY=VAL            Set an environment variable (can be used multiple times)
            -l, --label KEY=VAL   Add or override a label (can be used multiple times)
            -u, --user=""         Run as specified username or uid
            --no-deps             Don't start linked services.
            --rm                  Remove container after run. Ignored in detached mode.
            -p, --publish=[]      Publish a container's port(s) to the host
            --service-ports       Run command with the service's ports enabled and mapped
                                  to the host.
            --use-aliases         Use the service's network aliases in the network(s) the
                                  container connects to.
            -v, --volume=[]       Bind mount a volume (default [])
            -T                    Disable pseudo-tty allocation. By default `docker-compose run`
                                  allocates a TTY.
            -w, --workdir=""      Working directory inside the container
        r   r)  	--publish--service-portszEService port mapping and manual port mapping can not be used togetherr   Nr.  --entrypointr^   
stdin_openT)	r   r:  r   r-   r   build_one_off_container_optionsrun_one_off_containerr   r   )r   r   rY   rH  r^   container_optionss         rl   r  zTopLevelCommand.run  s    J ,,**79+=>Z(;G,=$>+ 
 9)y)*WV_<G^$0Goo)))4G ' 3 3L$ G;GVWUt||Wg!!4#<#<	
rp   c                     t        |      }t        j                  d       t        |d         j	                         D ]1  \  }}| j
                  j                  |      j                  ||       3 y)a  
        Set number of containers to run for a service.

        Numbers are specified in the form `service=num` as arguments.
        For example:

            $ docker-compose scale web=2 worker=3

        This command is deprecated. Use the up command with the `--scale` flag
        instead.

        Usage: scale [options] [SERVICE=NUM...]

        Options:
          -t, --timeout TIMEOUT      Specify a shutdown timeout in seconds.
                                     (default: 10)
        zRThe scale command is deprecated. Use the up command with the --scale flag instead.zSERVICE=NUM)r  N)r  rs   r   parse_scale_argsr  r   r:  scale)r   r   r  service_namenums        rl   r  zTopLevelCommand.scale  sm    & $G,@	

 "2'-2H!I!O!O!Q 	OL#LL$$\288g8N	Orp   c                 ^    | j                   j                  |d         }t        | dd       y)zO
        Start existing containers.

        Usage: start [SERVICE...]
        r   r  zNo containers to startr   N)r   rD  r  r  s      rl   rD  zTopLevelCommand.start  r  rp   c                 Z    t        |      }| j                  j                  |d   |       y)aB  
        Stop running containers without removing them.

        They can be started again with `docker-compose start`.

        Usage: stop [options] [--] [SERVICE...]

        Options:
          -t, --timeout TIMEOUT      Specify a shutdown timeout in seconds.
                                     (default: 10)
        r   r   r  N)r  r   r  )r   r   r  s      rl   r  zTopLevelCommand.stop  s*     $G,	(:GLrp   c                 v    t        |      }| j                  j                  |d   |      }t        | dd       y)z
        Restart running containers.

        Usage: restart [options] [--] [SERVICE...]

        Options:
          -t, --timeout TIMEOUT      Specify a shutdown timeout in seconds.
                                     (default: 10)
        r   r  zNo containers to restartr   N)r  r   restartr  )r   r   r  rf  s       rl   r  zTopLevelCommand.restart  s<     $G,\\))	8JT[)\
J :A>rp   c                 J   t        | j                  j                  |d   d      | j                  j                  |d   t        j                        z   t        d            }t        |      D ]  \  }}|dkD  r
t                | j                  j                  j                  |j                        }|j                  d      }g }|j                  d	g       D ]  }|j                  |        t        |j                         t        t        j                  ||              y
)zQ
        Display the running processes

        Usage: top [SERVICE...]

        r   FrR  rT  rZ   rV  r   Titles	ProcessesN)r   r   rf  r   rg  r   	enumeraterP   r   toprZ   r   rl  r/   rm  )	r   r   rf  idxr  top_dataro  rp  processs	            rl   r  zTopLevelCommand.top  s     LL##')2De#TLL##')2DlN_N_#`a6"

 (
3 	2NCQw||**..y~~>Hll8,GD#<<R8 %G$% )..!)//'401	2rp   c                 ^    | j                   j                  |d         }t        | dd       y)zH
        Unpause services.

        Usage: unpause [SERVICE...]
        r   r  zNo containers to unpauser   N)r   unpauser  r  s      rl   r  zTopLevelCommand.unpause/  s/     \\))	8J)K
J :A>rp   c                     d    d   t         j                        }d   }d   t              d   j                  d      j                  d      j                  d      j                  d	       }r|s|srt	        d
       j
                  j                  d      rrt	        d      g d}|D cg c]  }j                  |      ss| c}D ]  }t	        dj                  |              j
                  j                  dd      t         j                        5  t         j                  j                          fd}	  |d      }	sr
	 ddd       yt#        |	      }t%         j                  |d   ddi| j                  j'                        |      }t)        dt+        |j,                               |j/                         }|ryt)        d        j                  j-                  d   d      }t1        ||||      } j                  j3                         |rt5        ||      }t7        j8                  |       ddd       yc c}w # t        j                  j                  $ r:}
t        j                  d       t!        dd      }||s|
 |d      }	Y d}
~
`d}
~
ww xY w# 1 sw Y   yxY w)a  
        Builds, (re)creates, starts, and attaches to containers for a service.

        Unless they are already running, this command also starts any linked services.

        The `docker-compose up` command aggregates the output of each container. When
        the command exits, all containers are stopped. Running `docker-compose up -d`
        starts the containers in the background and leaves them running.

        If there are existing containers for a service, and the service's configuration
        or image was changed after the container's creation, `docker-compose up` picks
        up the changes by stopping and recreating the containers (preserving mounted
        volumes). To prevent Compose from picking up changes, use the `--no-recreate`
        flag.

        If you want to force Compose to stop and recreate all containers, use the
        `--force-recreate` flag.

        Usage: up [options] [--scale SERVICE=NUM...] [--] [SERVICE...]

        Options:
            -d, --detach               Detached mode: Run containers in the background,
                                       print new container names. Incompatible with
                                       --abort-on-container-exit.
            --no-color                 Produce monochrome output.
            --quiet-pull               Pull without printing progress information
            --no-deps                  Don't start linked services.
            --force-recreate           Recreate containers even if their configuration
                                       and image haven't changed.
            --always-recreate-deps     Recreate dependent containers.
                                       Incompatible with --no-recreate.
            --no-recreate              If containers already exist, don't recreate
                                       them. Incompatible with --force-recreate and -V.
            --no-build                 Don't build an image, even if it's missing.
            --no-start                 Don't start the services after creating them.
            --build                    Build images before starting containers.
            --abort-on-container-exit  Stops all containers if any container was
                                       stopped. Incompatible with -d.
            --attach-dependencies      Attach to dependent containers.
            -t, --timeout TIMEOUT      Use this timeout in seconds for container
                                       shutdown when attached or when containers are
                                       already running. (default: 10)
            -V, --renew-anon-volumes   Recreate anonymous volumes instead of retrieving
                                       data from the previous containers.
            --remove-orphans           Remove containers for services not defined
                                       in the Compose file.
            --exit-code-from SERVICE   Return the exit code of the selected service
                                       container. Implies --abort-on-container-exit.
            --scale SERVICE=NUM        Scale SERVICE to NUM instances. Overrides the
                                       `scale` setting in the Compose file if present.
            --no-log-prefix            Don't print prefix in logs.
        	--no-depsz--always-recreate-deps--abort-on-container-exitr   r
  r)  z
--no-start--attach-dependenciesr  zN-d cannot be combined with --abort-on-container-exit or --attach-dependencies.r	  r  )r)  r  --exit-code-fromr  z%--no-start and {} cannot be combined.r   Tc                     	j                   j                  
t              t              t	        d          | j                  d      j                  d            S )Nz--scale--renew-anon-volumesz--quiet-pull)r   
start_depsr  r  r  detachedremove_orphansr  scale_overriderD  always_recreate_depsreset_container_imagerenew_anonymous_volumesr   r   attach_dependencies)r   upr  r  r  r   )rebuildr  r  r  r  r   no_startr   r  r   r   r  r  s    rl   r  zTopLevelCommand.up.<locals>.up  sv    ||"/);GD3G<#%#1#1#3GI4F#G&,)=*1,3KK8N,O";;~6&(;! '  rp   FzThe image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.
z!Continue with the new image? [yN]Nr   r{  r  r  r~  zAborting on container exit...rR  r  )exitval_from_optsr   r  r   r-   r   r   rX   up_shutdown_contextwarn_for_swarm_moder   r   r   ImageNotFoundrs   ru   r4   filter_attached_containersr  r"  rP   r  rf  r  compute_exit_coder  compute_service_exit_coderL   rw   )r   r   exit_value_fromcascade_stopr  rh   xexcludedr  	to_attachrj   resattached_containerslog_printercascade_starterr  rG   r  r  r  r  r   r  r  r   r  r  s   ``               @@@@@@@@@@rl   r  zTopLevelCommand.up9  s   l !--
&'?@+GT\\B:;	*#G, !34;;z*;;|,%kk*AB!++&788<O`b b 22>>?WXn]^^e$(HqGKKNxH 	VHCJJ8TUU	V 22>>?Y[_` }gxP C	$ 3 34 (%uI	 8MC	$ C	$P #=##%
 3#%4 !\\00}0M')K ./+2H2H"IJ)oo/O56!%!8!8wyGYcg!8!h-#%8/>	 !!w!O" 9/K^ _I#GC	$ C	$ I< ==.. 
%		+
 ?G;cGtH	
%3C	$ C	$sO   J)J,J0K&6J>K&C2K&K#)/KK&K##K&&K/c                 V    |d   rt        t               yt        t        d             y)z
        Show version information and quit.

        Usage: version [--short]

        Options:
            --short     Shows only Compose's version number.
        z--shortfullN)rP   r
   r2   )rO  r   s     rl   r>   zTopLevelCommand.version  s"     9+"6*+rp   r{   )#__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r  r  r"  rM  classmethodr?   rt  rx  r  r  r  r  r   r  r   r  r  rD  r  r  r  r  r  r>   ro   rp   rl   rJ   rJ     sv   ;z. 6 6 M M Y/
 /
b Y9` 9`v Y
 
8 Y(+ (+T4 V_I IV Y   Y4. 4.l YK K Y"> ">H Y= = Y@ @* Y62 62p Y
 
. Y
 
 Y*+ *+X Y:
 :
x YO O8 Y= = YM M Y? ? Y2 26 Y? ? YS$ S$j Y,  ,rp   rJ   c                 B    t        t         fd|            }|s%t        j                  dj	                                yt        |      dkD  r4t        d |D cg c]  }|j                         d   d    c}      }|d   S |d   j                         d   d   S c c}w )	Nc                 "    | j                   k(  S r{   rY   )rn  r  s    rl   <lambda>z+compute_service_exit_code.<locals>.<lambda>  s    !)). rp   z.No containers matching the spec "{}" were run.r	   r   c                     | dk7  S Nr   ro   )rj   s    rl   r   z+compute_service_exit_code.<locals>.<lambda>  s
    a1f rp   r  r9  r   )listfilterrs   ru   rX   rb   inspect)r  r  
candidatesrn  exit_valuess   `    rl   r  r    s    f. J 		/	
 
:7AB!QYY[!*-B

 1~a=  "7+J77	 Cs   B
c                     d}|D ]=  }|j                   r||j                  k(  s |j                  dk(  r0|j                  } |S  |S r  )r  rZ   rG   )r  r  r  r  rG   rj   s         rl   r  r    sN    I AFF!:;;!#KK	 rp   c                     | d   }| d   }| j                  d      }|r|rt        d      |r|rt        d      |s|rt        j                  S |rt        j                  S t        j
                  S )Nz--no-recreatez--force-recreater  z6--force-recreate and --no-recreate cannot be combined.z:--no-recreate and --renew-anon-volumes cannot be combined.)r   r-   r   alwaysneverchanged)r   no_recreateforce_recreater  s       rl   r  r    sw    /*K/0N%kk*@A+PQQ.TUU0")))"(((&&&rp   c                 B    | j                  d      }|d S t        |      S )Nz	--timeout)r   rf   )r   r  s     rl   r  r    s#    kk+&G?44G4rp   c                    	 t        |       S # t        $ r}d }dg}|j                  rKdj                  dj	                  t        |j                                    }|d ||j                        |gz  }|j                  rKdj                  dj	                  t        |j                                    }|d ||j                        |gz  }t        dj	                  |            d }~ww xY w)	Nc                 D    dj                  d t        |       D              S )NrC   c              3   >   K   | ]  }d j                  |        yw)z    {}N)rX   )r}   rZ   s     rl   r   zAimage_digests_for_project.<locals>.list_images.<locals>.<genexpr>  s     NtX__T2Ns   )r[   r   )rt  s    rl   list_imagesz.image_digests_for_project.<locals>.list_images  s    99Nvf~NNNrp   z Some images are missing digests.z#Use `docker push {}` to push them.  z#The following images can be pushed:z#Use `docker pull {}` to pull them. z'The following images need to be pulled:z

)r   r   
needs_pushrX   r[   r   
needs_pullr-   )r   rj   r  parascommand_hints        rl   r   r     s     , )) ,	O 44<<5!567  5ALL) E <<5!567 
 9ALL) E E*++;,s   
 	C)CC$$C)c                 6   | j                  d      }|r| j                  d      st        j                  d       d| d<   ||j                         D cg c]  }|j                   c}vr+t        j                  d|       t        j                  d       |S c c}w )Nr  r  z8using --exit-code-from implies --abort-on-container-exitTz5No service named "%s" was found in your compose file.r	   )r   rs   r   r   rZ   ru   rL   rw   )r   r   r  r   s       rl   r  r  ;  s    kk"45O{{67KKRS37G/073G3G3I"Ja166"JJIIM%'HHQK	 #Ks   Bc                 p    |st         j                  S 	 t         |   S # t        $ r t        d| z        w xY w)Nz"%s flag must be one of: all, local)r    noneKeyErrorr-   )flagr|   s     rl   r  r  H  sB    ~~E E<tCDDEs    5c                     | d   r| d   rt        d      | d   rt        j                  S | d   rt        j                  S t        j                  S )Nz--buildz
--no-buildz+--build and --no-build can not be combined.)r-   r   forceskipr  r   s    rl   r  r  Q  sQ    ygl3EFFy   |rp   c                 h   ||xs& | d   xs t         j                  j                           | j                  d      |d}| d   r$t	        j
                  t        | d               |d<   | d   rt        | d         |d<   | j                  d      | d   d	k(  rd	gn| d   |d
<   d |d<   | d   r| j                  d      |d<   | d   sg |d<   | d   r| j                  d      |d<   | d   r| d   |d<   | d   r| d   |d<   | d   r*| d   D cg c]  }t        j                  |       }}||d<   |S c c}w )Nr/  r  )r^   r4  r  rH  z-er7  z--labellabelsr  rB   
entrypointr  r1  r3  r  portsr  z--namerZ   r+  working_dirz--volumer   )
rL   r5  isattyr   r   from_command_liner   r   r   r   )r   rH  r^   r  ir   s         rl   r  r  ^  s   EgdmE3993C3C3E/EFkk,/	 t}+6+H+Hgdm,,
-( y&2793E&F(#{{>".N+r1RDw~7N 	,'
 $(i x$+KK$9&!$%%''"{%,[[%='"x$+H$5&!{+2;+?-(z07
0CD1:##A&DD'.)$ Es   
D/c           
      $   |j                  d      }j                  d      }j                  d      }d_        j                  j                  gd    t
        j                  dd|d|       }		 t        fd	|	D              |r(j                  |       t        j                         y fd}
|j                  d       }t        j                          t        j                          	 	 t        s|r4j!                  |       t#        t%        | j&                        ||      }nt)        j*                  j&                  d    d      }t-        j*                  |      }|j/                         }j                  |       |j1                  |       j3                         } |
        t=        j>                         y # t        $ r t        d
      w xY w# t        j4                  $ r* j*                  j7                  j&                         d}Y qw xY w# t        j4                  t        j8                  f$ rD j*                  j;                  j&                          |
        t=        j>                  d       Y w xY w)Nr   r)  z--use-aliasesr   r  TF)r   r  r  r  rescaler   rU  override_optionsc              3   V   K   | ]   }|j                   j                  k(  s| " y wr{   )rY   rZ   )r}   rn  rY   s     rl   r   z(run_one_off_container.<locals>.<genexpr>  s      Lq!))w||2KLs   ))z(Could not bring up the requested servicec                  b    d   r)j                   j                   j                  dd       y y )Nz--rmT)r  r  )r   remove_containerr?  )r  r   r   s   rl   r.  z/run_one_off_container.<locals>.remove_container  s,    6?NN++ILL+M rp   r'  r/  )r8  r  r	   ) r   r   	scale_numr  rZ   r   r  nextStopIterationr"   start_containerrP   r   rC  set_signal_handler_to_hang_upr   connect_container_to_networksr=  get_docker_start_callr?  r8   r   r7   socketsrD  waitrR   r  HangUpExceptionrx  rL   rw   )r  r   rY   r   r   r   r   rH  use_network_aliasesrf  r.  rF  rG   rK  rL  r6  r  s    ```            @rl   r  r    sA   )556PQN[[$F!++o6G||n{++$***  	JOLJLL	 	+>?innN '223OPPG**,))+	"g55iATU')*;Y\\J$&:	
 )NNLL$+DM 1		 %W^^Y?++-''	3FG		'"%NN,	 HHY[  O"#MNNOH )) 	NN	-I	 %%w'>'>? ILL)s8   6G 7B<G( G%(:H%"H( $H%%H( (A$JJc                     dg}| j                  d      s|j                  d       | j                  d      r|j                  d       |j                  |       |S )NrD  rH  z--attachr  --interactive)r   rl  )r  container_iddocker_calls      rl   r5  r5    sU    )K  *:&\*?+|$rp   c                     t        |D cg c]  }|j                  dvs| c}t        | j                  ||      |xs | j	                         ||      S c c}w )N)Nr  )r  r  )r1   
log_driverr0   r   r"  )r   rf  
monochromer  r  r  r  rn  s           rl   r  r    sT     Eq!,,n"DEW22JL((! Es
   AAc                      t        | ||d       S )Nc                     | j                   S r{   r  )r  s    rl   r   z,filter_attached_containers.<locals>.<lambda>  s    )++ rp   r#   )rf  r   r  s      rl   r  r    s    !+	- -rp   c              #   <  K   |rd  y t        j                          	 	 d  y # t         j                  $ r! t        d       | j	                  ||       Y y w xY w# t         j                  $ r* | j                  |       t        j                  d       Y y w xY ww)Nz4Gracefully stopping... (press Ctrl+C again to force)r  r  r	   )r   rC  rR   rP   r  rx  rL   rw   )r   r   r  r  s       rl   r  r    s     **,	G(( 	GHILL}gLF	G $$ =1sC   B% B1AA BAA :BBBBc                 2    dj                  d | D              S )Nry   c              3   4   K   | ]  }|j                     y wr{   r  )r}   rn  s     rl   r   z"list_containers.<locals>.<genexpr>  s     0QVV0r   )r[   )rf  s    rl   r  r    s    990Z000rp   c                 H    | r t         j                  |       t        |      y r{   )rs   ru   r`   )	conditionmessagerG   s      rl   r  r    s!    		'## rp   c           
         t        d      }|st        t        j                  d            |j	                  dd      }|j	                  d      }|j	                  d      }|j	                  d      }|j	                  d      }|j	                  d	      }	|j	                  d
      }
g }|r|j                  d       |r|j                  d|g       |r|j                  d|g       |r|j                  d|g       |r|j                  d       |	r7|j                  d	t        j                  dd|	j                  d            g       |
r|j                  d
|
g       |g|z   | z   } t        j                  dj                  t        t        j                  |                    |j!                         D ci c]  \  }}|	|| }}}t#        j$                  | |      S c c}}w )Nr   zCouldn't find `docker` binary.z--tlsFz--tlscacertz	--tlscertz--tlskeyz--tlsverifyz--hostz	--contextz
^https?://ztcp://=r  )env)r   r-   r   docker_not_found_msgr   rl  extendr   sublstriprs   debugr[   mappipesquoter  
subprocesscall)rc   
dockeroptsr7  executable_pathtlsca_certcertrW  verifyhostcontexttls_optionskr  filtered_envs                  rl   r=  r=    s   %h/O334TUVV
..%
(Cnn]+G>>+&D
..
$C^^M*F>>(#Dnn[)GK
7#M734K./
J,-=)rvvmXt{{37GHI	
 '"	
 {*T1DIIchhs5;;-./%0%6%6%8JTQAMAqDJLJ??4\22 Ks   1
G<Gc                     i }| D ]7  }d|vrt        d      |j                  dd      \  }}	 t        |      }|||<   9 |S # t        $ r t        d|z        w xY w)NrJ  z4Arguments to scale should be in the form service=numr   z5Number of containers for service "%s" is not a number)r-   r   rf   r   )r   r  r   r  r  s        rl   r  r  5  s    
C 
 a<RSSGGCOc	c(C
  L
  J  	G,V 	s   AAc                     dg}| d   r|dgz  }n|dgz  }| d   s|dgz  }| d   r|dgz  }| d   r
|d| d   gz  }| d   r| d   D ]	  }|d|gz  } | d	   r
|d	| d	   gz  }||gz  }||z  }|S )
Nrr   r)  r;  r/  z--ttyr0  r1  r*  r+  ro   )r   r<  r^   rc   env_variables        rl   r>  r>  E  s    8Dz!!4=	~  x78,--w#G, 	,LWl++D	, {gk233\NDGODKrp   c                 f    d d d d d}| D ]!  }||vrt        d|z         ||   |      s! y y )Nc                     | j                   S r{   r  rn  s    rl   r   z*has_container_with_state.<locals>.<lambda>d  s
    Q\\ rp   c                     | j                    S r{   rf  rg  s    rl   r   z*has_container_with_state.<locals>.<lambda>e  s    - rp   c                     | j                   S r{   )	is_pausedrg  s    rl   r   z*has_container_with_state.<locals>.<lambda>f  s
    AKK rp   c                     | j                   S r{   )is_restartingrg  s    rl   r   z*has_container_with_state.<locals>.<lambda>g  s
     rp   )runningrS  paused
restartingzInvalid state: %sTr,   )rf  statestatesr  s       rl   has_container_with_staterr  b  sP    )-'/	F   	/%7886%=#	rp   c                 *      fd}t        ||      S )Nc                    D ]y  }|dk(  r2|   }j                  | j                  gd      }t        ||      r8 y|dk(  r.|   }|dk(  s|dk(  r|| j                  vs] yt	        d|z        t	        d	|z         y)
NrA   T)rS  Fr   rh  r   z#Invalid value for source filter: %szInvalid filter: %s)rf  rZ   rr  r   r-   )rY   frp  rf  r   r  r   s        rl   should_includez'filter_services.<locals>.should_includeq  s     	:AH}Q$///M
/
EB haW$'(9W__4$#$IF$RSS 4q 899	: rp   )r  )r  r   r   rv  s   ` ` rl   r  r  p  s    $ .(++rp   c                 `    i }| )d| vrt        d      | j                  dd      \  }}|||<   |S )NrJ  z/Arguments to --filter should be in form KEY=VALr   )r-   r   )argr  rW  vals       rl   r  r    sA    D
c>MNN99S!$SS	Krp   c                     | j                         }|j                  di       j                  d      dk(  r8|j                  dd      j                  d      ry t        j	                  d       y y )NSwarmLocalNodeStateactiveServerVersionrB   ucpa
  The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.
)rt   r   
startswithrs   r   )r   rt   s     rl   r  r    s^    ;;=Dxx  !12h>88OR(33E:+	
 ?rp   )TN)FNT)F)z
contextlibr   r  r   rR  r   rT  rL   distutils.spawnr   r  r   operatorr   docker.errorsr   docker.utilsrB   r   r   r
   r   r   r   r   r   config.environmentr   config.serializer   config.typesr   constr   r   r   metrics.decoratorr   parallelr   progress_streamr   r   r   r   r   r   r   rY   r   r   r   r    r!   r"   r   r$   colorsr%   r^   r&   r'   r(   docopt_commandr)   r*   r+   r-   r%  r.   r/   r  r0   r1   r2   r3   r4   compose.metrics.clientr5   r6   dockerpty.ptyr7   r8   r9   r   r  rs   rm   rK   ra   rS   rO   r   r   r   r   r\   rJ   r  r  r  r  r   r  r  r  r  r  r5  r  r  contextmanagerr  r  r  r=  r  r>  rr  r  r  r  ro   rp   rl   <module>r     s        	  
 +        ' & ! ' , / % % ' % ' + / ' $ # " " !   )  % * *  , $ ) , ' )  .   - # # +  1 ) IIg!=*@ (,FNNa #QL*"2:>8[, [,|8('&5
!,H
E
+\?D "-  "1$%3P :,,
rp   