mirror of
https://github.com/munki/munki.git
synced 2026-03-12 20:48:30 -05:00
PyLint cleanups for managedsoftwareupdate
This commit is contained in:
@@ -27,21 +27,28 @@ import sys
|
||||
import time
|
||||
import traceback
|
||||
|
||||
# Disable PyLint complaining about 'invalid' camelCase names
|
||||
# pylint: disable=C0103
|
||||
|
||||
# Do not place any imports with ObjC bindings above this!
|
||||
try:
|
||||
# PyLint cannot properly find names inside Cocoa libraries, so issues bogus
|
||||
# No name 'Foo' in module 'Bar' warnings. Disable them.
|
||||
# pylint: disable=E0611
|
||||
from Foundation import NSDate
|
||||
from Foundation import NSDistributedNotificationCenter
|
||||
from Foundation import NSNotificationDeliverImmediately
|
||||
from Foundation import NSNotificationPostToAllSessions
|
||||
# pylint: enable=E0611
|
||||
except ImportError:
|
||||
# Python is missing ObjC bindings. Run external report script.
|
||||
from munkilib import utils
|
||||
print >> sys.stderr, 'Python is missing ObjC bindings.'
|
||||
scriptdir = os.path.realpath(os.path.dirname(sys.argv[0]))
|
||||
script = os.path.join(scriptdir, 'report_broken_client')
|
||||
_scriptdir = os.path.realpath(os.path.dirname(sys.argv[0]))
|
||||
_script = os.path.join(_scriptdir, 'report_broken_client')
|
||||
try:
|
||||
result, stdout, stderr = utils.runExternalScript(script)
|
||||
print >> sys.stderr, result, stdout, stderr
|
||||
_result, _stdout, _stderr = utils.runExternalScript(_script)
|
||||
print >> sys.stderr, _result, _stdout, _stderr
|
||||
except utils.ScriptNotFoundError:
|
||||
pass # script is not required, so pass
|
||||
except utils.RunExternalScriptError, err:
|
||||
@@ -171,21 +178,23 @@ def runScript(script, display_name, runtype):
|
||||
utils.verifyFileOnlyWritableByMunkiAndRoot(__file__)
|
||||
except utils.VerifyFilePermissionsError, err:
|
||||
# OK, managedsoftwareupdate is insecure anyway - warn & execute.
|
||||
munkicommon.display_warning('Multiple munki executable scripts '
|
||||
'have insecure file permissions. Executing '
|
||||
'%s anyway. Error: %s' % (display_name, err))
|
||||
munkicommon.display_warning(
|
||||
'Multiple munki executable scripts have insecure file '
|
||||
'permissions. Executing %s anyway. Error: %s'
|
||||
% (display_name, err))
|
||||
else:
|
||||
# Just the preflight/postflight is insecure. Do not execute.
|
||||
munkicommon.display_warning('Skipping execution of %s due to '
|
||||
'insecure file permissions. Error: %s' % (display_name, err))
|
||||
munkicommon.display_warning(
|
||||
'Skipping execution of %s due to insecure file permissions. '
|
||||
'Error: %s' % (display_name, err))
|
||||
return result
|
||||
|
||||
try:
|
||||
result, stdout, stderr = utils.runExternalScript(
|
||||
script, allow_insecure=True, script_args=[runtype])
|
||||
if result:
|
||||
munkicommon.display_info('%s return code: %d'
|
||||
% (display_name, result))
|
||||
munkicommon.display_info(
|
||||
'%s return code: %d' % (display_name, result))
|
||||
if stdout:
|
||||
munkicommon.display_info('%s stdout: %s' % (display_name, stdout))
|
||||
if stderr:
|
||||
@@ -219,7 +228,8 @@ def doInstallTasks(do_apple_updates, only_unattended=False):
|
||||
if munkiUpdatesAvailable():
|
||||
# install munki updates
|
||||
try:
|
||||
munki_need_to_restart = installer.run(only_unattended=only_unattended)
|
||||
munki_need_to_restart = installer.run(
|
||||
only_unattended=only_unattended)
|
||||
except:
|
||||
munkicommon.display_error('Unexpected error in munkilib.installer:')
|
||||
munkicommon.log(traceback.format_exc())
|
||||
@@ -230,7 +240,7 @@ def doInstallTasks(do_apple_updates, only_unattended=False):
|
||||
# install Apple updates
|
||||
try:
|
||||
apple_need_to_restart = appleupdates.installAppleUpdates(
|
||||
only_unattended=only_unattended)
|
||||
only_unattended=only_unattended)
|
||||
except:
|
||||
munkicommon.display_error(
|
||||
'Unexpected error in appleupdates.installAppleUpdates:')
|
||||
@@ -301,8 +311,8 @@ def munkiUpdatesAvailable():
|
||||
len(plist.get('managed_installs', [])))
|
||||
except (AttributeError,
|
||||
FoundationPlist.NSPropertyListSerializationException):
|
||||
munkicommon.display_error('Install info at %s is invalid.' %
|
||||
installinfo)
|
||||
munkicommon.display_error(
|
||||
'Install info at %s is invalid.' % installinfo)
|
||||
return updatesavailable
|
||||
|
||||
|
||||
@@ -314,8 +324,8 @@ def munkiUpdatesContainAppleItems():
|
||||
try:
|
||||
plist = FoundationPlist.readPlist(installinfo)
|
||||
except FoundationPlist.NSPropertyListSerializationException:
|
||||
munkicommon.display_error('Install info at %s is invalid.' %
|
||||
installinfo)
|
||||
munkicommon.display_error(
|
||||
'Install info at %s is invalid.' % installinfo)
|
||||
else:
|
||||
# check managed_installs
|
||||
for item in plist.get('managed_installs', []):
|
||||
@@ -455,44 +465,41 @@ def main():
|
||||
scriptdir = os.path.realpath(os.path.dirname(sys.argv[0]))
|
||||
|
||||
p = optparse.OptionParser()
|
||||
p.set_usage("""Usage: %prog [options]""")
|
||||
p.set_usage('Usage: %prog [options]')
|
||||
p.add_option('--auto', '-a', action='store_true',
|
||||
help="""Used by launchd LaunchAgent for scheduled runs.
|
||||
No user feedback or intervention. All other options
|
||||
ignored.""")
|
||||
help='Used by launchd LaunchAgent for scheduled runs. '
|
||||
'No user feedback or intervention. All other options '
|
||||
'ignored.')
|
||||
p.add_option('--logoutinstall', '-l', action='store_true',
|
||||
help="""Used by launchd LaunchAgent when running at the
|
||||
loginwindow.""")
|
||||
help='Used by launchd LaunchAgent when running at the '
|
||||
'loginwindow.')
|
||||
p.add_option('--installwithnologout', action='store_true',
|
||||
help="""Used by Managed Software Update.app when user
|
||||
triggers an install without logging out.""")
|
||||
help='Used by Managed Software Update.app when user '
|
||||
'triggers an install without logging out.')
|
||||
p.add_option('--manualcheck', action='store_true',
|
||||
help="""Used by launchd LaunchAgent when checking
|
||||
manually.""")
|
||||
help='Used by launchd LaunchAgent when checking manually.')
|
||||
p.add_option('--munkistatusoutput', '-m', action='store_true',
|
||||
help="""Uses MunkiStatus.app for progress feedback when
|
||||
installing.""")
|
||||
help='Uses MunkiStatus.app for progress feedback when '
|
||||
'installing.')
|
||||
p.add_option('--id', default='',
|
||||
help='Alternate identifier for manifest retrieval')
|
||||
help='Alternate identifier for manifest retrieval')
|
||||
p.add_option('--quiet', '-q', action='store_true',
|
||||
help="""Quiet mode. Logs messages, but nothing to stdout.
|
||||
--verbose is ignored if --quiet is used.""")
|
||||
help='Quiet mode. Logs messages, but nothing to stdout. '
|
||||
'--verbose is ignored if --quiet is used.')
|
||||
p.add_option('--verbose', '-v', action='count', default=1,
|
||||
help="""More verbose output. May be specified multiple
|
||||
times.""")
|
||||
help='More verbose output. May be specified multiple times.')
|
||||
p.add_option('--checkonly', action='store_true',
|
||||
help="""Check for updates, but don't install them.
|
||||
This is the default behavior.""")
|
||||
help='Check for updates, but don\'t install them. This is '
|
||||
'the default behavior.')
|
||||
p.add_option('--installonly', action='store_true',
|
||||
help='Skip checking and install any pending updates.')
|
||||
help='Skip checking and install any pending updates.')
|
||||
p.add_option('--applesuspkgsonly', action='store_true',
|
||||
help=('Only check/install Apple SUS packages, '
|
||||
'skip Munki packages.'))
|
||||
help='Only check/install Apple SUS packages, skip Munki '
|
||||
'packages.')
|
||||
p.add_option('--munkipkgsonly', action='store_true',
|
||||
help=('Only check/install Munki packages, '
|
||||
'skip Apple SUS.'))
|
||||
help='Only check/install Munki packages, skip Apple SUS.')
|
||||
p.add_option('--version', '-V', action='store_true',
|
||||
help='Print the version of the munki tools and exit.')
|
||||
help='Print the version of the munki tools and exit.')
|
||||
|
||||
options, dummy_arguments = p.parse_args()
|
||||
|
||||
@@ -582,7 +589,7 @@ def main():
|
||||
if os.path.exists(launchdtriggerfile):
|
||||
try:
|
||||
launch_options = FoundationPlist.readPlist(launchdtriggerfile)
|
||||
options.munkipkgsonly = launch_options.get(
|
||||
options.munkipkgsonly = launch_options.get(
|
||||
'SuppressAppleUpdateCheck')
|
||||
except FoundationPlist.FoundationPlistException:
|
||||
pass
|
||||
@@ -687,7 +694,7 @@ def main():
|
||||
exit(0)
|
||||
|
||||
applesoftwareupdatesonly = (munkicommon.pref('AppleSoftwareUpdatesOnly')
|
||||
or options.applesuspkgsonly)
|
||||
or options.applesuspkgsonly)
|
||||
|
||||
skip_munki_check = (options.installonly or applesoftwareupdatesonly)
|
||||
if not skip_munki_check:
|
||||
@@ -772,15 +779,15 @@ def main():
|
||||
else:
|
||||
# check the normal preferences
|
||||
should_do_apple_updates = munkicommon.pref(
|
||||
'InstallAppleSoftwareUpdates')
|
||||
'InstallAppleSoftwareUpdates')
|
||||
|
||||
if should_do_apple_updates:
|
||||
if (not options.installonly and not munkicommon.stopRequested()):
|
||||
if not options.installonly and not munkicommon.stopRequested():
|
||||
force_update_check = False
|
||||
force_catalog_refresh = False
|
||||
if (options.manualcheck or runtype == 'checkandinstallatstartup'):
|
||||
if options.manualcheck or runtype == 'checkandinstallatstartup':
|
||||
force_update_check = True
|
||||
if (runtype == 'custom' and applesoftwareupdatesonly):
|
||||
if runtype == 'custom' and applesoftwareupdatesonly:
|
||||
force_update_check = True
|
||||
force_catalog_refresh = True
|
||||
try:
|
||||
@@ -862,14 +869,14 @@ def main():
|
||||
munkicommon.log('Installing only items marked unattended '
|
||||
'because SuppressLoginwindowInstall is '
|
||||
'true.')
|
||||
ignore_restart = doInstallTasks(
|
||||
dummy_restart = doInstallTasks(
|
||||
appleupdatesavailable, only_unattended=True)
|
||||
elif getIdleSeconds() < 10:
|
||||
munkicommon.log('Skipping auto install at loginwindow '
|
||||
'because system is not idle '
|
||||
'(keyboard or mouse activity).')
|
||||
elif munkicommon.isAppRunning(
|
||||
'/System/Library/CoreServices/FileSyncAgent.app'):
|
||||
'/System/Library/CoreServices/FileSyncAgent.app'):
|
||||
munkicommon.log('Skipping auto install at loginwindow '
|
||||
'because FileSyncAgent.app is running '
|
||||
'(HomeSyncing a mobile account on login?).')
|
||||
@@ -886,14 +893,14 @@ def main():
|
||||
else: # there are GUI users
|
||||
if munkicommon.pref('SuppressAutoInstall'):
|
||||
munkicommon.log('Skipping unattended installs because '
|
||||
'SuppressAutoInstall is true.')
|
||||
'SuppressAutoInstall is true.')
|
||||
else:
|
||||
# check for packages that need to be force installed
|
||||
# soon and convert them to unattended_installs if they
|
||||
# don't require a logout
|
||||
dummy_action = updatecheck.checkForceInstallPackages()
|
||||
# install anything that can be done unattended
|
||||
ignore_restart = doInstallTasks(
|
||||
dummy_restart = doInstallTasks(
|
||||
appleupdatesavailable, only_unattended=True)
|
||||
|
||||
# send a notification event so MSU can update its display
|
||||
|
||||
Reference in New Issue
Block a user