mirror of
https://github.com/munki/munki.git
synced 2026-04-23 04:59:17 -05:00
Various cleanups: replaced use of dateutil.dateparse methods with NSDate methods, etc.
git-svn-id: http://munki.googlecode.com/svn/trunk@459 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
+10
-2
@@ -19,6 +19,7 @@ Launches an app only if we're called in the current
|
||||
GUI user's session.
|
||||
Prevents multiple copies of the app from being launched
|
||||
when Fast User Switching is in use
|
||||
Intended for use by a launchd LaunchAgent.
|
||||
"""
|
||||
|
||||
import sys
|
||||
@@ -46,13 +47,20 @@ def main():
|
||||
if (consoleuser == thisuser) or \
|
||||
(consoleuser == None and thisuser == "root"):
|
||||
p = optparse.OptionParser()
|
||||
p.add_option('-a', action='store_true')
|
||||
p.add_option('-b', action='store_true')
|
||||
options, arguments = p.parse_args()
|
||||
cmd = ["/usr/bin/open"]
|
||||
if options.b:
|
||||
cmd.append("-b")
|
||||
else:
|
||||
cmd.append("-a")
|
||||
try:
|
||||
app = arguments[0]
|
||||
cmd.append(arguments[0])
|
||||
except:
|
||||
print >>sys.stderr, "Must specify an app to launch!"
|
||||
exit(-1)
|
||||
retcode = subprocess.call(["/usr/bin/open", "-a", app])
|
||||
retcode = subprocess.call(cmd)
|
||||
exit(retcode)
|
||||
else:
|
||||
# sleep 10 seconds so we don't trigger launchd throttling
|
||||
|
||||
@@ -20,12 +20,14 @@ managedsoftwareupdate
|
||||
import sys
|
||||
import os
|
||||
import optparse
|
||||
import datetime
|
||||
import dateutil.parser
|
||||
#import datetime
|
||||
#import dateutil.parser
|
||||
import subprocess
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from Foundation import NSDate
|
||||
|
||||
from munkilib import munkicommon
|
||||
from munkilib import updatecheck
|
||||
from munkilib import installer
|
||||
@@ -178,10 +180,10 @@ def munkiUpdatesAvailable():
|
||||
|
||||
def recordUpdateCheckResult(result):
|
||||
# record last check date and result
|
||||
nowString = munkicommon.NSDateNowString()
|
||||
now = NSDate.new()
|
||||
cmd = ['/usr/bin/defaults', 'write',
|
||||
'/Library/Preferences/ManagedInstalls',
|
||||
'LastCheckDate', '-date', nowString]
|
||||
'LastCheckDate', '-date', str(now)]
|
||||
retcode = subprocess.call(cmd)
|
||||
cmd = ['/usr/bin/defaults', 'write',
|
||||
'/Library/Preferences/ManagedInstalls',
|
||||
@@ -195,22 +197,22 @@ def notifyUserOfUpdates(manualcheck=False):
|
||||
# if we haven't notified in a while, notify:
|
||||
lastNotifiedString = munkicommon.pref('LastNotifiedDate')
|
||||
daysBetweenNotifications = munkicommon.pref('DaysBetweenNotifications')
|
||||
nowString = munkicommon.NSDateNowString()
|
||||
now = dateutil.parser.parse(nowString)
|
||||
now = NSDate.new()
|
||||
nextNotifyDate = now
|
||||
if lastNotifiedString:
|
||||
lastNotifiedDate = dateutil.parser.parse(lastNotifiedString)
|
||||
interval = datetime.timedelta(days=daysBetweenNotifications)
|
||||
lastNotifiedDate = NSDate.dateWithString_(lastNotifiedString)
|
||||
interval = daysBetweenNotifications * (24 * 60 * 60)
|
||||
if daysBetweenNotifications > 0:
|
||||
# we make this adjustment so a "daily" notification
|
||||
# doesn't require 24 hours to elapse
|
||||
interval = interval - datetime.timedelta(hours=6)
|
||||
nextNotifyDate = lastNotifiedDate + interval
|
||||
if now >= nextNotifyDate or manualcheck:
|
||||
# subtract 6 hours
|
||||
interval = interval - (6 * 60 * 60)
|
||||
nextNotifyDate = lastNotifiedDate.dateByAddingTimeInterval_(interval)
|
||||
if now.timeIntervalSinceDate_(nextNotifyDate) > 0 or manualcheck:
|
||||
# record current notification date
|
||||
cmd = ['/usr/bin/defaults', 'write',
|
||||
'/Library/Preferences/ManagedInstalls',
|
||||
'LastNotifiedDate', '-date', now.ctime()]
|
||||
'LastNotifiedDate', '-date', str(now)]
|
||||
retcode = subprocess.call(cmd)
|
||||
# notify user of available updates using LaunchAgent to start
|
||||
# Managed Software Update.app in the user context
|
||||
@@ -410,6 +412,10 @@ def main():
|
||||
print "Copyright 2010 The Munki Project"
|
||||
print "http://code.google.com/p/munki\n"
|
||||
|
||||
if options.manualcheck:
|
||||
# pre-heat MunkiStatus
|
||||
munkistatus.activate()
|
||||
|
||||
updatecheckresult = None
|
||||
if not options.installonly:
|
||||
try:
|
||||
|
||||
@@ -24,13 +24,15 @@ Utilities for dealing with Apple Software Update.
|
||||
import sys
|
||||
import os
|
||||
import stat
|
||||
import FoundationPlist
|
||||
import re
|
||||
import subprocess
|
||||
import dateutil.parser
|
||||
import datetime
|
||||
#import dateutil.parser
|
||||
#import datetime
|
||||
from xml.dom import minidom
|
||||
|
||||
from Foundation import NSDate
|
||||
|
||||
import FoundationPlist
|
||||
import munkicommon
|
||||
import munkistatus
|
||||
import installer
|
||||
@@ -407,8 +409,7 @@ def appleSoftwareUpdatesAvailable(forcecheck=False, suppresscheck=False):
|
||||
else:
|
||||
# have we checked recently? Don't want to check with
|
||||
# Apple Software Update server too frequently
|
||||
nowString = munkicommon.NSDateNowString()
|
||||
now = dateutil.parser.parse(nowString)
|
||||
now = NSDate.new()
|
||||
nextSUcheck = now
|
||||
cmd = ['/usr/bin/defaults', 'read',
|
||||
'/Library/Preferences/com.apple.softwareupdate',
|
||||
@@ -421,12 +422,12 @@ def appleSoftwareUpdatesAvailable(forcecheck=False, suppresscheck=False):
|
||||
lastSUcheckString = out.rstrip('\n')
|
||||
if lastSUcheckString:
|
||||
try:
|
||||
lastSUcheck = dateutil.parser.parse(lastSUcheckString)
|
||||
interval = datetime.timedelta(hours=24)
|
||||
nextSUcheck = lastSUcheck + interval
|
||||
lastSUcheck = NSDate.dateWithString_(lastSUcheckString)
|
||||
interval = 24 * 60 * 60
|
||||
nextSUcheck = lastSUcheck.dateByAddingTimeInterval_(interval)
|
||||
except ValueError:
|
||||
pass
|
||||
if now >= nextSUcheck:
|
||||
if now.timeIntervalSinceDate_(nextSUcheck) > 0:
|
||||
retcode = checkForSoftwareUpdates()
|
||||
|
||||
return writeAppleUpdatesFile()
|
||||
|
||||
@@ -33,7 +33,7 @@ import urllib2
|
||||
from distutils import version
|
||||
from xml.dom import minidom
|
||||
|
||||
from Foundation import NSDictionary, NSDate
|
||||
#from Foundation import NSDictionary, NSDate
|
||||
#from CoreFoundation import CFPreferencesCopyAppValue
|
||||
|
||||
import munkistatus
|
||||
@@ -476,14 +476,6 @@ def isApplication(pathname):
|
||||
#####################################################
|
||||
|
||||
|
||||
def NSDateNowString():
|
||||
'''
|
||||
Generates a NSDate-compatible string
|
||||
'''
|
||||
now = NSDate.new()
|
||||
return str(now)
|
||||
|
||||
|
||||
def getManagedInstallsPrefs():
|
||||
# define default values
|
||||
prefs = {}
|
||||
|
||||
@@ -115,7 +115,7 @@ def getMunkiStatusPID():
|
||||
|
||||
|
||||
def getMunkiStatusSocket():
|
||||
for i in range(0,10):
|
||||
for i in range(10):
|
||||
pid = getMunkiStatusPID()
|
||||
if pid:
|
||||
socketpath = "/tmp/com.googlecode.munki.munkistatus.%s" % pid
|
||||
@@ -123,7 +123,7 @@ def getMunkiStatusSocket():
|
||||
return socketpath
|
||||
else:
|
||||
# sleep and try again
|
||||
time.sleep(.2)
|
||||
time.sleep(.5)
|
||||
return ""
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import urllib2
|
||||
import urlparse
|
||||
import httplib
|
||||
import hashlib
|
||||
import datetime
|
||||
#import datetime
|
||||
import time
|
||||
import calendar
|
||||
import socket
|
||||
|
||||
Reference in New Issue
Block a user