- Refinement of fix for ValueError: NSInvalidArgumentException - -[__NSTaggedDate UTF8String] error on Lion when managedsoftwareupdate attempts to notify the user of available updates.

- pylint cleanups.

git-svn-id: http://munki.googlecode.com/svn/trunk@1265 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
Greg Neagle
2011-08-02 21:11:50 +00:00
parent beb2ace07c
commit 1b91dfd626
+12 -10
View File
@@ -93,12 +93,13 @@ def set_file_nonblock(f, non_blocking=True):
"""
flags = fcntl.fcntl(f.fileno(), fcntl.F_GETFL)
if bool(flags & os.O_NONBLOCK) != non_blocking:
flags ^= os.O_NONBLOCK
flags ^= os.O_NONBLOCK
fcntl.fcntl(f.fileno(), fcntl.F_SETFL, flags)
class Popen(subprocess.Popen):
'''Subclass of subprocess.Popen to add support for
timeouts for some operations.'''
def timed_readline(self, f, timeout):
"""Perform readline-like operation with timeout.
@@ -113,7 +114,8 @@ class Popen(subprocess.Popen):
output = []
inactive = 0
while 1:
(rlist, wlist, xlist) = select.select([f], [], [], 1.0)
(rlist, unused_wlist, unused_xlist) = select.select(
[f], [], [], 1.0)
if not rlist:
inactive += 1 # approx -- py select doesn't return tv
@@ -133,11 +135,11 @@ class Popen(subprocess.Popen):
else:
return ''.join(output)
def communicate(self, input=None, timeout=0):
def communicate(self, std_in=None, timeout=0):
"""Communicate, optionally ending after a timeout of no activity.
Args:
input: str, to send on stdin
std_in: str, to send on stdin
timeout: int, seconds of inactivity to raise error at
Returns:
(str or None, str or None) for stdout, stderr
@@ -145,7 +147,7 @@ class Popen(subprocess.Popen):
TimeoutError, if timeout is reached
"""
if timeout <= 0:
return super(Popen, self).communicate(input=input)
return super(Popen, self).communicate(input=std_in)
fds = []
stdout = []
@@ -163,7 +165,8 @@ class Popen(subprocess.Popen):
returncode = None
while returncode is None:
(rlist, wlist, xlist) = select.select(fds, [], [], 1.0)
(rlist, unused_wlist, unused_xlist) = select.select(
fds, [], [], 1.0)
if not rlist:
inactive += 1
@@ -286,7 +289,7 @@ def concat_log_message(msg, *args):
args = [str_to_ascii(arg) for arg in args]
try:
msg = msg % tuple(args)
except TypeError, e:
except TypeError, err:
warnings.warn(
'String format does not match concat args: %s' % (
str(sys.exc_info())))
@@ -830,8 +833,7 @@ def pref(pref_name):
# /Library/Preferences/<BUNDLE_ID>.plist for admin
# discoverability
set_pref(pref_name, pref_value)
if type(pref_value).__name__ in ['__NSCFDate', '__NSDate', '__CFDate',
'__NSTaggedDate']:
if isinstance(pref_value, NSDate):
# convert NSDate/CFDates to strings
pref_value = str(pref_value)
return pref_value