mirror of
https://github.com/elliotnunn/macresources.git
synced 2024-12-13 10:29:07 +00:00
Rget can dump to a file
This commit is contained in:
parent
9ab7a78461
commit
23a2e9c843
19
bin/Rget
19
bin/Rget
@ -3,6 +3,8 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import macresources
|
import macresources
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
|
from os import path
|
||||||
|
|
||||||
def fourcc(s):
|
def fourcc(s):
|
||||||
b = s.encode('mac_roman').ljust(4, b' ')
|
b = s.encode('mac_roman').ljust(4, b' ')
|
||||||
@ -43,6 +45,7 @@ parser = argparse.ArgumentParser(description='''
|
|||||||
parser.add_argument('srcfile', help='resource file or Rez file')
|
parser.add_argument('srcfile', help='resource file or Rez file')
|
||||||
parser.add_argument('type', type=fourcc, help='four-byte type of resource (converted to Mac Roman pre-lookup)')
|
parser.add_argument('type', type=fourcc, help='four-byte type of resource (converted to Mac Roman pre-lookup)')
|
||||||
parser.add_argument('id', type=resid, help='ID number of resource (-32768 to 32767)')
|
parser.add_argument('id', type=resid, help='ID number of resource (-32768 to 32767)')
|
||||||
|
parser.add_argument('-f', dest='tofile', action='store_true', help='copy to a tempfile instead')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -56,10 +59,18 @@ else:
|
|||||||
|
|
||||||
for r in resources:
|
for r in resources:
|
||||||
if r.type == args.type and r.id == args.id:
|
if r.type == args.type and r.id == args.id:
|
||||||
try:
|
myres = r
|
||||||
sys.stdout.buffer.write(r.data)
|
|
||||||
except BrokenPipeError:
|
|
||||||
pass
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise ValueError(args.type, args.id)
|
raise ValueError(args.type, args.id)
|
||||||
|
|
||||||
|
if args.tofile:
|
||||||
|
tmpname = '-%s-%s-%d' % (path.basename(args.srcfile), myres.type.decode('mac_roman'), myres.id)
|
||||||
|
with tempfile.NamedTemporaryFile(suffix=tmpname, delete=False, mode='wb') as f:
|
||||||
|
f.write(myres.data)
|
||||||
|
print(f.name)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
sys.stdout.buffer.write(myres.data)
|
||||||
|
except BrokenPipeError:
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user