diff options
-rw-r--r-- | cerbero/packages/osx/info_plist.py | 57 | ||||
-rw-r--r-- | test/test_cerbero_packages_osx_info_plist.py | 81 |
2 files changed, 120 insertions, 18 deletions
diff --git a/cerbero/packages/osx/info_plist.py b/cerbero/packages/osx/info_plist.py index fcf23a24..e2f3517f 100644 --- a/cerbero/packages/osx/info_plist.py +++ b/cerbero/packages/osx/info_plist.py @@ -22,35 +22,56 @@ INFO_PLIST_TPL='''\ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> - <key>CFBundleName</key> - <string>%(name)s</string> - <key>CFBundleIdentifier</key> - <string>%(identifier)s</string> - <key>CFBundleVersion</key> - <string>%(version)s</string> - <key>CFBundleSignature</key> - <string>????</string> - <key>CFBundlePackageType</key> - <string>FMWK</string> - <key>CFBundleGetInfoString</key> - <string>%(info)s</string> +%s </dict> </plist> ''' -class FrameworkPlist(object): - ''' Create a Info.plist file with the framework info ''' +class InfoPlist(object): + ''' Create a Info.plist file ''' - def __init__(self, name, identifier, version, info): + package_type = '' + + def __init__(self, name, identifier, version, info, icon=None): self.name = name self.identifier = identifier self.version = version self.info = info + self.icon = icon + + def format_property(self, key, value): + return '<key>%s</key>\n<string>%s</string>' % (key, value) + + def get_properties(self): + properties = {'CFBundleName': self.name, + 'CFBundleIdentifier': self.identifier, + 'CFBundleVersion': self.version, + 'CFBundlePackageGetInfoString': self.info, + 'CFBundlePackageType': self.package_type} + if self.icon: + properties['CFBundleIconFile'] = self.icon + return properties + + def get_properties_string(self): + props = self.get_properties() + return '\n'.join([self.format_property(k, props[k]) for k in + sorted(props.keys())]) def save(self, filename): - props = {'name': self.name, 'identifier': self.identifier, - 'version': self.version, 'info': self.info} + props_str = self.get_properties_string() with open(filename, 'w+') as f: - f.write(INFO_PLIST_TPL % props) + f.write(INFO_PLIST_TPL % props_str) + + +class FrameworkPlist(InfoPlist): + ''' Create a Info.plist file for frameworks ''' + + package_type = 'FMWK' + + + +class ApplicationPlist(InfoPlist): + ''' Create a Info.plist file for applications ''' + package_type = 'APPL' diff --git a/test/test_cerbero_packages_osx_info_plist.py b/test/test_cerbero_packages_osx_info_plist.py new file mode 100644 index 00000000..7dfb1f65 --- /dev/null +++ b/test/test_cerbero_packages_osx_info_plist.py @@ -0,0 +1,81 @@ +# cerbero - a multi-platform build system for Open Source software +# Copyright (C) 2012 Andoni Morales Alastruey <ylatuya@gmail.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import unittest +import tempfile + +from cerbero.packages.osx.info_plist import InfoPlist, FrameworkPlist,\ + ApplicationPlist, INFO_PLIST_TPL + + +class InfoPlistTest(unittest.TestCase): + + PROPS_TPL = ('%(icon)s<key>CFBundleIdentifier</key>\n' + '<string>test.org</string>\n' + '<key>CFBundleName</key>\n' + '<string>test</string>\n' + '<key>CFBundlePackageGetInfoString</key>\n' + '<string>Test package</string>\n' + '<key>CFBundlePackageType</key>\n' + '<string>%(ptype)s</string>\n' + '<key>CFBundleVersion</key>\n' + '<string>1.0</string>') + + def setUp(self): + self.info_plist = InfoPlist('test', 'test.org', '1.0', + 'Test package') + + def testFormatProperty(self): + self.assertEquals('<key>Key</key>\n<string>Value</string>', + self.info_plist.format_property('Key', 'Value')) + + def testGetPropertiesString(self): + result = self.info_plist.get_properties_string() + expected = self.PROPS_TPL % {'icon': '', 'ptype': ''} + self.assertEquals(result, expected) + + def testFrameworkPackageType(self): + self.info_plist = FrameworkPlist('test', 'test.org', '1.0', + 'Test package') + result = self.info_plist.get_properties_string() + expected = self.PROPS_TPL % {'ptype': 'FMWK', 'icon': ''} + self.assertEquals(result, expected) + + def testApplicationPackageType(self): + self.info_plist = ApplicationPlist('test', 'test.org', '1.0', + 'Test package') + result = self.info_plist.get_properties_string() + expected = self.PROPS_TPL % {'ptype': 'APPL', 'icon': ''} + self.assertEquals(result, expected) + + def testGetPropertiesStringWithIcon(self): + self.info_plist.icon = 'test.ico' + result = self.info_plist.get_properties_string() + expected = self.PROPS_TPL % {'ptype': '', 'icon': + self.info_plist.format_property('CFBundleIconFile', 'test.ico') + + '\n'} + self.info_plist.icon = None + self.assertEquals(result, expected) + + def testSave(self): + tmp = tempfile.NamedTemporaryFile() + self.info_plist.save(tmp.name) + with open(tmp.name, 'r') as f: + result = f.read() + expected = INFO_PLIST_TPL % self.info_plist.get_properties_string() + self.assertEquals(result, expected) |