
    Ij                         d dl mZ d dlZd dlZd dlmZmZmZ d dlZd dl	Z	 ee
          j        dz  dz  Z ej        d          Zdedefd	Zg Zd
 Z e             dS )    )PathN)OptionalListCallable	pginstallbinpgserverpg_exe_namereturnc                 l     ddt           t                   dt          t                   dt          f fd}|S )Nargspgdatar   c                    
                     d          dv r|
J d            |dt          |          g| z   } t          t          
z            g| z   }t          j        d          5 }t          j        d          5 }	 t
                              d||           t          j        |fd||dd	|}|	                    d
           |	                    d
           |
                                }|
                                }t
                              d|j        |||           n# t          j        $ r}	|	                    d
           |	                    d
           |
                                }|
                                }t
                              d|	j        |t          |	          ||           |	d}	~	ww xY w	 ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |S )aR  
            Run a command with the given command line arguments.
            Args:
                args: The command line arguments to pass to the command as a string,
                a list of options as would be passed to `subprocess.run`
                pgdata: The path to the data directory to use for the command.
                    If the command does not need a data directory, this should be None.
                kwargs: Additional keyword arguments to pass to `subprocess.run`, eg user, timeout.

            Returns:
                The stdout of the command as a string.
        .exe)initdbpg_ctlpg_dumpNz7pgdata must be provided for initdb, pg_ctl, and pg_dumpz-Dzw+z)Running commandline:
%s
with kwargs: `%s`T)checkstdoutstderrtextr   zOSuccessful postgres command %s with kwargs: `%s`
stdout:
%s
---
stderr:
%s
---
zVFailed postgres command %s with kwargs: `%s`:
error:
%s
stdout:
%s
---
stderr:
%s
---
)stripstrPOSTGRES_BIN_PATHtempfileTemporaryFile_loggerinfo
subprocessrunseekreadr   CalledProcessErrorerror)r   r   kwargsfull_command_liner   r   resultoutputr$   errr
   s             \/workspace/show-city-briefing-agent/.venv/lib/python3.11/site-packages/pgserver/_commands.pycommandz(create_command_function.<locals>.command   s    V$$(GGG$$&_$$$#f++&-D !2[!@AABTI#D)) 	VX5KD5Q5Q 	U[JL]_efff $(9 2f]cjn 2 2*02 2AAu"K@ @ @ @0   AAHfc#hhH H H	@	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	. s\   *G*?GB(D*)G*G9BF>>GGG*G	G*G	G**G.1G.)N)r   r   r   r   )r
   r+   s   ` r*   create_command_functionr,      sK    , ,tCy ,8D> ,s , , , , , ,\ N    c                     t                                           D ]m} | j        }t          |          }|                    d          }t          t          j        t                   ||           t          
                    |           nd S )Nr   )r   iterdirnamer,   r   setattrsysmodules__name____all__append)pathexe_nameprogfunction_names       r*   _initr;   >   sz    !))++ & &9&x00 v..H%}d;;;}%%%%& &r-   )pathlibr   r2   r   typingr   r   r   loggingr   __file__parentr   	getLoggerr   r   r,   r5   r;    r-   r*   <module>rC      s          



     + + + + + + + + + +  DNN)K7%? 
'
J
'
'/# /( / / / /b & & & r-   