Last active
November 27, 2020 08:52
-
-
Save carlashley/21fb88b57983d966678cd28dd5285f3b to your computer and use it in GitHub Desktop.
Bulk add the arm64,x86_64 host architecture value to Packages .pkgproj files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3 | |
"""Bulk adds the 'arm64,x86_64' value as and advanced option for '.pkgproj' files. | |
Walks all sub directories specified at '[path]' for '.pkgproj' files, makes a backup | |
file in the same destination. | |
Does not add the value if a value already exists. | |
Usage: ./add_hostArchitectures.py [path] | |
Tested with Python 3.7.9. | |
""" | |
import os | |
import plistlib | |
import shutil | |
import sys | |
from pathlib import Path, PurePath | |
NAME = sys.argv[0] | |
try: | |
WORK_DIR = sys.argv[1] | |
except IndexError: | |
print('Usage: {} [path]'.format(NAME)) | |
sys.exit(1) | |
_PKGPROJS = set() | |
_ARCH = ['arm64,x86_64'] | |
for _root, _, _files in os.walk(WORK_DIR): | |
for _f in _files: | |
_path = Path(_root) / _f | |
_pure_path = PurePath(_path) | |
if _pure_path.suffix == '.pkgproj': | |
_PKGPROJS.add(_path) | |
_dest_folder = str(_pure_path.parent) | |
_backup = Path(_dest_folder) / '{}.backup'.format(str(_path)) | |
if not _backup.exists(): | |
shutil.copy2(str(_path), str(_backup)) | |
for _proj in _PKGPROJS: | |
with open(str(_proj), 'rb') as _f: | |
_plist = plistlib.load(_f) | |
if not _plist['PROJECT']['PROJECT_SETTINGS'].get('ADVANCED_OPTIONS'): | |
_plist['PROJECT']['PROJECT_SETTINGS']['ADVANCED_OPTIONS'] = {'installer-script.options:hostArchitectures': _ARCH} | |
_f.close() | |
with open(str(_proj), 'wb') as _f: | |
plistlib.dump(_plist, _f, fmt=plistlib.FMT_XML) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment