Merge pull request #27240 from isbm/isbm-pkg.info-tz-bugfix-backport-2015.8

Backport of the fix of 'pkg.info*' for Beryllium
This commit is contained in:
Justin Findlay 2015-09-18 14:02:15 -06:00
commit 2d6c75cbd7
2 changed files with 11 additions and 6 deletions

View File

@ -287,7 +287,9 @@ def _get_pkg_info(*packages):
key, value = pkg_info_line.split(":", 1)
if value:
pkg_data[key] = value
pkg_data['install_date'] = _get_pkg_install_time(pkg_data.get('package'))
install_date = _get_pkg_install_time(pkg_data.get('package'))
if install_date:
pkg_data['install_date'] = install_date
pkg_data['description'] = pkg_descr.split(":", 1)[-1]
ret.append(pkg_data)
@ -318,11 +320,11 @@ def _get_pkg_install_time(pkg):
:return:
'''
iso_time = "N/A"
iso_time = None
if pkg is not None:
location = "/var/lib/dpkg/info/{0}.list".format(pkg)
if os.path.exists(location):
iso_time = datetime.datetime.fromtimestamp(os.path.getmtime(location)).isoformat()
iso_time = datetime.datetime.utcfromtimestamp(int(os.path.getmtime(location))).isoformat() + "Z"
return iso_time

View File

@ -406,9 +406,9 @@ def _pkg_time_to_iso(pkg_time):
:param pkg_time:
:return:
'''
ptime = time.strptime(pkg_time)
ptime = time.strptime(pkg_time, '%a %d %b %Y %H:%M:%S %p %Z')
return datetime.datetime(ptime.tm_year, ptime.tm_mon, ptime.tm_mday,
ptime.tm_hour, ptime.tm_min, ptime.tm_sec).isoformat()
ptime.tm_hour, ptime.tm_min, ptime.tm_sec).isoformat() + "Z"
def info(*packages):
@ -427,7 +427,10 @@ def info(*packages):
'''
cmd = packages and "rpm -qi {0}".format(' '.join(packages)) or "rpm -qai"
call = __salt__['cmd.run_all'](cmd + " --queryformat '-----\n'", output_loglevel='trace')
# Locale needs to be en_US instead of C, because RPM otherwise will yank the timezone from the timestamps
call = __salt__['cmd.run_all'](cmd + " --queryformat '-----\n'",
output_loglevel='trace', env={'LC_ALL': 'en_US', 'TZ': 'UTC'}, clean_env=True)
if call['retcode'] != 0:
comment = ''
if 'stderr' in call: