@@ -28,7 +28,7 @@ import io
28
28
import os
29
29
30
30
DEFAULT_VERSION = "1.9.0"
31
-
31
+ DEVNULL = open ( os . devnull , "w" )
32
32
33
33
def options ():
34
34
parser = argparse .ArgumentParser (add_help = False )
@@ -79,7 +79,8 @@ def get_version():
79
79
return None
80
80
81
81
82
- def install (version : str ):
82
+ def install (version : str , quiet : bool ):
83
+ info_out = DEVNULL if quiet else sys .stderr
83
84
url = url_template .format (version = version )
84
85
if install_dir .exists ():
85
86
shutil .rmtree (install_dir )
@@ -88,19 +89,20 @@ def install(version: str):
88
89
if ripunzip is None and platform .system () == "Windows" and windows_ripunzip .exists ():
89
90
ripunzip = windows_ripunzip
90
91
if ripunzip :
91
- print (f"downloading and extracting { url } using ripunzip" , file = sys .stderr )
92
- subprocess .run ([ripunzip , "unzip-uri" , url ], cwd = install_dir , check = True )
92
+ print (f"downloading and extracting { url } using ripunzip" , file = info_out )
93
+ subprocess .run ([ripunzip , "unzip-uri" , url ], stdout = info_out , stderr = info_out , cwd = install_dir ,
94
+ check = True )
93
95
return
94
96
with io .BytesIO () as buffer :
95
- print (f"downloading { url } " , file = sys . stderr )
97
+ print (f"downloading { url } " , file = info_out )
96
98
with urllib .request .urlopen (url ) as response :
97
99
while True :
98
100
bytes = response .read ()
99
101
if not bytes :
100
102
break
101
103
buffer .write (bytes )
102
104
buffer .seek (0 )
103
- print (f"extracting kotlin-compiler-{ version } .zip" , file = sys . stderr )
105
+ print (f"extracting kotlin-compiler-{ version } .zip" , file = info_out )
104
106
with ZipFilePreservingPermissions (buffer ) as archive :
105
107
archive .extractall (install_dir )
106
108
@@ -138,7 +140,8 @@ def main(opts, forwarded_opts):
138
140
else :
139
141
selected_version = current_version or DEFAULT_VERSION
140
142
if selected_version != current_version :
141
- install (selected_version )
143
+ # don't print information about install procedure unless explicitly using --select
144
+ install (selected_version , quiet = opts .select is None )
142
145
version_file .write_text (selected_version )
143
146
if opts .version or (opts .select and not forwarded_opts ):
144
147
print (f"info: kotlinc-jvm { selected_version } (codeql dev wrapper)" , file = sys .stderr )
@@ -149,8 +152,8 @@ def main(opts, forwarded_opts):
149
152
if __name__ == "__main__" :
150
153
try :
151
154
main (* options ())
152
- except Exception as e :
153
- print (f"{ e . __class__ . __name__ } : { e } " , file = sys .stderr )
155
+ except Error as e :
156
+ print (f"Error : { e } " , file = sys .stderr )
154
157
sys .exit (1 )
155
158
except KeyboardInterrupt :
156
159
sys .exit (1 )
0 commit comments