@@ -14,12 +14,9 @@ import urllib
1414
1515import requests .exceptions
1616import sal
17- sys .path .append ('/usr/local/munki' )
18- from munkilib import munkicommon
19-
2017
2118EXTERNAL_SCRIPTS_DIR = '/usr/local/sal/external_scripts'
22-
19+ verbose = 0
2320
2421def main ():
2522 set_verbosity ()
@@ -61,19 +58,23 @@ def get_checksums():
6158 try :
6259 response = sal_client .post ('preflight-v2/' , data = {'os_family' : 'Darwin' })
6360 except requests .exceptions .RequestException as error :
64- munkicommon .display_debug2 (str (error_msg ))
61+ if verbose :
62+ print (str (error_msg ), file = sys .stderr )
6563 return
6664 if response .status_code != requests .status_codes .codes .okay :
67- munkicommon .display_debug2 (f'Request failed with HTTP { response .status_code } ' )
65+ if verbose :
66+ print (f'Request failed with HTTP { response .status_code } ' , file = sys .stderr )
6867 return
6968 if response and "<h1>Page not found</h1>" in response .text :
70- munkicommon .display_debug2 (response .text )
69+ if verbose :
70+ print (response .text , file = sys .stderr )
7171 return
7272
7373 try :
7474 return response .json ()
7575 except ValueError :
76- munkicommon .display_debug2 ("Didn't receive valid JSON." )
76+ if verbose :
77+ print ("Didn't receive valid JSON." , file = sys .stderr )
7778 return None
7879
7980
@@ -91,7 +92,8 @@ def download_scripts(server_scripts):
9192 download_required = True
9293
9394 if download_required == True :
94- munkicommon .display_debug2 (f'downloading { server_script ["filename" ]} ' )
95+ if verbose :
96+ print (f'downloading { server_script ["filename" ]} ' )
9597 download_and_write_script (server_script )
9698
9799
@@ -101,21 +103,24 @@ def download_and_write_script(server_script):
101103 response = sal .get_sal_client ().get (
102104 f"preflight-v2/get-script/{ server_script ['plugin' ]} /{ server_script ['filename' ]} /" )
103105 except requests .exceptions .RequestException as error :
104- munkicommon .display_debug2 ('Error received downloading script:' )
105- munkicommon .display_debug2 (str (error ))
106+ if verbose :
107+ print ('Error received downloading script:' , file = sys .stderr )
108+ print (str (error ), file = sys .stderr )
106109 return
107110
108111 if response .status_code != requests .status_codes .codes .okay :
109- munkicommon .display_debug2 ('Error received downloading script:' )
110- munkicommon .display_debug2 (response .text )
112+ if verbose :
113+ print ('Error received downloading script:' , file = sys .stderr )
114+ print (response .text , file = sys .stderr )
111115
112116 script = open (
113117 os .path .join (EXTERNAL_SCRIPTS_DIR , server_script ['plugin' ], server_script ['filename' ]),
114118 'w' )
115119 try :
116120 data = response .json ()
117121 except ValueError :
118- munkicommon .display_debug2 ('Did not receive valid JSON when requesting script content.' )
122+ if verbose :
123+ print ('Did not receive valid JSON when requesting script content.' , file = sys .stderr )
119124 return
120125
121126 script .write (data [0 ]['content' ])
@@ -163,7 +168,7 @@ def remove_empty_folders(path):
163168def set_verbosity ():
164169 """Set the verbosity based on options or munki verbosity level."""
165170 args = get_args ()
166- munkicommon . verbose = (
171+ verbose = (
167172 5 if args .debug else int (os .environ .get ('MUNKI_VERBOSITY_LEVEL' , 0 )))
168173
169174
0 commit comments