[utils] Add helpers for CrossOver on macOS

This commit is contained in:
derrod 2021-12-29 12:54:49 +01:00
parent 33b89f5e9a
commit b5a2fba896

View file

@ -0,0 +1,50 @@
import logging
import plistlib
import os
import subprocess
logger = logging.getLogger('CXHelpers')
def mac_get_crossover_version(app_path):
try:
plist = plistlib.load(open(os.path.join(app_path, 'Contents', 'Info.plist'), 'rb'))
return plist['CFBundleShortVersionString']
except Exception as e:
logger.debug(f'Failed to load plist for "{app_path}" with {e!r}')
return None
def mac_find_crossover_apps():
paths = ['/Applications/CrossOver.app']
try:
out = subprocess.check_output(['mdfind', 'kMDItemCFBundleIdentifier="com.codeweavers.CrossOver"'])
paths.extend(out.decode('utf-8', 'replace').strip().split('\n'))
except Exception as e:
logger.warning(f'Trying to find CrossOver installs via mdfind failed: {e!r}')
valid = [p for p in paths if os.path.exists(os.path.join(p, 'Contents', 'Info.plist'))]
found_tuples = set()
for path in valid:
version = mac_get_crossover_version(path)
if not version:
continue
logger.debug(f'Found Crossover {version} at "{path}"')
found_tuples.add((version, path))
return sorted(found_tuples, reverse=True)
def mac_get_crossover_bottles():
bottles_path = os.path.expanduser('~/Library/Application Support/CrossOver/Bottles')
if not os.path.exists(bottles_path):
return []
return sorted(p for p in os.listdir(bottles_path) if
os.path.isdir(os.path.join(bottles_path, p)) and
os.path.exists(os.path.join(bottles_path, p, 'cxbottle.conf')))
def mac_is_valid_bottle(bottle_name):
bottles_path = os.path.expanduser('~/Library/Application Support/CrossOver/Bottles')
return os.path.exists(os.path.join(bottles_path, bottle_name, 'cxbottle.conf'))