Skip to content

Commit

Permalink
Merge pull request #3 from tuxudo/patch-1
Browse files Browse the repository at this point in the history
Update for python 3
  • Loading branch information
bochoven authored May 8, 2022
2 parents 5cc046d + 5038c5e commit 83f7b7c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions scripts/munkiinfo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/local/munkireport/munkireport-python2
#!/usr/local/munkireport/munkireport-python3
"""
munkiinfo for munkireport
"""

import os
import plistlib
import sys
import urlparse
import urllib.parse
import importlib

# pylint: disable=E0611
Expand All @@ -20,8 +20,8 @@
# Legacy support
try:
from munkilib import munkicommon as prefs
except ImportError, msg:
print "%s" % msg
except ImportError as msg:
print("%s" % msg)
exit(1)


Expand Down Expand Up @@ -100,7 +100,7 @@ def get_munkiprotocol():
"""The protocol munki is using"""
software_repo_url = pref_to_str(prefs.pref('SoftwareRepoURL'))
try:
url_parse = urlparse.urlparse(software_repo_url)
url_parse = urllib.parse.urlparse(software_repo_url)
return url_parse.scheme
except AttributeError:
return 'Could not obtain protocol'
Expand All @@ -117,9 +117,9 @@ def middleware_checks():
middleware = importlib.import_module(middleware_name)
middleware_version = middleware.__version__
except ImportError:
print "Error: munkiinfo.py - Error importing middleware for version checks."
print("Error: munkiinfo.py - Error importing middleware for version checks.")
except AttributeError:
print "Error: munkiinfo.py - Error getting version attribute from middleware."
print("Error: munkiinfo.py - Error getting version attribute from middleware.")

if middleware_name and middleware_version:
return middleware_name + '-' + middleware_version
Expand Down Expand Up @@ -151,14 +151,17 @@ def munkiinfo_report():

def main():
"""Main"""
# Create cache dir if it does not exist
cachedir = '%s/cache' % os.path.dirname(os.path.realpath(__file__))
if not os.path.exists(cachedir):
os.makedirs(cachedir)

result = munkiinfo_report()

# Write munkiinfo report to cache
cachedir = '%s/cache' % os.path.dirname(os.path.realpath(__file__))
output_plist = os.path.join(cachedir, 'munkiinfo.plist')
plistlib.writePlist(munkiinfo_report(), output_plist)
try:
plistlib.writePlist(result, output_plist)
except:
with open(output_plist, 'wb') as fp:
plistlib.dump(result, fp, fmt=plistlib.FMT_XML)

if __name__ == "__main__":
main()

0 comments on commit 83f7b7c

Please sign in to comment.