def local_version(self, pkg_id):
cmd = ['/usr/sbin/pkgutil', '--pkg-info-plist', pkg_id]
(result, error) = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() # NOQA
if result:
try:
ver = plistlib.readPlistFromString(result)['pkg-version']
except:
# If the plist can't be read, or throws an exception, the package is probably not installed. # NOQA
ver = '0.0.0'
if error:
# If there is an error, then the package is probably not installed.
# Unlikely to happen, because Apple seems to send stderr to stdout here. # NOQA
ver = '0.0.0'
return ver
评论列表
文章目录