mirror of
https://github.com/munki/munki.git
synced 2026-05-04 11:29:16 -05:00
Changed ManagedInstallReport.plist timestamps to ISO 8601 format, with timezone information.
git-svn-id: http://munki.googlecode.com/svn/trunk@852 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
@@ -547,7 +547,7 @@ def main():
|
||||
munkicommon.rotate_main_log()
|
||||
munkicommon.archive_report()
|
||||
# start a new report
|
||||
munkicommon.report['StartTime'] = time.ctime()
|
||||
munkicommon.report['StartTime'] = munkicommon.format_time()
|
||||
munkicommon.report['RunType'] = runtype
|
||||
|
||||
munkicommon.log("### Starting managedsoftwareupdate run ###")
|
||||
@@ -660,7 +660,7 @@ def main():
|
||||
|
||||
munkicommon.log("### Ending managedsoftwareupdate run ###")
|
||||
# finish our report
|
||||
munkicommon.report['EndTime'] = time.ctime()
|
||||
munkicommon.report['EndTime'] = munkicommon.format_time()
|
||||
munkicommon.report['ManagedInstallVersion'] = munkicommon.get_version()
|
||||
munkicommon.report['AvailableDiskSpace'] = \
|
||||
munkicommon.getAvailableDiskSpace()
|
||||
|
||||
@@ -223,6 +223,31 @@ def display_error(msg):
|
||||
report['Errors'].append(msg)
|
||||
|
||||
|
||||
def format_time(t=None, tz=None, alttz=None):
|
||||
"""Return struct_time as an ISO 8601 formatted string, with timezone information.
|
||||
If t is not given the current local time is used. If timezone information is
|
||||
not given, the local timezone and alternate timezone is used."""
|
||||
# get the current local time
|
||||
if t is None:
|
||||
t = time.localtime()
|
||||
# get the current local timezone offset
|
||||
if tz is None:
|
||||
tz = time.timezone
|
||||
if alttz is None:
|
||||
alttz = time.altzone
|
||||
# calculate UTC offset. NOTE: POSIX uses inverted UTC offset as timezone
|
||||
if t.tm_isdst:
|
||||
utcoffset = -alttz
|
||||
else:
|
||||
utcoffset = -tz
|
||||
# convert UTC offset in seconds to hours and minutes
|
||||
utcoffset_h = (utcoffset / 60) / 60
|
||||
utcoffset_m = (utcoffset / 60) % 60
|
||||
utcoffset_sign = "+" if utcoffset >= 0 else "-"
|
||||
utcoffset_string = " %s%02d%02d" % (utcoffset_sign, utcoffset_h, utcoffset_m)
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", t) + utcoffset_string
|
||||
|
||||
|
||||
def log(msg, logname=''):
|
||||
"""Generic logging function"""
|
||||
# date/time format string
|
||||
|
||||
Reference in New Issue
Block a user