@@ -22,22 +22,22 @@ def logger(log, v=0):
2222 print log
2323
2424
25- def cmdexec (command ):
25+ def cmdexec (command , stdin = '' ):
2626 """Execute a command."""
2727 # if 'command' is a string, split the string into components
2828 if isinstance (command , str ):
2929 command = command .split ()
3030
31- proc = subprocess .Popen (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
32- (stdout , stderr ) = proc .communicate ()
31+ proc = subprocess .Popen (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , stdin = subprocess . PIPE )
32+ (stdout , stderr ) = proc .communicate (stdin )
3333
3434 logger ("cmdexec: %s, result: %s, error: %s" % (command , stdout , stderr ), 3 )
3535
3636 # strip trailing whitespace, which would mess with string comparisons
3737 return {"return_code" : proc .returncode , "stderr" : stderr .rstrip (), "stdout" : stdout .rstrip ()}
3838
3939
40- # stolen from munkicommons.py
40+ # from munkicommons.py
4141def getFirstPlist (textString ):
4242 """Gets the next plist from a text string that may contain one or
4343 more text-style plists.
@@ -60,6 +60,21 @@ def getFirstPlist(textString):
6060 textString [plist_end_index :])
6161
6262
63+ def dmg_has_sla (dmgpath ):
64+ has_sla = False
65+ imageinfo_cmd = ['/usr/bin/hdiutil' , 'imageinfo' , dmgpath , '-plist' ]
66+ result = cmdexec (imageinfo_cmd )
67+ if result ["return_code" ] != 0 :
68+ print "error getting imageinfo! %s, %s" % (result ["return_code" ], result ["stderr" ])
69+ return False
70+ result_plist = result ["stdout" ]
71+ imageinfo_dict = plistlib .readPlistFromString (result_plist )
72+ properties = imageinfo_dict .get ('Properties' )
73+ if properties is not None :
74+ has_sla = properties .get ('Software License Agreement' , False )
75+ return has_sla
76+
77+
6378def attachdmg (dmgpath ):
6479 global dmg_was_mounted
6580 info_cmd = ["hdiutil" , "info" , "-plist" ]
@@ -90,7 +105,12 @@ def attachdmg(dmgpath):
90105 "/private/tmp" ,
91106 "-plist" ,
92107 "-nobrowse" ]
93- result = cmdexec (attachcmd )
108+ if dmg_has_sla (dmgpath ):
109+ stdin = "Y\n "
110+ print "NOTE: Disk image %s has a license agreement!" % dmgpath
111+ else :
112+ stdin = ''
113+ result = cmdexec (attachcmd , stdin )
94114 if result ["return_code" ] == 0 :
95115 # parse the plist output
96116 (theplist , alltext ) = getFirstPlist (result ["stdout" ])
@@ -246,7 +266,7 @@ if __name__ == "__main__":
246266 # extract version and other metadata
247267 (app_name , app_identifier , app_version ) = appNameAndVersion (app_path )
248268
249- logger ("Name: %s, ID: %s, Version: %s" % (app_name , app_identifier , app_version ))
269+ logger ("Name: %s, ID: %s, Version: %s" % (app_name , app_identifier , app_version ), 1 )
250270
251271 # TODO: get name syntax from prefs or parameter
252272 pkg_name = "{name}-{version}.pkg" .format (name = app_name , version = app_version , identifier = app_identifier )
0 commit comments