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)
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.BEGIN, self.info_plist._get_properties_string(), self.info_plist.END) self.assertEquals(result, expected)
def create_bundle(self, tmp=None): ''' Creates the Application bundle structure Contents/MacOS/MainExectuable -> Contents/Home/bin/main-executable Contents/Info.plist ''' tmp = tmp or tempfile.mkdtemp() contents = os.path.join(tmp, 'Contents') macos = os.path.join(contents, 'MacOS') resources = os.path.join(contents, 'Resources') for p in [contents, macos, resources]: if not os.path.exists(p): os.makedirs(p) # Create Contents/Info.plist # Use the template if provided in the package plist_tpl = None if os.path.exists(self.package.resources_info_plist): plist_tpl = open(self.package.resources_info_plist).read() framework_plist = ApplicationPlist(self.package.app_name, self.package.org, self.package.version, self.package.shortdesc, self.package.config.min_osx_sdk_version, os.path.basename(self.package.resources_icon_icns), plist_tpl) framework_plist.save(os.path.join(contents, 'Info.plist')) # Copy app icon to Resources shutil.copy(self.package.resources_icon_icns, resources) for f in self.package.osx_resources: f = self.package.relative_path(f) shutil.copy(f, resources) # Link or create a wrapper for the executables in Contents/MacOS for name, path, use_wrapper, wrapper in self.package.get_commands(): filename = os.path.join(macos, name) if use_wrapper: wrapper = self.package.get_wrapper(path, wrapper) if not wrapper: continue with open(filename, 'w') as f: f.write(wrapper) shell.call('chmod +x "%s"' % filename) else: # FIXME: We need to copy the binary instead of linking, because # beeing a different path, @executable_path will be different # and it we will need to set a different relative path with # install_name_tool shutil.copy(os.path.join(contents, 'Home', path), filename) return tmp
def create_bundle(self, tmp=None): ''' Creates the Application bundle structure Contents/MacOS/MainExectuable -> Contents/Home/bin/main-executable Contents/Info.plist ''' tmp = tmp or tempfile.mkdtemp() contents = os.path.join(tmp, 'Contents') macos = os.path.join(contents, 'MacOS') resources = os.path.join(contents, 'Resources') for p in [contents, macos, resources]: if not os.path.exists(p): os.makedirs(p) # Create Contents/Info.plist # Use the template if provided in the package plist_tpl = None if os.path.exists(self.package.resources_info_plist): plist_tpl = open(self.package.resources_info_plist).read() framework_plist = ApplicationPlist( self.package.app_name, self.package.org, self.package.version, self.package.shortdesc, self.package.config.min_osx_sdk_version, os.path.basename(self.package.resources_icon_icns), plist_tpl) framework_plist.save(os.path.join(contents, 'Info.plist')) # Copy app icon to Resources shutil.copy(self.package.resources_icon_icns, resources) for f in self.package.osx_resources: f = self.package.relative_path(f) shutil.copy(f, resources) # Link or create a wrapper for the executables in Contents/MacOS for name, path, use_wrapper, wrapper in self.package.get_commands(): filename = os.path.join(macos, name) if use_wrapper: wrapper = self.package.get_wrapper(path, wrapper) if not wrapper: continue with open(filename, 'w') as f: f.write(wrapper) shell.call('chmod +x "%s"' % filename) else: # FIXME: We need to copy the binary instead of linking, because # beeing a different path, @executable_path will be different # and it we will need to set a different relative path with # install_name_tool shutil.copy(os.path.join(contents, 'Home', path), filename) return tmp