swc-installation-test-2.py: Convert PathCommandDependency to VersionPlistCommandDepen...
authorW. Trevor King <wking@tremily.us>
Sun, 25 Jan 2015 23:32:14 +0000 (15:32 -0800)
committerW. Trevor King <wking@tremily.us>
Sun, 25 Jan 2015 23:32:14 +0000 (15:32 -0800)
commit14156218b0013d670a82783e33b14e5a15d1b252
treef03c237a43871f12c7fd657d9f13f109ad20b7f8
parentd13b26c9fb89beebe9ff9e9dfc86ba8ddb8d01cd
swc-installation-test-2.py: Convert PathCommandDependency to VersionPlistCommandDependency

Philip Guo suggested using version.plist to lookup the version number
for applications on OS X [1].  Searching around, I found an example of
Safari's version.plist posted by ASmit010 [2]:

  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
       <key>BuildVersion</key>
       <string>1</string>
       <key>CFBundleShortVersionString</key>
       <string>5.1.7</string>
       <key>CFBundleVersion</key>
       <string>7534.57.2</string>
       <key>ProjectName</key>
       <string>WebBrowser</string>
       <key>SourceVersion</key>
       <string>7534057002000000</string>
  </dict>
  </plist>

Looking at that example, the version information we want is associated
with CFBundleShortVersionString [3]:

  CFBundleShortVersionString (String - iOS, OS X) specifies the
  release version number of the bundle, which identifies a released
  iteration of the app. The release version number is a string
  comprised of three period-separated integers. The first integer
  represents major revisions to the app, such as revisions that
  implement new features or major changes. The second integer denotes
  revisions that implement less prominent features. The third integer
  represents maintenance releases.

  The value for this key differs from the value for CFBundleVersion,
  which identifies an iteration (released or unreleased) of the
  app. This key can be localized by including it in your
  InfoPlist.strings files

The sibling-entries for keys and values are a bit awkward using
Python's stock ElementTree [4,5], which doesn't have built-in methods
for finding parents or siblings [6].  I've followed the example set by
lxml and added _get_parent and _get_next helpers (mirroring getparent
[7] and getnext [8]) to make it the logic in _get_version_from_plist
more clear.

[1]: https://twitter.com/pgbovine/status/559094439009075203
[2]: https://discussions.apple.com/message/19757845#19757845
[3]: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-111349
[4]: https://docs.python.org/2/library/xml.etree.elementtree.html
[5]: https://docs.python.org/3/library/xml.etree.elementtree.html
[6]: http://lxml.de/1.3/api.html#trees-and-documents
[7]: http://lxml.de/api/lxml.etree._Element-class.html#getparent
[8]: http://lxml.de/api/lxml.etree._Element-class.html#getnext
swc-installation-test-2.py