def get_bundle_data(path): path = os.path.abspath(path) info = os.path.join(path, 'Contents', 'Info.plist') ans = { 'name': os.path.splitext(os.path.basename(path))[0], 'path': path, } try: with open(info, 'rb') as f: plist = loads(f.read()) except Exception: return None ans['name'] = plist.get('CFBundleDisplayName') or plist.get( 'CFBundleName') or ans['name'] icfile = plist.get('CFBundleIconFile') if icfile: icfile = os.path.join(path, 'Contents', 'Resources', icfile) if not os.path.exists(icfile): icfile += '.icns' if os.path.exists(icfile): ans['icon_file'] = icfile bid = plist.get('CFBundleIdentifier') if bid: ans['identifier'] = bid ans['extensions'] = extensions = set() for dtype in plist.get('CFBundleDocumentTypes', ()): utis = frozenset(dtype.get('LSItemContentTypes', ())) if utis: extensions |= get_extensions_from_utis(utis, plist) else: for ext in dtype.get('CFBundleTypeExtensions', ()): if isinstance(ext, string_or_bytes): extensions.add(ext.lower()) for mt in dtype.get('CFBundleTypeMIMETypes', ()): if isinstance(mt, string_or_bytes): for ext in mimetypes.guess_all_extensions(mt, strict=False): extensions.add(ext.lower()) return ans
def get_bundle_data(path): path = os.path.abspath(path) info = os.path.join(path, 'Contents', 'Info.plist') ans = { 'name': os.path.splitext(os.path.basename(path))[0], 'path': path, } try: with open(info, 'rb') as f: plist = loads(f.read()) except Exception: return None ans['name'] = plist.get('CFBundleDisplayName') or plist.get('CFBundleName') or ans['name'] icfile = plist.get('CFBundleIconFile') if icfile: icfile = os.path.join(path, 'Contents', 'Resources', icfile) if not os.path.exists(icfile): icfile += '.icns' if os.path.exists(icfile): ans['icon_file'] = icfile bid = plist.get('CFBundleIdentifier') if bid: ans['identifier'] = bid ans['extensions'] = extensions = set() for dtype in plist.get('CFBundleDocumentTypes', ()): utis = frozenset(dtype.get('LSItemContentTypes', ())) if utis: extensions |= get_extensions_from_utis(utis, plist) else: for ext in dtype.get('CFBundleTypeExtensions', ()): if isinstance(ext, string_or_bytes): extensions.add(ext.lower()) for mt in dtype.get('CFBundleTypeMIMETypes', ()): if isinstance(mt, string_or_bytes): for ext in mimetypes.guess_all_extensions(mt, strict=False): extensions.add(ext.lower()) return ans
def raw_to_object(self, raw): from polyglot.plistlib import loads return loads(raw)