1- #!/usr/bin/env python
1+ #!/usr/bin/env python3
22# encoding: utf-8
33"""
44chrome-enable-autoupdates.py
1111
1212History:
1313--------
14+ 2022-04-14, Johan McGwire
15+ - Port to Python3
16+
14172019-08-05, Andy Duss
1518- Fix keystone_registration_framework_path to point to correct directory
1619
@@ -68,25 +71,26 @@ def chrome_installed():
6871
6972def chrome_version ():
7073 """Returns Chrome version"""
71- info_plist = plistlib .readPlist (info_plist_path )
72- bundle_short_version = info_plist ["CFBundleShortVersionString" ]
74+ with open (info_plist_path , 'rb' ) as info_plist_file :
75+ info_plist = plistlib .load (info_plist_file )
76+ bundle_short_version = info_plist ["CFBundleShortVersionString" ]
7377 return bundle_short_version
7478
7579
7680def chrome_update_url ():
7781 """Returns KSUpdateURL from Chrome Info.plist"""
78- info_plist = plistlib .readPlist (info_plist_path )
79- update_url = info_plist ["KSUpdateURL" ]
82+ with open (info_plist_path , 'rb' ) as info_plist_file :
83+ info_plist = plistlib .load (info_plist_file )
84+ update_url = info_plist ["KSUpdateURL" ]
8085 return update_url
8186
82-
8387def chrome_product_id ():
8488 """Returns KSProductID from Chrome Info.plist"""
85- info_plist = plistlib .readPlist (info_plist_path )
86- product_id = info_plist ["KSProductID" ]
89+ with open (info_plist_path , 'rb' ) as info_plist_file :
90+ info_plist = plistlib .load (info_plist_file )
91+ product_id = info_plist ["KSProductID" ]
8792 return product_id
8893
89-
9094def keystone_registration_framework_path ():
9195 """Returns KeystoneRegistration.framework path"""
9296 if LooseVersion (chrome_version ()) >= LooseVersion ("76" ):
@@ -124,16 +128,16 @@ def keystone_install():
124128 p = subprocess .Popen (ksinstall_process , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
125129 (results , error ) = p .communicate ()
126130 if results :
127- print results
131+ print ( results )
128132 if p .returncode != 0 :
129133 if error :
130- print >> sys . stderr , "%s" % error
131- print >> sys . stderr , "Keystone install exited with code %i" % p .returncode
134+ print ( "%s" % error , file = sys . stderr )
135+ print ( "Keystone install exited with code %i" % p .returncode , file = sys . stderr )
132136
133137 # Since we used --force argument, succeed no matter what the exit code was.
134138 return True
135139 else :
136- print >> sys . stderr , "Error: KeystoneRegistration.framework not found"
140+ print ( "Error: KeystoneRegistration.framework not found" , file = sys . stderr )
137141 return False
138142
139143
@@ -158,15 +162,15 @@ def register_chrome_with_keystone():
158162 p = subprocess .Popen (ksadmin_process , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
159163 (results , error ) = p .communicate ()
160164 if error :
161- print >> sys . stderr , "%s" % error
165+ print ( "%s" % error , file = sys . stderr )
162166 if results :
163- print results
167+ print ( results )
164168 if p .returncode == 0 :
165169 return True
166170 else :
167171 return False
168172 else :
169- print >> sys . stderr , "Error: %s doesn't exist" % ksadmin
173+ print ( "Error: %s doesn't exist" % ksadmin , file = sys . stderr )
170174 return False
171175
172176
@@ -176,29 +180,29 @@ def main(argv=None):
176180 try :
177181 # Check for root
178182 if os .geteuid () != 0 :
179- print >> sys . stderr , "This script must be run as root"
183+ print ( "This script must be run as root" , file = sys . stderr )
180184 return 1
181185
182186 if not chrome_installed ():
183- print >> sys . stderr , "Error: Chrome is not installed on this computer"
187+ print ( "Error: Chrome is not installed on this computer" , file = sys . stderr )
184188 return 1
185189 if keystone_install ():
186- print "Keystone installed"
190+ print ( "Keystone installed" )
187191 else :
188- print >> sys . stderr , "Error: Keystone install failed"
192+ print ( "Error: Keystone install failed" , file = sys . stderr )
189193 return 1
190194 if register_chrome_with_keystone ():
191- print "Registered Chrome with Keystone"
195+ print ( "Registered Chrome with Keystone" )
192196 return 0
193197 else :
194- print >> sys . stderr , "Error: Failed to register Chrome with Keystone"
198+ print ( "Error: Failed to register Chrome with Keystone" , file = sys . stderr )
195199 return 1
196200
197- except Usage , err :
198- print >> sys .stderr , err . msg
199- print >> sys . stderr , "for help use --help"
201+ except Exception as err :
202+ print ( err , file = sys .stderr )
203+ print ( "for help use --help" , file = sys . stderr )
200204 return 2
201205
202206
203207if __name__ == "__main__" :
204- sys .exit (main ())
208+ sys .exit (main ())
0 commit comments