66import shutil
77import subprocess
88import time
9+ import sys
910from azure .core .exceptions import ResourceNotFoundError
1011from knack .util import CLIError
1112from knack .log import get_logger
1213from azext_vme import consts
13-
14+ import threading
1415
1516logger = get_logger (__name__ )
1617
1718
18- def call_subprocess_raise_output (cmd : list , logcmd : bool = True ) -> str :
19+ class PollingAnimation :
20+ def __init__ (self ):
21+ self .tickers = ["/" , "|" , "\\ " , "-" , "/" , "|" , "\\ " , "-" ]
22+ self .currTicker = 0
23+ self .running = True
24+
25+ def tick (self ):
26+ while self .running : # Keep the animation going
27+ sys .stdout .write ('\r ' + self .tickers [self .currTicker ] + " Running .." )
28+ sys .stdout .flush ()
29+ self .currTicker = (self .currTicker + 1 ) % len (self .tickers )
30+ time .sleep (0.5 ) # Adjust speed if needed
31+
32+ def flush (self ):
33+ self .running = False # Stop the animation
34+ sys .stdout .write ("\r \033 [K" ) # Clears the line
35+ sys .stdout .flush ()
36+
37+
38+ def call_subprocess_raise_output (cmd : list , logcmd : bool = False , logstatus : bool = True ) -> str :
1939 """
2040 Call a subprocess and raise a CLIError with the output if it fails.
2141
@@ -32,6 +52,11 @@ def call_subprocess_raise_output(cmd: list, logcmd: bool = True) -> str:
3252 # Log the command to be run, but do not log the password.
3353 print (f"Running command: { ' ' .join (log_cmd )} " )
3454
55+ if logstatus :
56+ animation = PollingAnimation ()
57+ spinner_thread = threading .Thread (target = animation .tick )
58+ spinner_thread .start ()
59+
3560 try :
3661 called_process = subprocess .run (
3762 cmd , encoding = "utf-8" , capture_output = True , text = True , check = True
@@ -43,15 +68,21 @@ def call_subprocess_raise_output(cmd: list, logcmd: bool = True) -> str:
4368 called_process .stderr ,
4469 )
4570
71+ if logstatus :
72+ animation .running = False
73+ spinner_thread .join ()
74+ animation .flush ()
4675 return called_process .stdout
4776 except subprocess .CalledProcessError as error :
77+ if logstatus :
78+ animation .running = False
79+ spinner_thread .join ()
80+ animation .flush ()
4881 all_output : str = (
4982 f"Command: { ' ' .join (log_cmd )} \n "
50- f"stdout: { error .stdout } \n "
51- f"stderr: { error .stderr } \n "
52- f"Return code: { error .returncode } "
83+ f"{ error .stderr } "
5384 )
54- logger . debug ( "The following command failed to run: \n %s" , all_output )
85+
5586 # Raise the error without the original exception, which may contain secrets.
5687 raise CLIError (all_output ) from None
5788
@@ -89,10 +120,10 @@ def check_and_add_cli_extension(cli_extension_name):
89120 "-o" ,
90121 "tsv"
91122 ]
92- result = call_subprocess_raise_output (command , False )
123+ result = call_subprocess_raise_output (command , False , False )
93124
94125 if not (cli_extension_name in result .strip ()):
95- print (f"{ cli_extension_name } is not installed. Adding it now ..." )
126+ print (f"Installing az cli extension { cli_extension_name } ..." )
96127 command = [
97128 str (shutil .which ("az" )),
98129 "extension" ,
@@ -101,6 +132,7 @@ def check_and_add_cli_extension(cli_extension_name):
101132 cli_extension_name
102133 ]
103134 call_subprocess_raise_output (command )
135+ print (f"Installed az cli extension { cli_extension_name } successfully." )
104136
105137
106138def check_and_enable_bundle_feature_flag (
@@ -131,7 +163,8 @@ def check_and_enable_bundle_feature_flag(
131163 call_subprocess_raise_output (command )
132164
133165 # Wait for the feature flag to be enabled on the dp side
134- time .sleep (5 )
166+ time .sleep (30 )
167+ print ("Enabled the bundle feature flag successfully." )
135168
136169
137170def check_deployment_status (resources , deployment , timestamp ):
0 commit comments