Extension attribute - checking for Outlook 365 out of date

mhasman
Valued Contributor

My first extension attribute. I just simply adopted the MS Office 2011 Out-Of-Date extension attribute we use for scoping Office 2011 updates. Seems to be working :)

#!/usr/bin/python
'''Office version extension attribute.

Checks the lowest version number for the main apps if found.
Reports OfficeNotInstalled if something is missing.
Reports True if Office is in need of and capable of updating (min version met)
Reports False otherwise

Note: This a pretty minimal check for version and existence!

'''

from distutils.version import  StrictVersion
import subprocess
import os.path
import shlex
import sys

PREFIX = '/Applications/'
FILES_TO_CHECK = {'Microsoft Excel.app/Contents/Info.plist',
                  'Microsoft Word.app/Contents/Info.plist',
                  'Microsoft Powerpoint.app/Contents/Info.plist',
                  'Microsoft Outlook.app/Contents/Info.plist'}
CURRENT_VERSION = StrictVersion('15.18')
MINIMUM_VERSION = StrictVersion('15.0')

results = []

for file in FILES_TO_CHECK:
    args = shlex.split('defaults read "%s" CFBundleShortVersionString'
                       % os.path.join(PREFIX, file))
    process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    output = process.communicate()
    if output[1]:
        result = 'OfficeNotInstalled'
        print '<result>%s</result>' % str(result)
        sys.exit()
    else:
        results.append(StrictVersion(output[0]))

results.sort()
result = results[0]

# 15.0 is required for upgrade packages
if result < CURRENT_VERSION and result >= MINIMUM_VERSION:
    result = True
else:
    result = False

print '<result>%s</result>' % str(result)
0 REPLIES 0