Skip to content

Commit d31af8d

Browse files
committed
Port to Python3 for macOS 12.3+
1 parent b723875 commit d31af8d

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

End-user Read Me.rtf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{\rtf1\ansi\ansicpg1252\cocoartf2578
1+
{\rtf1\ansi\ansicpg1252\cocoartf2638
22
\cocoascreenfonts1\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica-Bold;\f1\fswiss\fcharset0 Helvetica;}
33
{\colortbl;\red255\green255\blue255;}
44
{\*\expandedcolortbl;;}
@@ -18,6 +18,9 @@ http://www.timdoug.com/\
1818
released under the GNU GPL (see COPYING)\
1919
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
2020
\cf0 \
21+
NEW IN 4.8:\
22+
- Port to Python3 for macOS 12.3+, see https://developer.apple.com/documentation/macos-release-notes/macos-12_3-release-notes#Python\
23+
\
2124
NEW IN 4.7:\
2225
- Native Apple Silicon support: rebuild w/ arm64 and x86_64 binaries\
2326
\

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ unpkg.app: unpkg.py VERSION
1313
-a unpkg \
1414
-I org.timdoug.unpkg \
1515
-u timdoug \
16-
-p /usr/bin/python \
16+
-p /usr/bin/python3 \
1717
-c unpkg.py \
1818
-V ${VERSION} \
1919
-i appIcon.icns \

unpkg.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22

33
# unpkg
44
# http://www.timdoug.com/unpkg/
55
# by timdoug[.com|@gmail.com]
66
#
77
# version notes:
88
#
9+
# 4.8 -- 2022-03-20
10+
# - Port to Python3 for macOS 12.3+
11+
# https://developer.apple.com/documentation/macos-release-notes/macos-12_3-release-notes#Python
12+
#
913
# 4.7 -- 2021-03-14
1014
# - Native Apple Silicon support: rebuild w/ arm64 and x86_64 binaries
1115
#
@@ -85,11 +89,11 @@ def get_extract_dir(pkg_path):
8589

8690
if os.path.exists(extract_dir):
8791
orig_extract_dir = extract_dir
88-
for i in xrange(1, 1000):
92+
for i in range(1, 1000):
8993
extract_dir = '%s-%s' % (orig_extract_dir, str(i))
9094
if not os.path.exists(extract_dir): break
9195
if i == 999: # I sure hope this never happens...
92-
print 'Cannot establish appropriate extraction directory.'
96+
print('Cannot establish appropriate extraction directory.')
9397
sys.exit()
9498

9599
return extract_dir
@@ -112,7 +116,7 @@ def extract_package(pkg_path, extract_dir):
112116
if os.path.isdir(pkg_path):
113117
pax_path = find_pax(pkg_path)
114118
if not pax_path:
115-
print 'Cannot find pax file. (not a valid package?)'
119+
print('Cannot find pax file. (not a valid package?)')
116120
return False
117121
os.mkdir(extract_dir)
118122
extract_prog = '/bin/pax -r < "%s"'
@@ -125,12 +129,12 @@ def extract_package(pkg_path, extract_dir):
125129
else:
126130
# no 'with' for compatibility with python 2.3 (10.4)
127131
try:
128-
f = open(pkg_path, 'r')
129-
if f.read(4) != 'xar!':
130-
print 'Not a valid package.'
132+
f = open(pkg_path, 'rb')
133+
if f.read(4) != b'xar!':
134+
print('Not a valid package.')
131135
return False
132136
except IOError:
133-
print 'Cannot read package.'
137+
print('Cannot read package.')
134138
return False
135139
else:
136140
f.close()
@@ -140,14 +144,14 @@ def extract_package(pkg_path, extract_dir):
140144

141145
payloads = []
142146
for root, dirs, files in os.walk(temp_dir):
143-
for file in filter(lambda x: x == 'Payload', files):
147+
for file in [x for x in files if x == 'Payload']:
144148
payloads.append(os.path.join(root, file))
145149

146150
os.mkdir(extract_dir)
147151
extract_prog = '/usr/bin/gzcat "%s" | "' + CPIO_PATH + '" -i -m --quiet'
148152

149153
if len(payloads) == 0:
150-
print 'No payloads found.'
154+
print('No payloads found.')
151155
return False
152156
elif len(payloads) == 1:
153157
run_in_path(extract_prog % payloads[0], extract_dir)
@@ -164,11 +168,11 @@ def extract_package(pkg_path, extract_dir):
164168

165169
def main():
166170
for pkg_path in sys.argv[1:]:
167-
print 'Extracting "%s"...' % os.path.splitext(os.path.basename(pkg_path))[0]
171+
print('Extracting "%s"...' % os.path.splitext(os.path.basename(pkg_path))[0])
168172
sys.stdout.flush()
169173

170174
if not os.access(pkg_path, os.R_OK):
171-
print 'Cannot read package.'
175+
print('Cannot read package.')
172176
continue
173177

174178
extract_dir = get_extract_dir(pkg_path)
@@ -183,20 +187,20 @@ def main():
183187
if extract_package(os.path.join(root, file), subpkg_extract_dir):
184188
count += 1
185189
if count > 0:
186-
print 'Extracted %d internal package%s to "%s".' % \
187-
(count, ('', 's')[count > 1], extract_dir)
190+
print('Extracted %d internal package%s to "%s".' % \
191+
(count, ('', 's')[count > 1], extract_dir))
188192
else:
189193
shutil.rmtree(extract_dir)
190-
print 'No packages found within the metapackage.'
194+
print('No packages found within the metapackage.')
191195
elif pkg_path.endswith('.pkg'):
192196
if extract_package(pkg_path, extract_dir):
193-
print 'Extracted to "%s".' % extract_dir
197+
print('Extracted to "%s".' % extract_dir)
194198
else:
195-
print 'Not a package.'
199+
print('Not a package.')
196200

197-
print '----------------------'
201+
print('----------------------')
198202

199-
print 'Done!'
203+
print('Done!')
200204

201205
if __name__ == '__main__':
202206
main()

0 commit comments

Comments
 (0)