
                         r    S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	J
r
  S
S jrS rSS	 jrg)zUtilities for local mode.    )absolute_import)division)unicode_literalsN)filesc           	      X   Uc  [         R                  n[        R                  " U [        R                  [        R                  [        R
                  SSS9 nU(       a*  UR                  R                  UR                  S5      5        UR                  R                  5         [        R                  " UR                  SS9nU H$  nUR                  U5        UR                  5         M&     UR                  5         SSS5        UR                  $ ! , (       d  f       WR                  $ = f)a0  Executes shell commands in subprocess.

Executes the supplied command with the supplied standard input string, streams
the output to stdout, and returns the process's return code.

Args:
  cmd: (List[str]) Strings to send in as the command.
  input_str: (str) if supplied, it will be passed as stdin to the supplied
    command. if None, stdin will get closed immediately.
  file: optional file-like object (stream), the output from the executed
    process's stdout will get sent to this stream. Defaults to sys.stdout.

Returns:
  return code of the process
NF   )stdinstdoutstderruniversal_newlinesbufsizezutf-8 )newline)sysr
   
subprocessPopenPIPESTDOUTr	   writeencodecloseioTextIOWrapperflush
returncode)cmd	input_strfilepoutlines         ;lib/googlecloudsdk/command_lib/ai/custom_jobs/local_util.pyExecuteCommandr#      s      
\::D	OO__ ggmmI$$W-.GGMMO


188R
0C
jj
jjl 
 jjl%( 
) ( 
s   B%D
D)c                 \    U R                  S[        R                  R                  5      S-   $ )zConverts the supplied python module into corresponding python file.

Args:
  module_name: (str) A python module name (separated by dots)

Returns:
  A string representing a python file path.
.z.py)replaceospathsep)module_names    r"   ModuleToPathr+   G   s$     
		S"''++	.	66    c                    U =(       d    [         R                  " 5       n Sn[        R                  " U 5       H  n[        R                  R                  X5      n[        R                  R                  U5      (       a"  US:X  a  [         R                  " U5        SnMf  Mh  [        R                  R                  U5      u  pEUS;   d  M  [        R                  " U5        SnM     U$ )z@Removes generic `__pycache__` folder and  '*.pyc' '*.pyo' files.F__pycache__T)z.pycz.pyo)
r   GetCWDr'   listdirr(   joinisdirRmTreesplitextremove)root_dir
is_cleanednameitem_exts         r"   ClearPyCacher<   S   s    '(*jj"d77<<'D	ww}}T		T
 
 ww%fa	 	 
		$
 # 
r,   )NN)N)__doc__
__future__r   r   r   r   r'   r   r   googlecloudsdk.core.utilr   r#   r+   r<    r,   r"   <module>rA      s2      &  ' 	 	  
 *'T	7r,   