[Pythonmac-SIG] obtaining versions of application bundles
brad.allen at omsdal.com
brad.allen at omsdal.com
Fri Oct 22 23:48:48 CEST 2004
It looks like there are some CFM apps where the 'plst' resource doesn't
agree with the 'vers' resource. In the case of Lotus Notes 6.5.1, the
developer must have failed to keep the data in the 'plst' resource current,
but it is current in the 'vers' resource. The 'plst' resource reports
version 6.0. (see below).
#this is a slightly edited version of Bob Ippolito's appVersion function
posted on the Pythonmac mailing list
from Carbon.File import FSRef, FSGetResourceForkName
from Carbon.Files import fsRdPerm
from Carbon.Res import FSOpenResourceFile, CloseResFile, UseResFile,
Get1Resource
from cStringIO import StringIO
import os, plistlibTest #this is a test version of plistlib by Bob Ippolito
def getInfoPlistForApp(app):
if os.path.isdir(app):
return plistlibTest.Plist.fromFile(os.path.join(app, 'Contents',
'Info.plist'))
fsRef = FSRef(app)
resId = FSOpenResourceFile(fsRef, FSGetResourceForkName(), fsRdPerm)
UseResFile(resId)
plistData = StringIO(Get1Resource('plst', 0).data)
CloseResFile(resId)
return plistlibTest.Plist.fromFile(plistData)
def getAppVersion(app):
return getInfoPlistForApp(app)['CFBundleVersion']
if __name__ == '__main__':
#for testing
print 'Mach-O example:
Timbuktu',getAppVersion('/Applications/Timbuktu Pro/Timbuktu Pro.app')
print ' Correct answer: 7.03'
print 'CFM example: Lotus Notes',getAppVersion('/Users/ballen/Lotus
Notes/Notes')
print ' Correct answer: 6.5.1'
#---------------output posted below------------------------
Mach-O example: Timbuktu 7.0.3
Correct answer: 7.03
CFM example: Lotus Notes 6.0
Correct answer: 6.5.1
More information about the Pythonmac-SIG
mailing list