Skip to content

Instantly share code, notes, and snippets.

@opragel
Last active November 8, 2016 03:16
Show Gist options
  • Save opragel/db367b9616e48a8cebce to your computer and use it in GitHub Desktop.
Save opragel/db367b9616e48a8cebce to your computer and use it in GitHub Desktop.
ea_microsoft_outlook2016_versioncheck.py
#!/usr/bin/python
"""
This script checks whether the installed version of Microsoft Outlook 2016 is
equal, less, or more than the target version defined by APP_TARGET_VERSION
and reports the result in Casper Suite extension attribute style.
T = Local app version is equal to provided target version
N = Local app version is newer than provided target version
F = Local app version is less than provided target version
N/A = Local app plist was not found or accesible at specified path
"""
import os.path
import plistlib
from pkg_resources import parse_version
APP_PATH = "/Applications/Microsoft Outlook.app"
APP_VERSION_KEY = "CFBundleShortVersionString"
APP_TARGET_VERSION = "15.27.0"
def get_version_check_result(app_path, app_version_key, app_target_version):
"""
Reports T if the local app version is equal to target version, F if the
local app version is less than target version, N if the local app
version is greater than target version, and N/A if the plist is not found.
"""
app_plist_path = app_path + "/Contents/Info.plist"
if not os.path.isfile(app_plist_path):
version_check_result = "N/A"
else:
app_info_plist = plistlib.readPlist(app_plist_path)
app_version = app_info_plist[app_version_key]
if parse_version(app_target_version) == parse_version(app_version):
version_check_result = "T"
elif parse_version(app_target_version) < parse_version(app_version):
version_check_result = "N"
else:
version_check_result = "F"
return version_check_result
def main():
""" Executes script functions. """
result = get_version_check_result(APP_PATH,
APP_VERSION_KEY,
APP_TARGET_VERSION)
print '<result>%s</result>' % result
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment