Skip to content

Commit 39a9c80

Browse files
authored
Merge pull request #13 from dortania/py3
Rewrite for Python 3 support
2 parents ca18f4f + b8381a8 commit 39a9c80

File tree

149 files changed

+22325
-13522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+22325
-13522
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
ignore = E501
3+
per-file-ignores =
4+
Resources/Constants.py:E704

.github/workflows/main.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
release:
8+
types: [published]
9+
10+
jobs:
11+
build:
12+
name: Build
13+
runs-on: macos-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Python 3
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: "3.x"
21+
- name: Install Python Dependencies
22+
run: |
23+
python3 -m pip install -U pip
24+
pip3 install pyinstaller
25+
26+
- run: pyinstaller Opencore-Patcher.spec
27+
- run: cd dist; zip ../OpenCore-Patcher.zip OpenCore-Patcher
28+
29+
- name: Upload to Artifacts
30+
uses: actions/upload-artifact@v2
31+
with:
32+
path: OpenCore-Patcher.zip
33+
- name: Upload to Release
34+
if: github.event_name == 'release'
35+
uses: svenstaro/upload-release-action@e74ff71f7d8a4c4745b560a485cc5fdb9b5b999d
36+
with:
37+
repo_token: ${{ secrets.GITHUB_TOKEN }}
38+
file: OpenCore-Patcher.zip
39+
tag: ${{ github.ref }}
40+
file_glob: true

.pylintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[MASTER]
2+
3+
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
4+
5+
[MESSAGES CONTROL]
6+
7+
disable=unused-import,
8+
subprocess-run-check,
9+
line-too-long,
10+
too-few-public-methods,
11+
missing-module-docstring,
12+
missing-class-docstring,
13+
missing-function-docstring

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## 0.0.11
44
- Re-add OpenCore GUI
5+
- Rewrite in py3
6+
- Add OpenCore-Patcher binary for releases avoiding local python requirement
7+
- Increment binaries
8+
- OpenCore cbd2fa3(0.6.7 release)
9+
- WhateverGreen 2e19d1b(1.4.8 release)
10+
- Rework SMBIOS allowing both original and custom serials(Should resolve all iMessage issues)
11+
- Support upgraded GPU detection in iMac10,x-12,x
12+
- Add Wifi card upgrade detection
513

614
## 0.0.10
715
- Increment binaries

Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
<key>LSMultipleInstancesProhibited</key>
2828
<true/>
2929
<key>NSHumanReadableCopyright</key>
30-
<string>Copyright 2020 Dortania</string>
30+
<string>Copyright 2021 Dortania</string>
3131
</dict>
3232
</plist>

OpenCore-Patcher.command

Lines changed: 90 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -1,208 +1,94 @@
1-
#!/usr/bin/env python
2-
from __future__ import print_function
1+
#!/usr/bin/env python3
32

4-
from shutil import copy
5-
from shutil import rmtree
3+
from __future__ import print_function
64

7-
import os
8-
import json
95
import subprocess
10-
import sys
11-
import zipfile
12-
13-
from Resources import *
14-
15-
16-
# Allow py2 and 3 support
17-
try:
18-
input = raw_input
19-
except NameError:
20-
pass
21-
22-
# List build versions
23-
patcher_version = "0.0.11"
24-
25-
CustomSMBIOS=False
26-
MainMenu=True
27-
MenuWidth = 52
28-
header = '#' * MenuWidth
29-
subheader = '-' * MenuWidth
30-
31-
while MainMenu:
32-
os.system('clear')
33-
34-
print(header)
35-
print(" OpenCore Legacy patcher v%s" % patcher_version)
36-
print(" Current Model: %s" % BuildOpenCore.current_model)
37-
print(header)
38-
print("")
39-
if BuildOpenCore.current_model not in ModelArray.SupportedSMBIOS:
40-
print(" Your model is not supported by this patcher!")
41-
print("")
42-
print(" If you plan to create the USB for another machine,")
43-
print(" please select option 3")
44-
print(subheader)
45-
print("")
46-
elif BuildOpenCore.current_model in ("MacPro3,1", "iMac7,1"):
47-
print(" This model is supported")
48-
print(" However please ensure the CPU have been upgraded")
49-
print(" to support SSE4.1+")
50-
print(subheader)
51-
print("")
52-
else:
53-
print(" This model is supported")
54-
print(subheader)
55-
print("")
56-
print(" 1. Build OpenCore")
57-
print(" 2. Install OpenCore to USB/internal drive")
58-
print(" 3. Change model")
59-
print(" 4. Credits")
60-
print(" 5. Exit")
61-
print("")
62-
63-
MainMenu = input('Please select an option: ')
64-
65-
if MainMenu=="1":
66-
OpenCoreBuilderMenu=True
67-
while OpenCoreBuilderMenu:
68-
os.system('clear')
69-
70-
print(header)
71-
print(" Build OpenCore v%s for model: %s" % (Versions.opencore_version, BuildOpenCore.current_model))
72-
print(header)
73-
print("")
74-
print(" 1. Auto build OpenCore")
75-
print(" 2. Return to main menu")
76-
print("")
77-
78-
OpenCoreBuilderMenu = input('Please select an option: ')
79-
80-
if OpenCoreBuilderMenu=="1":
81-
AutoBuilderMenu=True
82-
while AutoBuilderMenu:
83-
os.system('clear')
84-
print(header)
85-
print(" Building OpenCore for model: %s" % BuildOpenCore.current_model)
86-
print(header)
87-
print("")
88-
print("The current working directory:")
89-
print (" %s" % Versions.current_path)
90-
print("")
91-
BuildOpenCore.BuildEFI()
92-
BuildOpenCore.BuildGUI()
93-
BuildOpenCore.BuildSMBIOS()
94-
BuildOpenCore.SavePlist()
95-
BuildOpenCore.CleanBuildFolder()
96-
print("")
97-
print("Your OpenCore EFI has been built at:")
98-
print(" %s" % Versions.opencore_path_done)
99-
print("")
100-
AutoBuilderMenu = input("Press any key to return to previous menu: ")
101-
if AutoBuilderMenu=="1":
102-
print("Returning to previous menu...")
103-
AutoBuilderMenu=False
104-
OpenCoreBuilderMenu=False
105-
elif OpenCoreBuilderMenu=="2":
106-
print("\n Returning to main menu...")
107-
OpenCoreBuilderMenu=False
108-
MainMenu=True
109-
else:
110-
print("\n Not Valid Choice Try again")
111-
OpenCoreBuilderMenu = True
112-
113-
114-
elif MainMenu=="2":
115-
print("\n Not yet implemented")
116-
OpenCoreInstallerMenu=True
117-
while OpenCoreInstallerMenu:
118-
os.system('clear')
119-
120-
print(header)
121-
print(" Install OpenCore to drive")
122-
print(header)
123-
print("")
124-
print(" 1. Install to USB/internal drive")
125-
print(" 2. Return to main menu")
126-
print("")
127-
128-
OpenCoreInstallerMenu = input('Please select an option: ')
129-
130-
if OpenCoreInstallerMenu=="1":
131-
os.system('clear')
132-
if os.path.exists(Versions.opencore_path_done):
133-
print("Found OpenCore in Build Folder")
134-
BuildOpenCore.ListDiskutil()
135-
BuildOpenCore.MoveOpenCore()
136-
137-
else:
138-
print("OpenCore folder missing!")
139-
print("Please build OpenCore first")
140-
print("")
141-
OpenCoreInstallerMenu = input("Press any key to exit: ")
142-
if OpenCoreInstallerMenu=="1":
143-
print("Returning to main menu...")
144-
OpenCoreInstallerMenu=False
145-
elif OpenCoreInstallerMenu=="2":
146-
print("\n Returning to main menu...")
147-
OpenCoreInstallerMenu=False
148-
MainMenu=True
149-
else:
150-
print("\n Not Valid Choice Try again")
151-
OpenCoreInstallerMenu = True
152-
153-
elif MainMenu=="3":
154-
SMBIOSMenu=True
155-
while SMBIOSMenu:
156-
os.system('clear')
157-
158-
print(header)
159-
print(" Enter a new SMBIOS")
160-
print(header)
161-
print("")
162-
print(" Tip: Run this command on the machine to find the SMBIOS")
163-
print("")
164-
print(" system_profiler SPHardwareDataType | grep 'Model Identifier'")
165-
print("")
166-
SMBIOSOption = input('Please enter the SMBIOS of your machine (Press enter to exit): ')
167-
if SMBIOSOption == "":
168-
print("Exiting...")
169-
SMBIOSMenu=False
170-
MainMenu=True
6+
7+
from Resources import build, ModelArray, Constants, utilities
8+
9+
PATCHER_VERSION = "0.0.11"
10+
11+
12+
class OpenCoreLegacyPatcher():
13+
def __init__(self):
14+
self.constants = Constants.Constants()
15+
self.current_model: str = None
16+
opencore_model: str = subprocess.run("nvram 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:oem-product".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()
17+
if not opencore_model.startswith("nvram: Error getting variable"):
18+
opencore_model = [line.strip().split(":oem-product ", 1)[1] for line in opencore_model.split("\n") if line.strip().startswith("4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:")][0]
19+
self.current_model = opencore_model
20+
else:
21+
self.current_model = subprocess.run("system_profiler SPHardwareDataType".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
22+
self.current_model = [line.strip().split(": ", 1)[1] for line in self.current_model.stdout.decode().split("\n") if line.strip().startswith("Model Identifier")][0]
23+
24+
def build_opencore(self):
25+
build.BuildOpenCore(self.constants.custom_model or self.current_model, self.constants).build_opencore()
26+
27+
def install_opencore(self):
28+
build.BuildOpenCore(self.constants.custom_model or self.current_model, self.constants).copy_efi()
29+
30+
def change_model(self):
31+
utilities.cls()
32+
utilities.header(["Select Different Model"])
33+
print("""
34+
Tip: Run the following command on the target machine to find the model identifier:
35+
36+
system_profiler SPHardwareDataType | grep 'Model Identifier'
37+
""")
38+
self.constants.custom_model = input("Please enter the model identifier of the target machine: ").strip()
39+
40+
def credits(self):
41+
utilities.TUIOnlyPrint(["Credits"], "Press [Enter] to go back.\n",
42+
["""Many thanks to the following:
43+
44+
- Acidanthera:\tOpenCore, kexts and other tools
45+
- Khronokernel:\tWriting and maintaining this patcher
46+
- DhinakG:\t\tWriting and maintaining this patcher
47+
- Syncretic:\t\tAAAMouSSE and telemetrap
48+
- Slice:\t\tVoodooHDA"""]).start()
49+
50+
def main_menu(self):
51+
response = None
52+
while not (response and response == -1):
53+
title = [
54+
f"OpenCore Legacy Patcher v{self.constants.patcher_version}",
55+
f"Selected Model: {self.constants.custom_model or self.current_model}"
56+
]
57+
58+
if (self.constants.custom_model or self.current_model) not in ModelArray.SupportedSMBIOS:
59+
in_between = [
60+
'Your model is not supported by this patcher!',
61+
'',
62+
'If you plan to create the USB for another machine, please select the "Change Model" option in the menu.'
63+
]
64+
elif not self.constants.custom_model and self.current_model in ("MacPro3,1", "iMac7,1") and \
65+
"SSE4.1" not in subprocess.run("sysctl machdep.cpu.features".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode():
66+
in_between = [
67+
'Your model requires a CPU upgrade to a CPU supporting SSE4.1+ to be supported by this patcher!',
68+
'',
69+
f'If you plan to create the USB for another {self.current_model} with SSE4.1+, please select the "Change Model" option in the menu.'
70+
]
71+
elif self.constants.custom_model in ("MacPro3,1", "iMac7,1"):
72+
in_between = ["This model is supported",
73+
"However please ensure the CPU has been upgraded to support SSE4.1+"
74+
]
17175
else:
172-
print("")
173-
print(" New SMBIOS: %s" % SMBIOSOption)
174-
print("")
175-
SMBIOSMenuYN = input("Is this correct? (y/n)")
176-
if SMBIOSMenuYN in {"y", "Y", "yes", "Yes"}:
177-
SMBIOSMenu=False
178-
BuildOpenCore.current_model = SMBIOSOption
179-
MainMenu=True
180-
CustomSMBIOS=True
181-
elif MainMenu=="4":
182-
CreditMenu=True
183-
while CreditMenu:
184-
os.system('clear')
185-
186-
print(header)
187-
print(" Credits")
188-
print(header)
189-
print("")
190-
print(" Many thanks to the following:")
191-
print("")
192-
print(" - Acidanthera: OpenCore, kexts and other tools")
193-
print(" - DhinakG: Writing and maintaining this Patcher")
194-
print(" - Khronokernel: Writing and maintaining this Patcher")
195-
print(" - Syncretic: AAAMouSSE and telemetrap")
196-
print(" - Slice: VoodooHDA")
197-
print("")
198-
CreditMenu = input(" Press any key to exit: ")
199-
print("Returning to main menu...")
200-
CreditMenu=False
201-
MainMenu=True
202-
203-
elif MainMenu=="5":
204-
print("\n Closing program...")
205-
sys.exit(1)
206-
else:
207-
print("\n Not Valid Choice Try again")
208-
MainMenu=True
76+
in_between = ["This model is supported"]
77+
78+
menu = utilities.TUIMenu(title, "Please select an option: ", in_between=in_between, auto_number=True, top_level=True)
79+
80+
options = ([["Build OpenCore", self.build_opencore]] if ((self.constants.custom_model or self.current_model) in ModelArray.SupportedSMBIOS) else []) + [
81+
["Install OpenCore to USB/internal drive", self.install_opencore],
82+
["Change Model", self.change_model],
83+
["Credits", self.credits]
84+
]
85+
86+
for option in options:
87+
menu.add_menu_option(option[0], function=option[1])
88+
89+
response = menu.start()
90+
91+
print("Bye")
92+
93+
94+
OpenCoreLegacyPatcher().main_menu()

0 commit comments

Comments
 (0)